containers.podman.podman_container_exec (1.12.1) — module

Executes a command in a running container.

Authors: Takuya Nishimura (@nishipy)

Install collection

Install with ansible-galaxy collection install containers.podman:==1.12.1


Add to requirements.yml

  collections:
    - name: containers.podman
      version: 1.12.1

Description

Executes a command in a running container.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Execute a command with workdir
  containers.podman.podman_container_exec:
    name: ubi8
    command: "cat redhat-release"
    workdir: /etc
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Execute command in background by using detach
  containers.podman.podman_container_exec:
    name: detach_container
    command: "cat redhat-release"
    detach: true

Inputs

    
env:
    description:
    - Set environment variables.
    type: dict

tty:
    default: false
    description:
    - Allocate a pseudo-TTY.
    type: bool

argv:
    description:
    - Passes the command as a list rather than a string.
    - One of the I(command) or I(args) is required.
    elements: str
    type: list

name:
    description:
    - Name of the container where the command is executed.
    required: true
    type: str

user:
    description:
    - The username or UID used and, optionally, the groupname or GID for the specified
      command.
    - Both user and group may be symbolic or numeric.
    type: str

detach:
    default: false
    description:
    - If true, the command runs in the background.
    - The exec session is automatically removed when it completes.
    type: bool

command:
    description:
    - The command to run in the container.
    - One of the I(command) or I(args) is required.
    type: str

workdir:
    description:
    - Working directory inside the container.
    type: str

executable:
    default: podman
    description:
    - The path to the podman executable.
    type: str

privileged:
    default: false
    description:
    - Give extended privileges to the container.
    type: bool

Outputs

exec_id:
  description:
  - The ID of the exec session.
  returned: success and I(detach=true)
  sample: f99002e34c1087fd1aa08d5027e455bf7c2d6b74f019069acf6462a96ddf2a47
  type: str
rc:
  description:
  - The exit code of the command executed in the container.
  returned: success
  sample: 0
  type: int
stderr:
  description:
  - The standard output of the command executed in the container.
  returned: success
  type: str
stdout:
  description:
  - The standard output of the command executed in the container.
  returned: success
  type: str