On 22.03.2019 17:47, John Harmon wrote: > > Thx Kai. > > I tried it, and the regexp test shows that the regexp is good, but it > doesn't replace the line. It just says ok, and continues on. Here is my > slightly modified variant also doing the same thing (or to be more > specific, not doing anything): > > regexp: 'nameservers:\n.*addresses:.*\[(.*)\]' > line: '\1 {{ dns1 }}, {{ dns2 }}'
Replace doesn't have line: to my knowledge. > Result: > > TASK [dns_update : Update DNS servers] > *************************************************************************************************************************************************************************************************** > ok: [ansible-ub18] > > > File remains the same So, to check I created a little test with my regexp to see if it work, and it does. $ more dns.yaml network: ethernets: enp0s3: addresses: [10.10.50.0/24] gateway4: 10.10.50.5 dhcp4: no nameservers: addresses: [10.1.2.3, 10.1.2.4] version: 2 $ cat test.yml --- - hosts: localhost vars: dns1: 1.1.1.1 dns2: 2.2.2.2 gather_facts: no tasks: - replace: path: dns.yaml regexp: '(.*nameservers.*$\n.*addresses:).*$' replace: '\1 [{{ dns1 }}, {{ dns2 }}]' $ ansible-playbook test.yml TASK [replace] ************************************************************* --- before: dns.yaml +++ after: dns.yaml @@ -5,5 +5,5 @@ gateway4: 10.10.50.5 dhcp4: no nameservers: - addresses: [10.1.2.3, 10.1.2.4] + addresses: [1.1.1.1, 2.2.2.2] version: 2 changed: [localhost] => { "changed": true } MSG: 1 replacements made PLAY RECAP ***************************************************************** localhost : ok=1 changed=1 unreachable=0 failed=0 $ cat dns.yaml network: ethernets: enp0s3: addresses: [10.10.50.0/24] gateway4: 10.10.50.5 dhcp4: no nameservers: addresses: [1.1.1.1, 2.2.2.2] version: 2 So it does work in my test. -- Kai Stian Olstad -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To post to this group, send email to ansible-project@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/ba30ae5f-6a29-c950-cb97-e28bd1825ae5%40olstad.com. For more options, visit https://groups.google.com/d/optout.