Reputation: 6701
Standard CLI Ansible looks for the group_vars
and host_vars
directory in the same location as the host file. See for example How can I change the path of group_vars and host_vars?.
Ansible AWX / Tower has the option of using an "external source" for inventory. When I add the URL of my Git repo I can select the host file or root.
I tried a configuration with a host file in the root and a configuration with the host file in a sub directory. With both options the directories group_vars
and host_vars
are ignored as far as I can tell.
The documentation is a bit vague on the issue.
Keeping variable data along with the objects in Tower (see the inventory editor) is encouraged, rather than using group_vars/ and host_vars/. If you use dynamic inventory sources, Tower can sync such variables with the database as long as the Overwrite Variables option is not set. 26. Best Practices — Ansible Tower User Guide v3.7.0
Can Tower / AWX sync those variables? Variables in group_vars
and / or host_vars
? Or is this sync ability limited to the host file?
If it is possible, how should this work?
It seems that Ansible AWX / Tower is a one way street. If you want to use AWX you have to migrate the group_vars
and host_vars
directories to AWX / Tower and after that there is no way back?
An Ansible project can work with standard CLI Ansible or AWX / Tower - not both!?
Upvotes: 3
Views: 9494
Reputation: 11
In my case Ansible Controller (formerly Tower) reads inventory group_vars
and host_vars
directories the same way Ansible does locally. Creating folders named after the groups and hosts inside these directories to be able to split vars into multiple files also works.
I have my inventory in the root of a git repository and vars files in group_vars
and host_vars
subdirectories. I synced the repo to Automation Controller and used it as a source for an inventory. Inspecting the inventory in AC, the vars show up under the respective group in the "Groups" tab and the host in the "Hosts" tab. The vars are used normally when running a playbook based on the inventory in AC.
Upvotes: 0
Reputation: 33
If you are using a static inventory
file within your GitHub repo (in the root folder or a sub-folder), you can place vars within this file.
In my experience, this is the way I had to go in order to get TOWER to "see" these vars (does not appear to read the separate "vars" folders as you pointed out).
I setup a TOWER PROJECT
as I normally would, sync.
Then, I setup an INVENTORY
within TOWER, and define my GitHub repo based inventory
file under SOURCE, and sync the SOURCE.
This will result in the host_vars
& group_vars
being sync'ed over, and tied to the hosts & groups created on TOWER (from your defined INVENTORY
.)
EG:
[ans-poc-tower]
towernode.fqdn https_port=443
[ans-poc-tower:vars]
role=TOWER
loc=RemoteDC
Reference: adding-variables-to-inventory
Upvotes: 2