Defining variables in included files and roles
You can define variables in reusable variables files or in reusable roles. If you define variables in reusable variable files, the sensitive variables are separated from playbooks. This separation enables you to store your playbooks in a source control software and even share the playbooks, without the risk of exposing passwords or other sensitive and personal data. For information about creating reusable files and roles, seeReusing Ansible artifacts.
This example shows how you can include variables defined in an external file:
The contents of each variables file is a simple YAML dictionary. For example:
You can keep per-host and per-group variables in similar files. To learn about organizing your variables, seeOrganizing host and group variables.