I have a playbook with multiple hosts section. I would like to define a variable in this playbook.yml file that applies only within the file, for example:
vars:
I prefer to keep global variables in the inventory file, where you keep the groups and names of your hosts.
For example:
my-hosts
:
[all:vars]
my_global_var="hello"
[db]
db1
db2
[web]
web1
web2
Run your playbook with:
ansible-playbook -i my-hosts playbook.yml
The variable will now be defined for all hosts.
If you are using ec2.py
or some other dynamic inventory, you can put the global variables in the file group_vars/all
to achieve the same result.