ansible / ansible-runner

A tool and python library that helps when interfacing with Ansible directly or as part of another system whether that be through a container image interface, as a standalone tool, or as a Python module that can be imported. The goal is to provide a stable and consistent interface abstraction to Ansible.
Other
968 stars 356 forks source link

Command-line argument --inventory does not work #1295

Closed LDTips closed 1 year ago

LDTips commented 1 year ago

When using ansible-runner I wanted to specify alternate inventory directory by using the --inventory commandline argument

However, it does not work as expected. Instead it changes the hosts file in /inventory to be equal to the provided

The command I run: ansible-runner run -p install_sim.yml --inventory /runner/inventory2/ --process-isolation --container-image localhost/ran-deployment-stable .

Results not in using the inventory found in this location, but rather replaces the hosts file contents inside the default folder (/runner/inventory) with the path supplied to the --inventory argument. My hosts file just has the line /runner/inventory2/

If I rearrange the folder structure and use the ansible-playbook install_sim.yml --inventory inventory2, it works as expected

Shrews commented 1 year ago

I believe our handling of --inventory might indeed be broken, but I need to research a bit more.

What version of ansible-runner are you using?

LDTips commented 1 year ago

The version is 2.3.2

Shrews commented 1 year ago

Thanks.

I've dug into this more and it appears that the --inventory value is not being validated properly. The only value that is supported in this CLI parameter is a relative location under the <private_data_dir>/inventory subdirectory. Apparently, it's not designed to support a full path, nor any other value. The inventory parameter to the run() API method is supposed to support multiple types of values, however.

I'll work on getting a fix out for this, as well as improving the documentation around it.

Shrews commented 1 year ago

@LDTips I can only reproduce the behavior you see (contents of inventory/hosts being replaced) when I specify a value for --inventory that does not exist on the localhost. Since you are using /runner in your path, are you attempting to specify the location on the container image (the private data dir is mounted into the container image at that location)? If so, that is not what you should be doing. You should be referencing paths on the localhost.

LDTips commented 1 year ago

I think this occurred even when I was specifying localhost paths, but can't remember it for now. In any case, this behaviour seems weird. You can close this issue for now, as for the time being I am unable to check it due to lack of access to the device on which this bug occurred.

When I have time, I will check it and reopen the issue if even after following your guidelines the issue will still occur.

Shrews commented 1 year ago

Thanks for the response. Going to keep this open as I feel there are improvements to be made wrt the CLI option, at least.