I have a playbook which performs a potentially destructive action, which I expect to run with --limit normally, and I would like to assert that all hosts which meet a certain condition are included in my --limit to avoid unexpected behavior. The particular use case is failing over a PostgreSQL master and updating all replicas correspondingly.
I don’t have a problem getting the list to validate against (I use an ansible_local fact), but I can’t figure out how to get a property of each host present in hostvars as a list. So I want to be able to say something like:
- name: validate all streaming replicas are in scope
assert:
that:- “{{ item }} in {{ hostvars.values()|map(attribute=‘ansible_default_ipv4’)|map(‘address’) }}”
with_items: ansible_local.academia.pg_streaming_replicas
when: inventory_hostname == old_master
But “hostvars.values()|map(attribute=‘ansible_default_ipv4’)|map(‘address’)” doesn’t do what I expect, and neither does any variant I’ve tried. What’s the right way to get the list of IPs for all hosts that Ansible knows about?
-David