name: Dump result
ansible.builtin.debug:
msg: “{{ result }}”
look like? It presumably has a ‘json’ field? Which itself contains a ‘value’?
Without a reasonable approximation of your input, I can’t possibly suggest how to create expected output from it.
TASK [debug] **************************************************************************************************************************
ok: [localhost] => {
“msg”: “The List of VMs is [‘servera’, ‘serverb’, ‘serverc’, ‘serverd’, ‘centos8-latest’]”
}
TASK [write the server list to the file /tmp/output.txt] ******************************************************************************
ok: [localhost]
Yes. Or if you feel like ignoring the warnings* about using variables in copy’s “content”:
- name: Write to the file
ansible.builtin.copy:
content: |
{% for server in servers %}
{{ server }}
{% endfor %}
dest: "{{my_inv}}"
* I do it quite often, looking for cases where the promised unexpected surprises happen, but I haven’t found them yet. It’ll probably happen some day when it least convenient.
Yes. Or if you feel like ignoring the warnings^* about using
variables in copy's "content":
\- name: Write to the file
ansible\.builtin\.copy:
content: |
{% for server in servers %}
{{ server }}
{% endfor %}
dest: "{{my_inv}}"
^* I do it quite often, looking for cases where the promised
unexpected surprises happen, but I haven't found them yet. It'll
probably happen some day when it least convenient.
I got bitten by this somewhen in the past when the input for `content`
turned out to be valid JSON. Ansible parsed it and converted it to the
Python representation of the dictionary, which wasn't valid JSON
anymore (`"` converted to `'`).
But that's something rather special, for many simple templates such as
yours it's no problem at all (and I also use `content` for that).