- name: Append to all known_host files shell: cat /tmp/append >> {{ item }} loop: - '{{ known.stdout_lines }}'
How do I make that last play work? --
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/84e78306-66cf-4d86-8b45-d1c4816c598en%40googlegroups.com.
-- Todd
loop: - '{{ known.stdout_lines }}'passes the whole list as a single item. So you need to not put the list in a list:
loop: '{{ known.stdout_lines }}'should do the trick.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/48b522d1-3503-4606-958b-29ab38398f5en%40googlegroups.com.
-- Todd
You want stdout_lines rather than stdout. The former is a list with new-lines removed. The latter is a possibly very long string with the complete output stream intact.
- name: Append to all known_host files shell: cat /tmp/append >> {{ item }} loop: - '{{ known.stdout_lines }}'
- name: Append to all known_host files shell: cat /tmp/append >> {{ item }} loop: '{{ known.stdout_lines }}'
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/4b07b147-2d6b-40d4-aa6f-a0e385893c6a%40gmail.com.
- name: test loop constructs
hosts: localhost
gather_facts: false
become: false
vars:
my_list: [ one, two, three ]
tasks:
- name: construct 1
debug: var=item
loop:
- '{{ my_list }}'
- name: construct 2
debug: var=item
loop: '{{ my_list }}'
% ansible-playbook -i localhost, loop.yml
PLAY [test loop constructs] ********************************************************************************************
TASK [construct 1] *****************************************************************************************************
ok: [localhost] => (item=['one', 'two', 'three']) => {
"ansible_loop_var": "item",
"item": [
"one",
"two",
"three"
]
}
TASK [construct 2] *****************************************************************************************************
ok: [localhost] => (item=one) => {
"ansible_loop_var": "item",
"item": "one"
}
ok: [localhost] => (item=two) => {
"ansible_loop_var": "item",
"item": "two"
}
ok: [localhost] => (item=three) => {
"ansible_loop_var": "item",
"item": "three"
}
PLAY RECAP *************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
On May 24, 2024, at 7:41 AM, Rowe, Walter P. (Fed) <walte...@nist.gov> wrote:
Very subtle but very different. Great catch Todd.
In the first instance you create a list that contains a single item – another list called known.stdout_lines.
loop:
- '{{ known.stdout_lines }}'
In the second instance you provide a list called known.stdout_lines as the list for the loop:
loop: '{{ known.stdout_lines }}'
The second instance is the desired behavior. The difference is subtle at first glance but makes a world of difference in execution.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b661295c-91dd-449f-ad73-d1eb4a60f7a1%40gmail.com.
On May 23, 2024, at 11:30 AM, Todd Lewis <uto...@gmail.com> wrote:
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b661295c-91dd-449f-ad73-d1eb4a60f7a1%40gmail.com.