diff --git a/plugins/modules/podman_container_exec.py b/plugins/modules/podman_container_exec.py index d30e85c..73d71b7 100644 --- a/plugins/modules/podman_container_exec.py +++ b/plugins/modules/podman_container_exec.py @@ -40,6 +40,11 @@ options: description: - Set environment variables. type: dict + executable: + description: + - The path to the podman executable. + type: str + default: podman privileged: description: - Give extended privileges to the container. @@ -141,6 +146,7 @@ def run_container_exec(module: AnsibleModule) -> dict: tty = module.params['tty'] user = module.params['user'] workdir = module.params['workdir'] + executable = module.params['executable'] if command is not None: argv = shlex.split(command) @@ -178,7 +184,7 @@ def run_container_exec(module: AnsibleModule) -> dict: exec_with_args.extend(exec_options) rc, stdout, stderr = run_podman_command( - module=module, executable='podman', args=exec_with_args) + module=module, executable=executable, args=exec_with_args, ignore_errors=True) result = { 'changed': changed, @@ -211,6 +217,10 @@ def main(): 'type': 'bool', 'default': False, }, + 'executable': { + 'type': 'str', + 'default': 'podman', + }, 'env': { 'type': 'dict', }, diff --git a/tests/integration/targets/podman_container_exec/tasks/main.yml b/tests/integration/targets/podman_container_exec/tasks/main.yml index 2d28743..623965c 100644 --- a/tests/integration/targets/podman_container_exec/tasks/main.yml +++ b/tests/integration/targets/podman_container_exec/tasks/main.yml @@ -12,6 +12,7 @@ - name: Test exec when the container doesn't exist containers.podman.podman_container_exec: + executable: "{{ test_executable | default('podman') }}" name: "{{ container_name }}" command: "cat /etc/redhat-release" ignore_errors: true @@ -19,6 +20,7 @@ - name: Create and start a container for testing containers.podman.podman_container: + executable: "{{ test_executable | default('podman') }}" name: "{{ container_name }}" image: registry.access.redhat.com/ubi8 command: sleep 1d @@ -26,6 +28,7 @@ - name: Test exec with command and workdir options containers.podman.podman_container_exec: + executable: "{{ test_executable | default('podman') }}" name: "{{ container_name }}" command: "cat redhat-release" workdir: /etc @@ -33,6 +36,7 @@ - name: Test exec with argv and env options containers.podman.podman_container_exec: + executable: "{{ test_executable | default('podman') }}" name: "{{ container_name }}" argv: - /bin/sh @@ -45,6 +49,7 @@ - name: Test exec with detach option containers.podman.podman_container_exec: + executable: "{{ test_executable | default('podman') }}" name: "{{ container_name }}" command: "cat redhat-release" detach: true @@ -59,6 +64,21 @@ - "'goodbye world' in exec2.stdout" - exec3.exec_id is defined + - name: Test exec with failing command + containers.podman.podman_container_exec: + executable: "{{ test_executable | default('podman') }}" + name: "{{ container_name }}" + command: "ls /nonexistent" + register: exec4 + ignore_errors: true + + - name: Check if the result is as expected in case of a failing command + assert: + that: + - exec4 is failed + - "'No such file or directory' in exec4.stderr" + - exec4.rc != 0 + always: - name: Cleanup containers.podman.podman_container: