My Problem is that I want to replace a random (most of the time) APIPA address, which gets assigned to a interface when you install a new Debian machine, with, for example, the IP address 1.1.1.1
. I want to replace it with the Ansible "regex and replace" method.
I use Ansible 2.9
Here is something I tried but it doesn't work:
- name: Replace multiple lines and entries
replace:
path: /etc/network/interfaces.d/vm
regexp: "{{ '({0-9}{1,3}{\\.}){3}{0-9}{1,3}' }}"
replace: "5.5.5.5"
And here's how the vm file looks like:
# qemu (virtio_net driver)
allow-hotplug enp0s2
iface enp0s2 inet dhcp
# vbox (virtio_net driver)
allow-hotplug enp0s3
iface enp0s3 inet dhcp
# vmware (vmxnet3 driver)
allow-hotplug ens192
iface ens192 inet dhcp
address 12.80.55.47/27
allow-hotplug ens224
iface ens224 inet static
address 192.168.1.77/28