On Thu, 13 Feb 2020 06:11:43 -0800 (PST) Matthias Steffens <[email protected]> wrote:
> ... grep for the IP-address ... on every host with ansible and
> get an list of hosts where it's configured or not.
Try this
- set_fact:
my_hosts: "{{ hostvars|dict2items|json_query(query) }}"
vars:
query: "[?value.ansible_all_ipv4_addresses.contains(@,
'{{ ipv4_address }}')].value.ansible_hostname"
The variable "my_hosts" should keep the list of "ansible_hostname" with the
"ipv4_address" among "ansible_all_ipv4_addresses".
For example with the inventory
$ cat hosts
test_01 ansible_host=10.1.0.51
test_02 ansible_host=10.1.0.52
test_03 ansible_host=10.1.0.53
test_06 ansible_host=10.1.0.56
test_09 ansible_host=10.1.0.59
the playbook
- hosts: all
gather_facts: true
vars:
ipv4_address: 10.1.0.51
tasks:
- set_fact:
my_hosts: "{{ hostvars|dict2items|json_query(query) }}"
vars:
query: "[?value.ansible_all_ipv4_addresses.contains(@,
'{{ ipv4_address }}')].value.ansible_hostname"
run_once: true
- debug:
var: my_hosts
run_once: true
give
ok: [test_01] => {
"my_hosts": [
"test_01"
]
}
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/20200213180335.51e0de52%40gmail.com.
pgpK42dw2jC7E.pgp
Description: OpenPGP digital signature
