getting inventory properties as a list

54 views
Skip to first unread message

David Judd

unread,
Oct 15, 2014, 8:49:54 PM10/15/14
to ansible...@googlegroups.com
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

Michael DeHaan

unread,
Oct 20, 2014, 5:11:46 PM10/20/14
to ansible...@googlegroups.com
So pretty much limit in ansible works, so you shouldn't feel the need to double check it.

If you must, I would do this, and keep in mind you don't use "{{ }}" in conditionals in ansible.

- assert:
     that:
       - item in play_hosts
     with_items:  required_servers




--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/16430f19-2e86-4dcb-b2f5-5b016cc2dfe8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages