containers/ansible-podman-collections

No values returned from podman_container_exec on failures

ocafebabe opened this issue · 3 comments

Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)

/kind bug

Description

I'm having an issue when trying the exec module: the returned dict doesn't contain the documented values on failures (i.e.: rc and stdout).

Steps to reproduce the issue:

N/A

Describe the results you received:

Failed to run ['podman', 'container', 'exec', '--env', 'IGNORE="dr"', '--tty', '--workdir', '/home/user/sanity', 'appia', '/bin/bash', '-c', './sanity -i $IGNORE | tee $HOME/tmp/sanity.log; exit \\${PIPESTATUS[0]}'] ['container', 'exec', '--env', 'IGNORE="dr"', '--tty', '--workdir', '/home/user/sanity', 'appia', '/bin/bash', '-c', './sanity -i $IGNORE | tee $HOME/tmp/sanity.log; exit \\${PIPESTATUS[0]}']: 
The conditional check 'sanity_result is defined and sanity_result.rc != '0'' failed. The error was: error while evaluating conditional (sanity_result is defined and sanity_result.rc != '0'): 'dict object' has no attribute 'rc'

Describe the results you expected:

The return code and stdout in the registered var ("sanity_result")

Additional information you deem important (e.g. issue happens only occasionally):

It happens on every run

Version of the containers.podman collection:
Either git commit if installed from git: git show --summary
Or version from ansible-galaxy if installed from galaxy: ansible-galaxy collection list | grep containers.podman

1.12.0

Output of ansible --version:

2.12.10

Output of podman version:

3.4.2

Output of podman info --debug:

host:
  arch: amd64
  buildahVersion: 1.23.1
  cgroupControllers: []
  cgroupManager: cgroupfs
  cgroupVersion: v1
  conmon:
    package: 'conmon: /usr/libexec/podman/conmon'
    path: /usr/libexec/podman/conmon
    version: 'conmon version 2.1.2, commit: '
  cpus: 32
  distribution:
    codename: focal
    distribution: ubuntu
    version: "20.04"
  eventLogger: journald
  hostname: (REDACTED)
  idMappings:
    gidmap:
    - container_id: 0
      host_id: 1002
      size: 1
    - container_id: 1
      host_id: 165536
      size: 65536
    uidmap:
    - container_id: 0
      host_id: 1001
      size: 1
    - container_id: 1
      host_id: 165536
      size: 65536
  kernel: 5.4.0-166-generic
  linkmode: dynamic
  logDriver: journald
  memFree: 8828387328
  memTotal: 123641950208
  ociRuntime:
    name: crun
    package: 'crun: /usr/bin/crun'
    path: /usr/bin/crun
    version: |-
      crun version UNKNOWN
      commit: ea1fe3938eefa14eb707f1d22adff4db670645d6
      spec: 1.0.0
      +SYSTEMD +SELINUX +APPARMOR +CAP +SECCOMP +EBPF +CRIU +YAJL
  os: linux
  remoteSocket:
    path: /run/user/1001/podman/podman.sock
  security:
    apparmorEnabled: false
    capabilities: CAP_CHOWN,CAP_DAC_OVERRIDE,CAP_FOWNER,CAP_FSETID,CAP_KILL,CAP_NET_BIND_SERVICE,CAP_SETFCAP,CAP_SETGID,CAP_SETPCAP,CAP_SETUID,CAP_SYS_CHROOT
    rootless: true
    seccompEnabled: true
    seccompProfilePath: /usr/share/containers/seccomp.json
    selinuxEnabled: false
  serviceIsRemote: false
  slirp4netns:
    executable: /usr/bin/slirp4netns
    package: 'slirp4netns: /usr/bin/slirp4netns'
    version: |-
      slirp4netns version 1.1.8
      commit: unknown
      libslirp: 4.3.1-git
      SLIRP_CONFIG_VERSION_MAX: 3
      libseccomp: 2.4.3
  swapFree: 0
  swapTotal: 0
  uptime: 2185h 1m 50.75s (Approximately 91.04 days)
plugins:
  log:
  - k8s-file
  - none
  - journald
  network:
  - bridge
  - macvlan
  volume:
  - local
registries:
  (REDACTED):
    Blocked: false
    Insecure: false
    Location: (REDACTED)
    MirrorByDigestOnly: false
    Mirrors: null
    Prefix: (REDACTED)
  search:
  - (REDACTED)
store:
  configFile: /home/user/.config/containers/storage.conf
  containerStore:
    number: 2
    paused: 0
    running: 2
    stopped: 0
  graphDriverName: overlay
  graphOptions:
    overlay.mount_program:
      Executable: /usr/bin/fuse-overlayfs
      Package: 'fuse-overlayfs: /usr/bin/fuse-overlayfs'
      Version: |-
        fusermount3 version: 3.9.0
        fuse-overlayfs: version 1.5
        FUSE library version 3.9.0
        using FUSE kernel interface version 7.31
  graphRoot: /home/user/.local/share/containers/storage
  graphStatus:
    Backing Filesystem: extfs
    Native Overlay Diff: "false"
    Supports d_type: "true"
    Using metacopy: "false"
  imageStore:
    number: 5
  runRoot: /tmp/podman-run-1001/containers
  volumePath: /home/user/.local/share/containers/storage/volumes
version:
  APIVersion: 3.4.2
  Built: 0
  BuiltTime: Thu Jan  1 01:00:00 1970
  GitCommit: ""
  GoVersion: go1.15.2
  OsArch: linux/amd64
  Version: 3.4.2

Package info (e.g. output of rpm -q podman or apt list podman):

podman/now 100:3.4.2-5 amd64 [installed,local]

Playbok you run with ansible (e.g. content of playbook.yaml):

        - name: Test
          containers.podman.podman_container_exec:
            name: mycontainer
            command: /bin/bash -c './sanity | tee $HOME/tmp/sanity.log; exit \${PIPESTATUS[0]}'
            env:
              IGNORE: "{{ sanity_ignore }}"
            workdir: /home/user/sanity
            tty: true
          register: sanity_result
          ignore_errors: yes

        - name: Fail when there are sanity errors
          fail:
            msg: "{{ sanity_result.stdout }}"
          when: sanity_result is defined and sanity_result.rc != 0

@ocafebabe please check if #718 helps you. BTW, if you set tty: true it will put both stdout and stderr to stdout, just FYI.

@sshnaidm Thanks a lot for that! Are you going to tag a new release with these changes?

@ocafebabe yeah, after we verify it all works with podman v5