I wrote a playbook with the purpose of changing the last bit of the default gateway ip of all the hosts in my inventory.ini
So far I am able to change the last bit through this command :
cat /etc/network/interfaces | grep -i default | awk -F'.' -vOFS='.' '{$NF=6}1;' > /etc/network/interfaces
But the problem is that I still cannot figure out how to replace only the last line of the interfaces file without overwriting the whole content of the file.
Here's how my playbook look like :
---
- name: test connectivity
hosts: all
tasks:
- name: ping
ping:
- name: change default gateway address
command: cat /etc/network/interfaces | grep -i default | awk -F'.' -vOFS='.' '{$NF=6}1;' > /etc/network/interfaces
- name: restart networking service
command: systemctl restart networking
- name: check ip configuration
command: netstat -rn
...
All hint and tips are more than welcome.