diff --git a/docs/python_interface.rst b/docs/python_interface.rst index c3f3ec261..cf85369bd 100644 --- a/docs/python_interface.rst +++ b/docs/python_interface.rst @@ -262,6 +262,22 @@ Usage examples print("Final status:") print(r.stats) +.. code-block:: python + + import ansible_runner + # Specifying custom container working directory while using Podman + # `/tmp/demo` contains `my_project` directory which contains all the Ansible content + res = ansible_runner.run( + private_data_dir='/tmp/demo', + host_pattern='localhost', + container_workdir='/runner/my_project', + playbook='debug.yml', + process_isolation_executable='podman', + process_isolation=True, + container_image='quay.io/ansible/ansible-runner:devel', + ) + stdout = res.stdout.read() + .. code-block:: python from ansible_runner import Runner, RunnerConfig diff --git a/test/fixtures/projects/project_dir_test/project/debug.yml b/test/fixtures/projects/project_dir_test/project/debug.yml new file mode 100644 index 000000000..e19899a9f --- /dev/null +++ b/test/fixtures/projects/project_dir_test/project/debug.yml @@ -0,0 +1,6 @@ +- hosts: all + gather_facts: no + + tasks: + - debug: + msg: "In project" diff --git a/test/integration/test_interface.py b/test/integration/test_interface.py index 1986d8d22..5c9428e9a 100644 --- a/test/integration/test_interface.py +++ b/test/integration/test_interface.py @@ -190,6 +190,19 @@ def test_multiple_inventories(project_fixtures): assert 'host_2' in stdout +def test_default_project_dir(project_fixtures): + private_data_dir = project_fixtures / 'project_dir_test' + + res = run( + private_data_dir=private_data_dir, + playbook='debug.yml', + ) + stdout = res.stdout.read() + + assert res.rc == 0, stdout + assert 'project' in stdout + + def test_project_dir(project_fixtures): private_data_dir = project_fixtures / 'project_dir_test' @@ -204,6 +217,41 @@ def test_project_dir(project_fixtures): assert 'my_project' in stdout +@pytest.mark.test_all_runtimes +def test_default_project_dir_inside_container(project_fixtures, runtime): + private_data_dir = project_fixtures / 'project_dir_test' + + res = run( + private_data_dir=private_data_dir, + playbook='debug.yml', + process_isolation_executable=runtime, + process_isolation=True, + container_image=defaults.default_container_image, + ) + stdout = res.stdout.read() + + assert res.rc == 0, stdout + assert 'project' in stdout + + +@pytest.mark.test_all_runtimes +def test_project_dir_inside_container(project_fixtures, runtime): + private_data_dir = project_fixtures / 'project_dir_test' + + res = run( + private_data_dir=private_data_dir, + container_workdir='/runner/my_project', + playbook='debug.yml', + process_isolation_executable=runtime, + process_isolation=True, + container_image=defaults.default_container_image, + ) + stdout = res.stdout.read() + + assert res.rc == 0, stdout + assert 'my_project' in stdout + + def test_inventory_absolute_path(project_fixtures): private_data_dir = project_fixtures / 'debug'