Search code examples
ansibleaerospike

How use hostvars from multiple hosts in one variable in Ansible?


I want to add more servers to Aerospike cluster. For that i want to use facts from gather_facts. Here the example how i do it for one server. How i can add all hosts which works with my playbook ? I don't want to use hosts from groups in inventory - because i'm using dynamical inventory.

heartbeat {
    mode mesh
    port 3002
    mesh-seed-address-port {{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }} 3002
    interval 150
    timeout 10
}

Thank you.

Solution

  • Your question is a little vague. I would suggest writing a dynamic inventory script (https://docs.ansible.com/ansible/developing_inventory.html)

    That said if you're insistent about using facts to dynamically generate inventory you can use the add host module in a with_items (or other loop type) loop.