Hellos guys,
I have a result from ec2_instance_facts, and i can get the ip addresses
like:
- name: Get IP addresses from results
set_fact:
inject_ips: “{{ facts_output | json_query(‘instances[].
public_ip_address’) }}”
and that gives me something like:
ok: [localhost] => {
"ansible_facts": {
"inject_ips": [
"1.2.3.4",
"1.2.3.4",
"1.2.3.4"
]
},
"changed": false
}
but i need the list to include the name, like:
ok: [localhost] => {
"ansible_facts": {
"inject_ips": [
"1.2.3.4,name1",
"1.2.3.4,name2",
"1.2.3.4,name3"
]
},
"changed": false
}
I can also get the name with:
- name: Get IP addresses from results
set_fact:
inject_ips: “{{ facts_output | json_query(‘instances[].tags[].Name’)
}}”
But i don't know how to concatenate them, i tried:
- name: Get IP addresses from results
set_fact:
inject_ips: “{{ facts_output | json_query(‘instances[].
public_ip_address’) }},{{ facts_output | json_query(‘instances[].tags[].Name
’) }}”
which gives me:
ok: [localhost] => {
"ansible_facts": {
"inject_ips": [
[
"1.2.3.4",
"1.2.3.4",
"1.2.3.4",
"1.2.3.4"
],
[
"name1",
"name2",
"name3",
"name4"
]
]
},
"changed": false
}
The point is to then use it like:
- name: execute to add the ips
command: “exec item[ip] item[name]”
run_once: true
with_items:
- “{{ inject_ips }}”
Right now I'm splitting them by comma ","
Any suggestion is welcomed!
Help is very appreciated!
Thanks
David.
--
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/a61a0563-3436-4564-bbfe-a9f57d54fd3b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.