On Mon, May 04, 2020 at 02:02:13PM -0700, Justin Nelson wrote:
> 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)

Here also you have two task writing to the same file at the same time.
So here you need to add "run_once: yes" to the lineinfile task.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20200504211803.rnrw6wb4rkawvmyo%40olstad.com.

Reply via email to