ansible-zuul[bot]: Build failed.

- [ansible-tox-py36 ](https://logs.zuul.ansible.com/09/309/deaeca9548d3fdcc17bba40a929003203a378838/check/ansible-tox-py36/bf52091/) : FAILURE in 6m 41s
- [ansible-tox-py37 ](https://logs.zuul.ansible.com/09/309/deaeca9548d3fdcc17bba40a929003203a378838/check/ansible-tox-py37/57b6baf/) : FAILURE in 8m 20s
- [ansible-build-python-tarball ](https://logs.zuul.ansible.com/09/309/deaeca9548d3fdcc17bba40a929003203a378838/check/ansible-build-python-tarball/0367337/) : SUCCESS in 2m 28s
- [ansible-tox-linters ](https://logs.zuul.ansible.com/09/309/deaeca9548d3fdcc17bba40a929003203a378838/check/ansible-tox-linters/b3003dc/) : SUCCESS in 4m 34s
- [ansible-tox-py27 ](https://logs.zuul.ansible.com/09/309/deaeca9548d3fdcc17bba40a929003203a378838/check/ansible-tox-py27/ddd68c6/) : FAILURE in 5m 34s

ansible-zuul[bot]: Build failed.

- [ansible-tox-py36 ](https://logs.zuul.ansible.com/09/309/f6a147c30c09327d9fdfddc4ec4446efc5f772fb/check/ansible-tox-py36/ceb73b6/) : FAILURE in 7m 47s
- [ansible-tox-py37 ](https://logs.zuul.ansible.com/09/309/f6a147c30c09327d9fdfddc4ec4446efc5f772fb/check/ansible-tox-py37/9336fd7/) : FAILURE in 7m 11s
- [ansible-build-python-tarball ](https://logs.zuul.ansible.com/09/309/f6a147c30c09327d9fdfddc4ec4446efc5f772fb/check/ansible-build-python-tarball/991f9f2/) : SUCCESS in 2m 24s
- [ansible-tox-linters ](https://logs.zuul.ansible.com/09/309/f6a147c30c09327d9fdfddc4ec4446efc5f772fb/check/ansible-tox-linters/64f792b/) : SUCCESS in 4m 42s
- [ansible-tox-py27 ](https://logs.zuul.ansible.com/09/309/f6a147c30c09327d9fdfddc4ec4446efc5f772fb/check/ansible-tox-py27/c0941c0/) : FAILURE in 13m 03s

diff --git a/ansible_runner/runner_config.py b/ansible_runner/runner_config.py
index 46d1f7d..69291f3 100644
--- a/ansible_runner/runner_config.py
+++ b/ansible_runner/runner_config.py
@@ -201,7 +201,7 @@ class RunnerConfig(object):
         """
         Prepares the inventory default under ``private_data_dir`` if it's not overridden by the constructor.
         """
-        if self.inventory is None:
+        if self.inventory is None and os.path.exists(os.path.join(self.private_data_dir, "inventory")):
             self.inventory  = os.path.join(self.private_data_dir, "inventory")
 
     def prepare_env(self):
@@ -316,7 +316,9 @@ class RunnerConfig(object):
         except ConfigurationError:
             pass
 
-        if isinstance(self.inventory, list):
+        if self.inventory is None:
+            pass
+        elif isinstance(self.inventory, list):
             for i in self.inventory:
                 exec_list.append("-i")
                 exec_list.append(i)

Allow use of Inventory defined in ansible.cfg
If `inventory` is not given to the runner, the configuration defaults to `private_data_dir/inventory`.
https://github.com/ansible/ansible-runner/blob/31b4174663e3562af30e85175e833bf047e3df14/ansible_runner/runner_config.py#L200-L201

So with this, its always defined an `-i` option to the ansible playbook. I want to run playbooks in a git repository, which provides own inventories from the repository.

I think of defaulting to no `-i` given if no inventory is specified, this leads in use of the inventory defined in `ansible.cfg` and its precedence.
diff --git a/test/unit/test_runner_config.py b/test/unit/test_runner_config.py
index dd5d15b..606ccc6 100644
--- a/test/unit/test_runner_config.py
+++ b/test/unit/test_runner_config.py
@@ -22,7 +22,6 @@ from ansible_runner.runner_config import RunnerConfig, ExecutionMode
 from ansible_runner.loader import ArtifactLoader
 from ansible_runner.exceptions import ConfigurationError
 
-
 try:
     Pattern = re._pattern_type
 except AttributeError:
@@ -190,7 +189,8 @@ def test_prepare_env_directory_isolation():
         assert rc.cwd == '/tmp/foo'
 
 
-def test_prepare_inventory():
+@patch('os.path.exists', return_value=True)
+def test_prepare_inventory(path_exists):
     rc = RunnerConfig(private_data_dir='/')
     rc.prepare_inventory()
     assert rc.inventory == '/inventory'
@@ -200,11 +200,17 @@ def test_prepare_inventory():
     rc.inventory = 'localhost,anotherhost,'
     rc.prepare_inventory()
     assert rc.inventory == 'localhost,anotherhost,'
+    path_exists.return_value = False
+    rc.inventory = None
+    rc.prepare_inventory()
+    assert rc.inventory is None
 
 
 def test_generate_ansible_command():
     rc = RunnerConfig(private_data_dir='/', playbook='main.yaml')
-    rc.prepare_inventory()
+    with patch('os.path.exists') as path_exists:
+        path_exists.return_value=True
+        rc.prepare_inventory()
     rc.extra_vars = None
 
     cmd = rc.generate_ansible_command()
@@ -235,8 +241,14 @@ def test_generate_ansible_command():
     assert cmd == ['ansible-playbook', 'main.yaml']
     rc.inventory = None
 
+    with patch('os.path.exists', return_value=False) as path_exists:
+        rc.prepare_inventory()
+        cmd = rc.generate_ansible_command()
+    assert cmd == ['ansible-playbook', 'main.yaml']
+
     rc.verbosity = 3
-    rc.prepare_inventory()
+    with patch('os.path.exists', return_value=True) as path_exists:
+        rc.prepare_inventory()
     cmd = rc.generate_ansible_command()
     assert cmd == ['ansible-playbook', '-i', '/inventory', '-vvv', 'main.yaml']
     rc.verbosity = None
@@ -265,7 +277,9 @@ def test_generate_ansible_command():
 
 def test_generate_ansible_command_with_api_extravars():
     rc = RunnerConfig(private_data_dir='/', playbook='main.yaml', extravars={"foo":"bar"})
-    rc.prepare_inventory()
+    with patch('os.path.exists') as path_exists:
+        path_exists.return_value=True
+        rc.prepare_inventory()
 
     cmd = rc.generate_ansible_command()
     assert cmd == ['ansible-playbook', '-i', '/inventory', '-e', 'foo="bar"', 'main.yaml']
@@ -277,7 +291,9 @@ def test_generate_ansible_command_with_api_extravars():
 ])
 def test_generate_ansible_command_with_cmdline_args(cmdline):
     rc = RunnerConfig(private_data_dir='/', playbook='main.yaml')
-    rc.prepare_inventory()
+    with patch('os.path.exists') as path_exists:
+        path_exists.return_value=True
+        rc.prepare_inventory()
     rc.extra_vars = {}
 
     cmdline_side_effect = partial(load_file_side_effect, 'env/cmdline', cmdline)
@@ -408,7 +424,9 @@ def test_process_isolation_defaults():
     rc.playbook = 'main.yaml'
     rc.command = 'ansible-playbook'
     rc.process_isolation = True
-    rc.prepare()
+    with patch('os.path.exists') as path_exists:
+        path_exists.return_value=True
+        rc.prepare()
 
     assert rc.command == [
         'bwrap',
@@ -426,14 +444,20 @@ def test_process_isolation_defaults():
 @patch('tempfile.mkdtemp', return_value="/tmp/dirisolation/foo")
 @patch('os.chmod', return_value=True)
 @patch('shutil.rmtree', return_value=True)
-def test_process_isolation_and_directory_isolation(mock_makedirs, mock_copytree, mock_mkdtemp, mock_chmod, mock_rmtree):
+def test_process_isolation_and_directory_isolation(mock_makedirs, mock_copytree, mock_mkdtemp,
+                                                   mock_chmod, mock_rmtree):
+    def new_exists(path):
+        if path == "/project":
+            return False
+        return True
     rc = RunnerConfig('/')
     rc.artifact_dir = '/tmp/artifacts'
     rc.directory_isolation_path = '/tmp/dirisolation'
     rc.playbook = 'main.yaml'
     rc.command = 'ansible-playbook'
     rc.process_isolation = True
-    rc.prepare()
+    with patch('os.path.exists', new=new_exists):
+        rc.prepare()
 
     assert rc.command == [
         'bwrap',

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest mock
apt-get update apt-get install -y gcc
3.9
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
-e git+https://github.com/ansible/ansible-runner.git@b556af522dd6ba87ab39c90d01061c8a862f0196#egg=ansible_runner
exceptiongroup==1.2.2
iniconfig==2.1.0
lockfile==0.12.2
mock==5.2.0
packaging==24.2
pexpect==4.9.0
pluggy==1.5.0
psutil==7.0.0
ptyprocess==0.7.0
pytest==8.3.5
python-daemon==3.1.2
PyYAML==6.0.2
six==1.17.0
tomli==2.2.1

name: ansible-runner
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - exceptiongroup==1.2.2
      - iniconfig==2.1.0
      - lockfile==0.12.2
      - mock==5.2.0
      - packaging==24.2
      - pexpect==4.9.0
      - pluggy==1.5.0
      - psutil==7.0.0
      - ptyprocess==0.7.0
      - pytest==8.3.5
      - python-daemon==3.1.2
      - pyyaml==6.0.2
      - six==1.17.0
      - tomli==2.2.1
prefix: /opt/conda/envs/ansible-runner

test/unit/test_runner_config.py::test_prepare_inventory test/unit/test_runner_config.py::test_generate_ansible_command
test/unit/test_runner_config.py::test_runner_config_init_defaults test/unit/test_runner_config.py::test_runner_config_with_artifact_dir test/unit/test_runner_config.py::test_runner_config_init_with_ident test/unit/test_runner_config.py::test_runner_config_project_dir test/unit/test_runner_config.py::test_prepare_environment_vars_only_strings test/unit/test_runner_config.py::test_prepare_env_ad_hoc_command test/unit/test_runner_config.py::test_prepare_environment_pexpect_defaults test/unit/test_runner_config.py::test_prepare_env_passwords test/unit/test_runner_config.py::test_prepare_env_extra_vars_defaults test/unit/test_runner_config.py::test_prepare_env_settings_defaults test/unit/test_runner_config.py::test_prepare_env_settings test/unit/test_runner_config.py::test_prepare_env_sshkey_defaults test/unit/test_runner_config.py::test_prepare_env_sshkey test/unit/test_runner_config.py::test_prepare_env_defaults test/unit/test_runner_config.py::test_prepare_env_directory_isolation test/unit/test_runner_config.py::test_generate_ansible_command_with_api_extravars test/unit/test_runner_config.py::test_generate_ansible_command_with_cmdline_args[--tags test/unit/test_runner_config.py::test_prepare_command_defaults test/unit/test_runner_config.py::test_prepare_with_defaults test/unit/test_runner_config.py::test_prepare test/unit/test_runner_config.py::test_prepare_with_ssh_key test/unit/test_runner_config.py::test_wrap_args_with_ssh_agent_defaults test/unit/test_runner_config.py::test_wrap_args_with_ssh_agent_with_auth test/unit/test_runner_config.py::test_wrap_args_with_ssh_agent_silent test/unit/test_runner_config.py::test_process_isolation_defaults test/unit/test_runner_config.py::test_process_isolation_and_directory_isolation test/unit/test_runner_config.py::test_process_isolation_settings
ansible_runner/runner_config.py
ansible_runner/runner_config.py