Hello Morrissey,

You may use the below playbook to fulfill your requirements. It makes use 
of lineinfile module with regular expression to capture the line to be 
modified.

---
- hosts: localhost
  connection: local
  gather_facts: false
  tasks:
     - name: "insert values to a list"
       lineinfile:
           dest: /opt/test.txt
           regexp: '(^ALL.*$)'
           line: '\1, {{item}}'
           backrefs: yes
       with_items:
           - 1.1.1.1/255.255.255.255
           - 2.2.2.2/255.255.255.255

The file would be modified as shown below: 
Hello world !
ALL, 1.1.1.1/255.255.255.255, 2.2.2.2/255.255.255.255
This is a test file

Hope this is helpful !

Thanks,
Shivharsh

On Wednesday, 11 September 2019 19:36:27 UTC+5:30, TheSmiths wrote:
>
> Hi,
>
> I would like to use lineinfile module to do the next:
>
> 1. go over list of items (with_items)
> 2. look for specific line that always starts with the word "ALL:"  
> (hosts.allow)
> 3. append each item at the END of the line with comma before the item
>
> for example
>
> ALL ,1.1.1.1/255.255.255.255 , 2.2.2.2/255.255.255.255
>
> Thanks,
> Morrissey
>  
>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/acbe7f26-fea5-403b-92f3-b8e2c1506b1a%40googlegroups.com.

Reply via email to