On Mon, May 04, 2020 at 11:55:19AM -0700, Justin Nelson wrote:
> I have a simple playbook that I'm testing with in an attempt to update a
> file that has some test strings mapped to mac addresses. When I run my
> playbook I can only seem to get one of my two hosts to write the test
> string into the playbook and not both. If I run it a second time, I can get
> the second host in there.
>
> The plybook looks similar to the following:
>
> ---
> - name: Update File
> hosts:
> - test_group
> connection: local
> gather_facts: no
>
> vars:
> user_home: "{{ lookup('env', 'HOME') }}"
> config_file: "{{ inventory_hostname }}.conf"
>
> tasks:
> - name: Load device vars from config file
> include_vars: "{{ user_home }}/{{ config_file }}"
>
> - name: Update test file
> lineinfile:
> path: /var/tmp/test.yaml
> regexp: "^\ \ test[.-]{{ test_string|lower }}:.*"
> line: " test-{{ test_string|lower }}: {{ mac }}"
>
> The config file has multiple variables for each host in it including the
> 'test_string' and 'mac'.
>
> My test_group has two hosts:
>
> [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.
--
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/20200504203149.ea6bamcewwosjcte%40olstad.com.