Hello,
I need to execute a role with a conditional based on a variable set on a different host/group.
The variable is set doing a query on host db1 and a set_fact :
- hosts: db1
tasks: - name: Check for DB
shell: psql -Atc “SELECT id FROM …;”
register: dbs_check
- set_fact:
base_id: “{{ dbs_check.stdout.split(‘|’)[0]|int }}”
Then on a condition on base_id I want to run a role on a different host , but the variable is not defined as for normal Ansible behaviour.
- hosts: db2
roles:
- { role: createdb, when: base_id > 0 }
As a workaround I could run queries to DBs executing commands from localhost but I don’t like it.
Is there any easy workaround I am missing?
Thank you.
P.