Reputation: 163
I have multiple Ansible roles
each with their own playbook
as seen in the structure below:
roles/
|-- abc/
-- def/
-- hij/
-- someother/
common.yml
abc.yml
def.yml
hij.yml
However, all the playbooks have the set_facts
module that sets the same vars in each playbook. i.e: So, if the abc.yml
playbook has the below, all the other playbooks share the exact same.
- hosts: all
tasks:
- set_fact:
hostname: "user"
randomvar: "random"
The problem is, if one vars from the set_facts
needs updating, that means it needs to be done in each playbook. Is there a way to create a single playbook and pass the set_facts
vars dynamically to others?
Upvotes: 0
Views: 921
Reputation: 1930
with set_fact you set up a variable while the playbook runs. So instead of using set_fact, you can use the file group_vars\all.yml
to set variables for all hosts in your inventory. all
is a default group for all host.
The content of this file could be:
hostname: user
randomvar: random
from now all your playbooks can use these variables. And you have only one place to change them.
Upvotes: 2