This will work, but it's not idempotent.
So if you run it again it will add the two CIDRs again.
For it to work idempotently, the regex will need to match both what
you have before and what you get after.
Something like this should work:
---
- hosts: localhost
connection: local
gather_facts: false
vars:
cidrs:
-
1.1.1.1/255.255.255.255
-
2.2.2.2/255.255.255.255
tasks:
- name: "insert values to a list"
lineinfile:
dest: /tmp/test.txt
regexp: "^(?P<start>ALL:.*?)((,{{ cidrs | join(',') }})*)$"
line: "\\g<start>,{{ cidrs | join(',') }}"
backrefs: yes
The named group 'start' is to avoid clashing with a CIDR that begins
with a number.
Dick
> --
> 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-proje...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/acbe7f26-fea5-403b-92f3-b8e2c1506b1a%40googlegroups.com.
--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT