I've got a very odd issue with my Ansible inventory that has just started 
and I cannot find the culprit. This script is one that we've run for years. 
It collects some data from the user and then runs the ansible playbook 
using the python3 subprocess module.

When I enable verbosity in the script I think I've found what is causing 
the issues. For some reason the present working directory from where I run 
the script is appended with a space ahead of the inventory file that is 
defined.

For example, if I'm in /etc/ansible when I run the script, then the 
inventory in the output appears as:
inventory: ('/etc/ansible /etc/ansible/inventory/routers')

If I'm in my home directory when I run the script, then the inventory in 
the output appears as:
inventory: ('/home/<username> /etc/ansible/inventory/routers')

However, if I run the playbook with the same variables directly, without 
the script, the inventory ansible is now looking for is:
inventory: ('/etc/ansible/inventory/routers')

And the device I'm working on is now found in the inventory and the 
playbook proceeds to run.

Prior to debugging this, the inventory wasn't defined in the script (or on 
the CLI) and was defined in the /etc/ansible/ansible.cfg with:
inventory = /etc/ansible/inventory/

But since the issue started I added the explicit inventory file to use in 
an attempt to test and that still did not fix the issue.

I also have verified that the ansible version and directories are all the 
same both on the script run and my manual run.

$ ansible --version
ansible [core 2.12.6]
  config file = /etc/ansible/ansible.cfg
  configured module search path = 
['/home/<username>/.ansible/plugins/modules', 
'/usr/share/ansible/plugins/modules']
  ansible python module location = 
/usr/local/lib/python3.9/site-packages/ansible
  ansible collection location = 
/etc/ansible/collections:/home/<username>/.ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.7 (default, Sep 13 2021, 08:18:39) [GCC 8.5.0 
20210514 (Red Hat 8.5.0-3)]
  jinja version = 3.1.2
  libyaml = True

Anyone have an idea on where I can look for the culprit that has suddenly 
started appending the $PWD ahead of the inventory file, but only when run 
from the script.


-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/96538934-8f5e-4951-83d1-4f441c903624n%40googlegroups.com.

Reply via email to