How to get anothers host IP based on variables?

Viewed 183

I'd like to get the IP of a given host within my inventory based on the variables it has.

hosts

[pgsql_servers]
psql-01 ansible_host=10.11.12.13  pg_master=True  pg_slave=False
psql-02 ansible_host=10.11.12.14  pg_master=False pg_slave=True
psql-03 ansible_host=10.11.12.15  pg_master=False pg_slave=True

[pgsql_servers:vars]
ansible_python_interpreter=/usr/bin/python3

So within my slave-tasks, which only run for slaves, I'd like to get the IP of the only master given.

slave-tasks.yml

- name: Replicate data from Master
  command: repmgr -h HOW_TO_GET_MASTER-IP_HERE -U repmgr -d repmgr -D /var/lib/postgresql/9.5/main -f /etc/repmgr.conf standby clone
  become: true
  become_user: postgres

I thought of adding a when here, but the master won't hit the slave-tasks.yml so it'll never become True. Any ideas of how to manage this?

2 Answers
Related