containers.podman.podman_container_exec module – Executes a command in a running container.
Note
This module is part of the containers.podman collection (version 1.16.2).
You might already have this collection installed if you are using the ansible
package.
It is not included in ansible-core
.
To check whether it is installed, run ansible-galaxy collection list
.
To install it, use: ansible-galaxy collection install containers.podman
.
You need further requirements to be able to use this module,
see Requirements for details.
To use it in a playbook, specify: containers.podman.podman_container_exec
.
Synopsis
Executes a command in a running container.
Requirements
The below requirements are needed on the host that executes this module.
podman
Parameters
Parameter |
Comments |
---|---|
Passes the command as a list rather than a string. One of the command or args is required. |
|
The command to run in the container. One of the command or args is required. |
|
If true, the command runs in the background. The exec session is automatically removed when it completes. Choices:
|
|
Set environment variables. |
|
The path to the podman executable. Default: |
|
Name of the container where the command is executed. |
|
Give extended privileges to the container. Choices:
|
|
Allocate a pseudo-TTY. Choices:
|
|
The username or UID used and, optionally, the groupname or GID for the specified command. Both user and group may be symbolic or numeric. |
|
Working directory inside the container. |
Notes
Note
See the Podman documentation for details of podman-exec(1).
Examples
- name: Execute a command with workdir
containers.podman.podman_container_exec:
name: ubi8
command: "cat redhat-release"
workdir: /etc
- name: Execute a command with a list of args and environment variables
containers.podman.podman_container_exec:
name: test_container
argv:
- /bin/sh
- -c
- echo $HELLO $BYE
env:
HELLO: hello world
BYE: goodbye world
- name: Execute command in background by using detach
containers.podman.podman_container_exec:
name: detach_container
command: "cat redhat-release"
detach: true
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
The ID of the exec session. Returned: success and detach=true Sample: |
|
The exit code of the command executed in the container. Returned: success Sample: |
|
The standard output of the command executed in the container. Returned: success |
|
The standard output of the command executed in the container. Returned: success |