Ansible Inventory Issue: $PWD appended ahead of inventory file

98 views
Skip to first unread message

omeg...@gmail.com

unread,
Aug 11, 2022, 10:14:06 PM8/11/22
to Ansible Project
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.


Dick Visser

unread,
Aug 11, 2022, 11:39:24 PM8/11/22
to ansible...@googlegroups.com
If things work without the script, and fail with the script, then logic dictates that the script is causing the problem.

If this mysterious script has suddenly started changed its behaviour, then you need to find out what why, for example what changed on that host, and when.
Perhaps run it on another host?
With the supplied amount information this is about as much help there is possible.





--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/96538934-8f5e-4951-83d1-4f441c903624n%40googlegroups.com.
--
Sent from Gmail Mobile

omeg...@gmail.com

unread,
Aug 12, 2022, 2:52:10 PM8/12/22
to Ansible Project
Just an update:

In trying to fix an issue for the user that reported the problem I created an additional issue that I was overlooking.

In haste I added the -i flag as a single string ( [..., '-i /etc/ansible/inventory/routers', ...] ) in the subprocess.run() list when it should have been 2 strings ( [..., '-i', '/etc/ansible/inventory/routers', ...] )

Now I can move on to debugging the real problem for the user and not the problem that I created.

Walter Rowe

unread,
Aug 15, 2022, 8:11:55 AM8/15/22
to Ansible Project
I'm confused .. does the original problem reported above still exist?
--
Walter Rowe, Chief
Infrastructure Services
Office of Information Systems Management
National Institute of Standards and Technology
United States Department of Commerce

Reply all
Reply to author
Forward
0 new messages