concatenate multiple results

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.

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’) }}”

<snip />

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
’) }}”

<snip />

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!

Why split them up, why not just use facts_output directly.

   - name: execute to add the ips
     command: “exec item.public_ip_address item.tags.Name”
     run_once: true
     with_items:
       - “{{ facts_output.instances }}”

A little correction

   - name: execute to add the ips
     command: “exec {{ item.public_ip_address }} {{ item.tags.Name }}”
     run_once: true
     with_items:
       - “{{ facts_output.instances }}”