According to the documentation, an ansible.cfg adjacent to a playbook should be picked up and used by Ansible Tower during job run. This is not working.
Instead, ansible.cfg inside a project is only read if it is at the root of the project.
master branch.subdir/bug.yml with Show Changes enabled and set the verbosity to 3(Debug).
Ansible will see the ansible.cfg adjacent to the playbook and use that. It will be reflected in the debug output:
Identity added: /tmp/awx_66_RIxb4K/credential_3 (/tmp/awx_66_RIxb4K/credential_3)
ansible-playbook 2.4.0.0
config file = /var/lib/awx/projects/_6__bug_demo/subdir/ansible.cfg
configured module search path = [u'/var/lib/awx/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.5 (default, Aug 4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
Using /var/lib/awx/projects/_6__bug_demo/subdir/ansible.cfg as config file
...
TASK [Create a file using setting in ansible.cfg] ******************************
task path: /var/lib/awx/projects/_6__bug_demo/subdir/bug.yml:7
...
--- before: /tmp/template.txt
+++ after: /tmp/tmpyRyXCE/template.j2
@@ -1,2 +1,2 @@
-# Ansible managed
+# SET IN ADJACENT ANSIBLE.CFG
# The line above should read SET IN ADJACENT ANSIBLE.CFG
Ansible does not see the config file and does not use settings specificed in the ansible.cfg adjacent to the playbook in the repository.
Identity added: /tmp/awx_48_0lFZ3j/credential_3 (/tmp/awx_48_0lFZ3j/credential_3)
ansible-playbook 2.4.0.0
config file = None
configured module search path = [u'/var/lib/awx/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.5 (default, Aug 4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
No config file found; using defaults
Parsed /tmp/awx_48_0lFZ3j/tmpQ7jDnB.awxrest.py inventory source with script plugin
...
TASK [Create a file using setting in ansible.cfg] ******************************
task path: /var/lib/awx/projects/_6__bug_demo/subdir/bug.yml:7
...
--- before: /tmp/template.txt
+++ after: /tmp/tmpcNJ5lq/template.j2
@@ -1,2 +1,2 @@
+# Ansible managed
# The line above should read SET IN ADJACENT ANSIBLE.CFG
Disable job isolation seems to have no affect on this bug — behavior is the same in both cases.
I also have a branch in that bug repo that puts an ansible.cfg file at the root of the repo. If you change the Project to use the top-level-config branch, then run the same Job Template, you can see that the config file at the root of the repo, not adjacent to the playbook, gets picked up. This should not be the case.
Identity added: /tmp/awx_66_RIxb4K/credential_3 (/tmp/awx_66_RIxb4K/credential_3)
ansible-playbook 2.4.0.0
config file = /var/lib/awx/projects/_6__bug_demo/ansible.cfg
configured module search path = [u'/var/lib/awx/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.5 (default, Aug 4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
Using /var/lib/awx/projects/_6__bug_demo/ansible.cfg as config file
Parsed /tmp/awx_66_RIxb4K/tmpbDIjjO.awxrest.py inventory source with script plugin
...
TASK [Create a file using setting in ansible.cfg] ******************************
task path: /var/lib/awx/projects/_6__bug_demo/subdir/bug.yml:7
...
--- before: /tmp/template.txt
+++ after: /tmp/tmpyRyXCE/template.j2
@@ -1,2 +1,2 @@
-# Ansible managed
+# SET IN PROJECT ROOT ANSIBLE.CFG
# The line above should read SET IN ADJACENT ANSIBLE.CFG
Talked w/ @samdoran; not an actual bug, just poor Tower documentation (he's working on a fix).
Turns outâ„¢, this is a bug in the Ansible Tower docs, not a bug in Ansible Tower (that's a nice way of me saying PEBKAC). The docs state:
You can also install your own copy in ~/.ansible.cfg or keep a copy in a directory relative to your playbook named as ansible.cfg.
They _should_ state the ansible.cfg has to be at the root of the project because ansible-playbook is executed from there and Ansible is looking for ansible.cfg in the current working directory, _not_ adjacent to playbooks.
I'll submit a docs PR to clarify this.
Most helpful comment
Turns outâ„¢, this is a bug in the Ansible Tower docs, not a bug in Ansible Tower (that's a nice way of me saying PEBKAC). The docs state:
They _should_ state the
ansible.cfghas to be at the root of the project becauseansible-playbookis executed from there and Ansible is looking foransible.cfgin the current working directory, _not_ adjacent to playbooks.I'll submit a docs PR to clarify this.