So I added the delegate_to: localhost but I still only get one added on the 
first pass:

PLAY [Test Playbook] 
************************************************************************************************************************************

TASK [Load device vars from config] 
*********************************************************************************************************************
ok: [host1]
ok: [host2]

TASK [Update tmp file] 
**********************************************************************************************************************************
changed: [host1 -> localhost]
changed: [host2 -> localhost]

PLAY RECAP 
**********************************************************************************************************************************************
host1                      : ok=2    changed=1    unreachable=0    failed=0 
  
host2                      : ok=2    changed=1    unreachable=0    failed=0 


The file contents after that pass are:

  1 macs:
  2   test-host222: ab:09:87:65:43:21

And when I run it a second time:

PLAY [Test Playbook] 
************************************************************************************************************************************

TASK [Load device vars from config] 
*********************************************************************************************************************
ok: [host1]
ok: [host2]

TASK [Update tmp file] 
**********************************************************************************************************************************
changed: [host1 -> localhost]
ok: [host2 -> localhost]

PLAY RECAP 
**********************************************************************************************************************************************
host1                      : ok=2    changed=1    unreachable=0    failed=0 
  
host2                      : ok=2    changed=0    unreachable=0    failed=0 
  

With the file contents now the following:

  1 macs:
  2   test-host222: ab:09:87:65:43:21
  3   test-host111: 12:34:56:78:90:ab



On Monday, May 4, 2020 at 4:17:57 PM UTC-4, Vladimir Botka wrote:
>
> On Mon, 4 May 2020 11:55:19 -0700 (PDT) 
> Justin Nelson <[email protected] <javascript:>> wrote: 
>
> > - name: Update File 
> >   hosts: test_group 
> >   ... 
> >   tasks: 
> >   ...       
> >     - name: Update test file 
> >       lineinfile: 
> >         path: /var/tmp/test.yaml 
> >         regexp: "^\ \ test[.-]{{ test_string|lower }}:.*" 
> >         line: "  test-{{ test_string|lower }}: {{ mac }}" 
> > 
> > My test_group has two hosts: 
> > 
> > [test_group] 
> > host1 
> > host2 
> > 
> > ... 
> > 
> > When run, I expect to have both hosts with an entry in 
> /var/tmp/test.yaml 
> > similar to: 
> > 
> > mac_list: 
> >   test-abc: 01:23:45:67:89:ab 
> >   test-xyz: ab:09:87:65:43:21 
>
> The file '/var/tmp/test.yaml' is on the remote host. Each host updates its 
> own instance. I can only assume the file should be on the controller, e.g. 
>
>      - name: Update test file 
>        lineinfile: 
>          path: /var/tmp/test.yaml 
>          regexp: "^\ \ test[.-]{{ test_string|lower }}:.*" 
>          line: "  test-{{ test_string|lower }}: {{ mac }}" 
>        delegate_to: localhost 
>
> HTH, 
>
>         -vlado 
>

-- 
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/ada111c2-ec46-467c-8bf5-89456f64ab09%40googlegroups.com.

Reply via email to