mirror of
https://github.com/containers/ansible-podman-collections.git
synced 2026-02-04 07:11:49 +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:
parent
a4df896bae
commit
90ac7e19ac
2 changed files with 31 additions and 1 deletions
|
|
@ -40,6 +40,11 @@ options:
|
||||||
description:
|
description:
|
||||||
- Set environment variables.
|
- Set environment variables.
|
||||||
type: dict
|
type: dict
|
||||||
|
executable:
|
||||||
|
description:
|
||||||
|
- The path to the podman executable.
|
||||||
|
type: str
|
||||||
|
default: podman
|
||||||
privileged:
|
privileged:
|
||||||
description:
|
description:
|
||||||
- Give extended privileges to the container.
|
- Give extended privileges to the container.
|
||||||
|
|
@ -141,6 +146,7 @@ def run_container_exec(module: AnsibleModule) -> dict:
|
||||||
tty = module.params['tty']
|
tty = module.params['tty']
|
||||||
user = module.params['user']
|
user = module.params['user']
|
||||||
workdir = module.params['workdir']
|
workdir = module.params['workdir']
|
||||||
|
executable = module.params['executable']
|
||||||
|
|
||||||
if command is not None:
|
if command is not None:
|
||||||
argv = shlex.split(command)
|
argv = shlex.split(command)
|
||||||
|
|
@ -178,7 +184,7 @@ def run_container_exec(module: AnsibleModule) -> dict:
|
||||||
exec_with_args.extend(exec_options)
|
exec_with_args.extend(exec_options)
|
||||||
|
|
||||||
rc, stdout, stderr = run_podman_command(
|
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 = {
|
result = {
|
||||||
'changed': changed,
|
'changed': changed,
|
||||||
|
|
@ -211,6 +217,10 @@ def main():
|
||||||
'type': 'bool',
|
'type': 'bool',
|
||||||
'default': False,
|
'default': False,
|
||||||
},
|
},
|
||||||
|
'executable': {
|
||||||
|
'type': 'str',
|
||||||
|
'default': 'podman',
|
||||||
|
},
|
||||||
'env': {
|
'env': {
|
||||||
'type': 'dict',
|
'type': 'dict',
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
- name: Test exec when the container doesn't exist
|
- name: Test exec when the container doesn't exist
|
||||||
containers.podman.podman_container_exec:
|
containers.podman.podman_container_exec:
|
||||||
|
executable: "{{ test_executable | default('podman') }}"
|
||||||
name: "{{ container_name }}"
|
name: "{{ container_name }}"
|
||||||
command: "cat /etc/redhat-release"
|
command: "cat /etc/redhat-release"
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
|
@ -19,6 +20,7 @@
|
||||||
|
|
||||||
- name: Create and start a container for testing
|
- name: Create and start a container for testing
|
||||||
containers.podman.podman_container:
|
containers.podman.podman_container:
|
||||||
|
executable: "{{ test_executable | default('podman') }}"
|
||||||
name: "{{ container_name }}"
|
name: "{{ container_name }}"
|
||||||
image: registry.access.redhat.com/ubi8
|
image: registry.access.redhat.com/ubi8
|
||||||
command: sleep 1d
|
command: sleep 1d
|
||||||
|
|
@ -26,6 +28,7 @@
|
||||||
|
|
||||||
- name: Test exec with command and workdir options
|
- name: Test exec with command and workdir options
|
||||||
containers.podman.podman_container_exec:
|
containers.podman.podman_container_exec:
|
||||||
|
executable: "{{ test_executable | default('podman') }}"
|
||||||
name: "{{ container_name }}"
|
name: "{{ container_name }}"
|
||||||
command: "cat redhat-release"
|
command: "cat redhat-release"
|
||||||
workdir: /etc
|
workdir: /etc
|
||||||
|
|
@ -33,6 +36,7 @@
|
||||||
|
|
||||||
- name: Test exec with argv and env options
|
- name: Test exec with argv and env options
|
||||||
containers.podman.podman_container_exec:
|
containers.podman.podman_container_exec:
|
||||||
|
executable: "{{ test_executable | default('podman') }}"
|
||||||
name: "{{ container_name }}"
|
name: "{{ container_name }}"
|
||||||
argv:
|
argv:
|
||||||
- /bin/sh
|
- /bin/sh
|
||||||
|
|
@ -45,6 +49,7 @@
|
||||||
|
|
||||||
- name: Test exec with detach option
|
- name: Test exec with detach option
|
||||||
containers.podman.podman_container_exec:
|
containers.podman.podman_container_exec:
|
||||||
|
executable: "{{ test_executable | default('podman') }}"
|
||||||
name: "{{ container_name }}"
|
name: "{{ container_name }}"
|
||||||
command: "cat redhat-release"
|
command: "cat redhat-release"
|
||||||
detach: true
|
detach: true
|
||||||
|
|
@ -59,6 +64,21 @@
|
||||||
- "'goodbye world' in exec2.stdout"
|
- "'goodbye world' in exec2.stdout"
|
||||||
- exec3.exec_id is defined
|
- 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:
|
always:
|
||||||
- name: Cleanup
|
- name: Cleanup
|
||||||
containers.podman.podman_container:
|
containers.podman.podman_container:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue