The two hosts I have to test with are running 2.7.4 and 2.8.2. I don't have 
a 2.9.x host available to test the throttle command but it makes sense.

However, when I updated the playbook to the following:

---
- name: Test Playbook
  hosts: 
    - test_group
  gather_facts: no
  connection: local

  vars:
    user_home: "{{ lookup('env', 'HOME') }}"
    config_file: "{{ inventory_hostname }}.conf"

  tasks:
    - name: Load device vars from config
      include_vars: "{{ user_home }}/{{ inventory_hostname }}.conf"

    - name: Update tmp file
      lineinfile:
        path: "{{ playbook_dir }}/macs.yaml"
        regexp: "^\ \ test[.-]{{ test_string|lower }}:.*"
        line: "  test-{{test_string|lower}}: {{mac}}"
        create: yes
      loop: "{{ ansible_play_hosts }}"
      vars:
        test_string: "{{ hostvars[item]['test_string'] }}"
        mac: "{{ hostvars[item]['mac'] }}"

It ran as follows:

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

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

TASK [Update tmp file] 
**********************************************************************************************************************************
changed: [host2] => (item=host1)
changed: [host1] => (item=host1)
changed: [host1] => (item=host2)
ok: [host2] => (item=host2)

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

And wrote to the file on the controller as I would have expected it to.

shell> cat macs.yaml 
macs:
  test-host222: ab:09:87:65:43:21
  test-host111: 12:34:56:78:90:ab

I'll see if I can find a host that has 2.9 on it to test with the throttle 
command.

On Monday, May 4, 2020 at 4:49:56 PM UTC-4, Vladimir Botka wrote:
>
> On Mon, 4 May 2020 22:31:49 +0200 
> Kai Stian Olstad <[email protected] <javascript:>> wrote: 
>
> > > [test_group] 
> > > host1 
> > > host2   
> > 
> > Since you have two host you will have two tasks that tries to write to 
> the same 
> > file at the same time, and only one of them will win. 
> > 
> > Add "throttle: 1" to you lineinfile task and it will work. 
>
> I don't need "throttle" with 2.9.6. The playbook 
>
> shell> cat pb.yml 
> - hosts: 
>     - test_01 
>     - test_02 
>   gather_facts: false 
>   tasks: 
>     - lineinfile: 
>         path: test-file 
>         line: "{{ inventory_hostname }}" 
>       delegate_to: localhost 
>
> gives 
>
> shell> cat test-file 
> shell> ansible-playbook pb.yml 
>
> PLAY [test_01,test_02] 
> ******************************* 
>
> TASK [lineinfile] 
> ******************************* 
> changed: [test_01 -> localhost] 
> changed: [test_02 -> localhost] 
>
> PLAY RECAP 
> ******************************* 
> test_01                    : ok=1    changed=1    unreachable=0   
>  failed=0 
>  skipped=0    rescued=0    ignored=0 test_02                    : ok=1 
> changed=1    unreachable=0    failed=0    skipped=0    rescued=0   
>  ignored=0 
>
> shell> cat test-file 
> test_01 
> test_02 
> -- 
>

-- 
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/cb4adc2b-5caa-4736-be5e-62afbf38eab0%40googlegroups.com.

Reply via email to