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

get_inventory does not support running in different venv #1287

Closed eleksis closed 1 year ago

eleksis commented 1 year ago

get_inventory function (like others) accepts envvars argument. With this I want to switch to different python venv (same as doing when using run function). e.g.

    resp, err = ansible_runner.get_inventory(
        action='graph',
        inventories=inventories,
        response_format='json',
        playbook_dir=project,
        output_file='/tmp/hosts',
        envvars=set_environment(virtual_env),
    )

In set_environment i am setting VIRTUAL_ENV and PATH to venv where ansible is installed.

But in InventoryConfig.init() code is checking for ansible-inventory binary in primary env (where runner is installed) and ignores my envvars. (self._ansible_inventory_exec_path = get_executable_path("ansible-inventory"))

I would like to be able to run all ansible related commands (including ansible-inventory) in custom/specific venv.

Shrews commented 1 year ago

I don't believe this is a first-class functionality we want to support, at least at this time. It gets especially complicated when considering running in a containerized environment.