On Mon, 4 May 2020 11:55:19 -0700 (PDT) Justin Nelson <[email protected]> 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
If the file '/var/tmp/test.yaml' shall be created on both 'host1' and 'host2'
try this
- name: Update test file
lineinfile:
path: /var/tmp/test.yaml
regexp: "^\ \ test[.-]{{ test_string|lower }}:.*"
line: " test-{{ test_string|lower }}: {{ mac }}"
loop: "{{ ansible_play_hosts }}"
vars:
mac: "{{ hostvars[item]['mac'] }}"
test_string: "{{ hostvars[item]['test_string'] }}"
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/20200504222631.5ccd2be5%40gmail.com.
pgpq61Qf_QZpd.pgp
Description: OpenPGP digital signature
