containers.podman.podman_container_exec 模块 – 在正在运行的容器中执行命令。
注意
此模块是 containers.podman 集合 (版本 1.16.2) 的一部分。
如果您使用的是 ansible
包,则可能已安装此集合。它不包含在 ansible-core
中。要检查它是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用: ansible-galaxy collection install containers.podman
。您需要其他要求才能使用此模块,有关详细信息,请参见 要求。
要在 playbook 中使用它,请指定: containers.podman.podman_container_exec
。
概要
在正在运行的容器中执行命令。
要求
以下要求是在执行此模块的主机上所需的。
podman
参数
参数 |
注释 |
---|---|
将命令作为列表而不是字符串传递。 需要 *command* 或 *args* 之一。 |
|
在容器中运行的命令。 需要 *command* 或 *args* 之一。 |
|
如果为真,则命令在后台运行。 执行会话在完成后自动删除。 选项
|
|
设置环境变量。 |
|
podman 可执行文件的路径。 默认值: |
|
执行命令的容器名称。 |
|
向容器授予扩展权限。 选项
|
|
分配伪终端。 选项
|
|
使用的用户名或 UID,以及可选的指定命令的组名或 GID。 用户和组都可以是符号的或数字的。 |
|
容器内的工作目录。 |
注释
注意
有关 podman-exec(1) 的详细信息,请参见 Podman 文档。
示例
- 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
返回值
常见的返回值已在 此处 记录,以下是此模块特有的字段
键 |
描述 |
---|---|
执行会话的 ID。 返回:成功且 detach=true 示例: |
|
在容器中执行的命令的退出代码。 返回:成功 示例: |
|
在容器中执行的命令的标准错误输出。 返回:成功 |
|
在容器中执行的命令的标准错误输出。 返回:成功 |