1
0
Fork 0
mirror of https://github.com/containers/ansible-podman-collections.git synced 2026-02-03 23:01:48 +00:00

Return data for podman exec module

And add "executable" parameter to be aligned with other modules
Fix #711
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
This commit is contained in:
Sagi Shnaidman 2024-02-18 18:23:32 +02:00 committed by Sergey
parent a4df896bae
commit 90ac7e19ac
2 changed files with 31 additions and 1 deletions

View file

@ -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',
},

View file

@ -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: