containers / ansible-podman-collections

Repository for Ansible content that can include playbooks, roles, modules, and plugins for use with the Podman tool
GNU General Public License v3.0
260 stars 141 forks source link

podman_container module capitalize boolean environment variable #648

Closed tinsjourney closed 11 months ago

tinsjourney commented 11 months ago

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

/kind bug

Description

When using module podman_container to create container, if in the env parameter we use a boolean (true/false), the container is created with the environment variable capitalized (True/False). Which can be an issue when you have script in your container looking for lowercase.

When creating container manually variable stay lowercase.

Steps to reproduce the issue:

  1. Create playbook test.yaml

    ---
    - name: "test env issue"
    hosts: all
    connection: local
    
    tasks:
    - name: "Create container"
    containers.podman.podman_container:
      name: test_env
      state: present
      image: ubi8
      env:
        BOOLEAN: true
  2. Execute playbook

$ ansible-playbook -i localhost, test.yaml
  1. Inspect container to check env
podman inspect test_env | jq .[].Config.Env
[
  "BOOLEAN=True",
  "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
  "TERM=xterm",
  "container=oci"
]

Describe the results you received:

BOOLEAN variable is capitalized : True

Describe the results you expected:

BOOLEAN variable is lowercase as set in playbook : true

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

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

containers.podman 1.10.3

Output of ansible --version:

ansible [core 2.12.2]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/tins/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.8/site-packages/ansible
  ansible collection location = /home/tins/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.8.12 (default, Sep 16 2021, 10:46:05) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]
  jinja version = 2.10.3
  libyaml = True

Output of podman version:

Client:       Podman Engine
Version:      4.1.1
API Version:  4.1.1
Go Version:   go1.17.7
Built:        Mon Jul 11 16:56:53 2022
OS/Arch:      linux/amd64

Output of podman info --debug:

host:
  arch: amd64
  buildahVersion: 1.26.2
  cgroupControllers: []
  cgroupManager: cgroupfs
  cgroupVersion: v1
  conmon:
    package: conmon-2.1.2-2.module+el8.6.0+15917+093ca6f8.x86_64
    path: /usr/bin/conmon
    version: 'conmon version 2.1.2, commit: 8c4f33ac0dcf558874b453d5027028b18d1502db'
  cpuUtilization:
    idlePercent: 95.96
    systemPercent: 1.86
    userPercent: 2.18
  cpus: 2
  distribution:
    distribution: '"rhel"'
    version: "8.6"
  eventLogger: file
  hostname: foo.msa.lab
  idMappings:
    gidmap:
    - container_id: 0
      host_id: 1000
      size: 1
    - container_id: 1
      host_id: 100000
      size: 65536
    uidmap:
    - container_id: 0
      host_id: 1000
      size: 1
    - container_id: 1
      host_id: 100000
      size: 65536
  kernel: 4.18.0-372.26.1.el8_6.x86_64
  linkmode: dynamic
  logDriver: k8s-file
  memFree: 718184448
  memTotal: 3912998912
  networkBackend: cni
  ociRuntime:
    name: runc
    package: runc-1.1.3-2.module+el8.6.0+15917+093ca6f8.x86_64
    path: /usr/bin/runc
    version: |-
      runc version 1.1.3
      spec: 1.0.2-dev
      go: go1.17.7
      libseccomp: 2.5.2
  os: linux
  remoteSocket:
    path: /run/user/1000/podman/podman.sock
  security:
    apparmorEnabled: false
    capabilities: CAP_NET_RAW,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: true
  serviceIsRemote: false
  slirp4netns:
    executable: /usr/bin/slirp4netns
    package: slirp4netns-1.2.0-2.module+el8.6.0+15917+093ca6f8.x86_64
    version: |-
      slirp4netns version 1.2.0
      commit: 656041d45cfca7a4176f6b7eed9e4fe6c11e8383
      libslirp: 4.4.0
      SLIRP_CONFIG_VERSION_MAX: 3
      libseccomp: 2.5.2
  swapFree: 0
  swapTotal: 0
  uptime: 330h 7m 8.79s (Approximately 13.75 days)
plugins:
  log:
  - k8s-file
  - none
  - passthrough
  - journald
  network:
  - bridge
  - macvlan
  - ipvlan
  volume:
  - local
registries:
  search:
  - registry.access.redhat.com
  - registry.redhat.io
  - docker.io
store:
  configFile: /home/tins/.config/containers/storage.conf
  containerStore:
    number: 2
    paused: 0
    running: 1
    stopped: 1
  graphDriverName: overlay
  graphOptions: {}
  graphRoot: /home/tins/.local/share/containers/storage
  graphRootAllocated: 21357375488
  graphRootUsed: 15920668672
  graphStatus:
    Backing Filesystem: xfs
    Native Overlay Diff: "true"
    Supports d_type: "true"
    Using metacopy: "false"
  imageCopyTmpDir: /var/tmp
  imageStore:
    number: 2
  runRoot: /run/user/1000/containers
  volumePath: /home/tins/.local/share/containers/storage/volumes
version:
  APIVersion: 4.1.1
  Built: 1657551413
  BuiltTime: Mon Jul 11 16:56:53 2022
  GitCommit: ""
  GoVersion: go1.17.7
  Os: linux
  OsArch: linux/amd64
  Version: 4.1.1

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

podman-4.1.1-2.module+el8.6.0+15917+093ca6f8.x86_64

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

---
- name: "test env issue"
  hosts: all
  connection: local

  tasks:
  - name: "Create container"
    containers.podman.podman_container:
      name: test_env
      state: present
      image: ubi8
      env:
        BOOLEAN: true

Command line and output of ansible run with high verbosity

Please NOTE: if you submit a bug about idempotency, run the playbook with --diff option, like:

ansible-playbook -i inventory --diff -vv playbook.yml

ansible-playbook [core 2.12.2]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/tins/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.8/site-packages/ansible
  ansible collection location = /home/tins/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible-playbook
  python version = 3.8.12 (default, Sep 16 2021, 10:46:05) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]
  jinja version = 2.10.3
  libyaml = True
Using /etc/ansible/ansible.cfg as config file
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: test.yaml ********************************************************************************************************************************************************************************************************************************************************************************************************************************************************
1 plays in test.yaml

PLAY [test env issue] ******************************************************************************************************************************************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *****************************************************************************************************************************************************************************************************************************************************************************************************************************************************
task path: /pulp/test.yaml:2
ok: [localhost]
META: ran handlers

TASK [Create container] ****************************************************************************************************************************************************************************************************************************************************************************************************************************************************
task path: /pulp/test.yaml:7
ok: [localhost] => {"actions": [], "changed": false, "container": {"AppArmorProfile": "", "Args": ["/bin/bash"], "BoundingCaps": ["CAP_CHOWN", "CAP_DAC_OVERRIDE", "CAP_FOWNER", "CAP_FSETID", "CAP_KILL", "CAP_NET_BIND_SERVICE", "CAP_NET_RAW", "CAP_SETFCAP", "CAP_SETGID", "CAP_SETPCAP", "CAP_SETUID", "CAP_SYS_CHROOT"], "Config": {"Annotations": {"io.kubernetes.cri-o.TTY": "false", "io.podman.annotations.autoremove": "FALSE", "io.podman.annotations.init": "FALSE", "io.podman.annotations.privileged": "FALSE", "io.podman.annotations.publish-all": "FALSE"}, "AttachStderr": false, "AttachStdin": false, "AttachStdout": false, "Cmd": ["/bin/bash"], "CreateCommand": ["podman", "container", "create", "--name", "test_env", "--env", "BOOLEAN=True", "ubi8"], "Domainname": "", "Entrypoint": "", "Env": ["BOOLEAN=True", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "TERM=xterm", "container=oci"], "Hostname": "0e4a74b86abc", "Image": "registry.access.redhat.com/ubi8:latest", "Labels": {"architecture": "x86_64", "build-date": "2023-09-13T02:08:30", "com.redhat.component": "ubi8-container", "com.redhat.license_terms": "https://www.redhat.com/en/about/red-hat-end-user-license-agreements#UBI", "description": "The Universal Base Image is designed and engineered to be the base layer for all of your containerized applications, middleware and utilities. This base image is freely redistributable, but Red Hat only supports Red Hat technologies through subscriptions for Red Hat products. This image is maintained by Red Hat and updated regularly.", "distribution-scope": "public", "io.buildah.version": "1.29.0", "io.k8s.description": "The Universal Base Image is designed and engineered to be the base layer for all of your containerized applications, middleware and utilities. This base image is freely redistributable, but Red Hat only supports Red Hat technologies through subscriptions for Red Hat products. This image is maintained by Red Hat and updated regularly.", "io.k8s.display-name": "Red Hat Universal Base Image 8", "io.openshift.expose-services": "", "io.openshift.tags": "base rhel8", "maintainer": "Red Hat, Inc.", "name": "ubi8", "release": "1067", "summary": "Provides the latest release of Red Hat Universal Base Image 8.", "url": "https://access.redhat.com/containers/#/registry.access.redhat.com/ubi8/images/8.8-1067", "vcs-ref": "384f2bb33eebab960262e967aa16d01fe2dbebff", "vcs-type": "git", "vendor": "Red Hat, Inc.", "version": "8.8"}, "OnBuild": null, "OpenStdin": false, "Passwd": true, "StdinOnce": false, "StopSignal": 15, "StopTimeout": 10, "Timeout": 0, "Tty": false, "Umask": "0022", "User": "", "Volumes": null, "WorkingDir": "/"}, "ConmonPidFile": "/run/user/1000/containers/overlay-containers/0e4a74b86abc352bdfcb1f38f90ff12e1f47a8462cdf76d9af616e45f0bc6783/userdata/conmon.pid", "Created": "2023-09-27T09:56:44.137506395+02:00", "Dependencies": [], "Driver": "overlay", "EffectiveCaps": ["CAP_CHOWN", "CAP_DAC_OVERRIDE", "CAP_FOWNER", "CAP_FSETID", "CAP_KILL", "CAP_NET_BIND_SERVICE", "CAP_NET_RAW", "CAP_SETFCAP", "CAP_SETGID", "CAP_SETPCAP", "CAP_SETUID", "CAP_SYS_CHROOT"], "ExecIDs": [], "GraphDriver": {"Data": {"LowerDir": "/home/tins/.local/share/containers/storage/overlay/4f16824046fe531a901ddf7c37fd7074341381edc679b5d2c3a2171e71c32831/diff", "UpperDir": "/home/tins/.local/share/containers/storage/overlay/8f7589ad7ab77e8f9303bbf6a6b4f70f89207f83fd24b10130f97618a72896fd/diff", "WorkDir": "/home/tins/.local/share/containers/storage/overlay/8f7589ad7ab77e8f9303bbf6a6b4f70f89207f83fd24b10130f97618a72896fd/work"}, "Name": "overlay"}, "HostConfig": {"AutoRemove": false, "Binds": [], "BlkioDeviceReadBps": null, "BlkioDeviceReadIOps": null, "BlkioDeviceWriteBps": null, "BlkioDeviceWriteIOps": null, "BlkioWeight": 0, "BlkioWeightDevice": null, "CapAdd": [], "CapDrop": ["CAP_AUDIT_WRITE", "CAP_MKNOD"], "Cgroup": "", "CgroupConf": null, "CgroupManager": "cgroupfs", "CgroupMode": "host", "CgroupParent": "", "Cgroups": "default", "ConsoleSize": [0, 0], "ContainerIDFile": "", "CpuCount": 0, "CpuPercent": 0, "CpuPeriod": 0, "CpuQuota": 0, "CpuRealtimePeriod": 0, "CpuRealtimeRuntime": 0, "CpuShares": 0, "CpusetCpus": "", "CpusetMems": "", "Devices": [], "DiskQuota": 0, "Dns": [], "DnsOptions": [], "DnsSearch": [], "ExtraHosts": [], "GroupAdd": [], "IOMaximumBandwidth": 0, "IOMaximumIOps": 0, "IpcMode": "shareable", "Isolation": "", "KernelMemory": 0, "Links": null, "LogConfig": {"Config": null, "Path": "/home/tins/.local/share/containers/storage/overlay-containers/0e4a74b86abc352bdfcb1f38f90ff12e1f47a8462cdf76d9af616e45f0bc6783/userdata/ctr.log", "Size": "0B", "Tag": "", "Type": "k8s-file"}, "Memory": 0, "MemoryReservation": 0, "MemorySwap": 0, "MemorySwappiness": 0, "NanoCpus": 0, "NetworkMode": "slirp4netns", "OomKillDisable": false, "OomScoreAdj": 0, "PidMode": "private", "PidsLimit": 0, "PortBindings": {}, "Privileged": false, "PublishAllPorts": false, "ReadonlyRootfs": false, "RestartPolicy": {"MaximumRetryCount": 0, "Name": ""}, "Runtime": "oci", "SecurityOpt": [], "ShmSize": 65536000, "Tmpfs": {}, "UTSMode": "private", "Ulimits": [], "UsernsMode": "", "VolumeDriver": "", "VolumesFrom": null}, "HostnamePath": "", "HostsPath": "", "Id": "0e4a74b86abc352bdfcb1f38f90ff12e1f47a8462cdf76d9af616e45f0bc6783", "Image": "27e761650ada195871070d642e111311ffc297690bdd3d263145912b90d0dd6d", "ImageName": "registry.access.redhat.com/ubi8:latest", "IsInfra": false, "MountLabel": "system_u:object_r:container_file_t:s0:c325,c365", "Mounts": [], "Name": "test_env", "Namespace": "", "NetworkSettings": {"Bridge": "", "EndpointID": "", "Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "HairpinMode": false, "IPAddress": "", "IPPrefixLen": 0, "IPv6Gateway": "", "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "MacAddress": "", "Ports": {}, "SandboxID": "", "SandboxKey": ""}, "OCIRuntime": "runc", "Path": "/bin/bash", "PidFile": "/run/user/1000/containers/overlay-containers/0e4a74b86abc352bdfcb1f38f90ff12e1f47a8462cdf76d9af616e45f0bc6783/userdata/pidfile", "Pod": "", "ProcessLabel": "system_u:system_r:container_t:s0:c325,c365", "ResolvConfPath": "", "RestartCount": 0, "Rootfs": "", "State": {"CheckpointedAt": "0001-01-01T00:00:00Z", "Dead": false, "Error": "", "ExitCode": 0, "FinishedAt": "0001-01-01T00:00:00Z", "Health": {"FailingStreak": 0, "Log": null, "Status": ""}, "OOMKilled": false, "OciVersion": "1.0.2-dev", "Paused": false, "Pid": 0, "Restarting": false, "RestoredAt": "0001-01-01T00:00:00Z", "Running": false, "StartedAt": "0001-01-01T00:00:00Z", "Status": "created"}, "StaticDir": "/home/tins/.local/share/containers/storage/overlay-containers/0e4a74b86abc352bdfcb1f38f90ff12e1f47a8462cdf76d9af616e45f0bc6783/userdata"}, "podman_actions": [], "podman_systemd": {"container-test_env": "# container-test_env.service\n# autogenerated by Podman 4.1.1\n# Wed Sep 27 10:00:56 CEST 2023\n\n[Unit]\nDescription=Podman container-test_env.service\nDocumentation=man:podman-generate-systemd(1)\nWants=network-online.target\nAfter=network-online.target\nRequiresMountsFor=/run/user/1000/containers\n\n[Service]\nEnvironment=PODMAN_SYSTEMD_UNIT=%n\nRestart=on-failure\nTimeoutStopSec=70\nExecStart=/usr/bin/podman start test_env\nExecStop=/usr/bin/podman stop -t 10 test_env\nExecStopPost=/usr/bin/podman stop -t 10 test_env\nPIDFile=/run/user/1000/containers/overlay-containers/0e4a74b86abc352bdfcb1f38f90ff12e1f47a8462cdf76d9af616e45f0bc6783/userdata/conmon.pid\nType=forking\n\n[Install]\nWantedBy=default.target\n"}, "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
META: ran handlers
META: ran handlers

PLAY RECAP *****************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Additional environment details (AWS, VirtualBox, physical, etc.):

sshnaidm commented 11 months ago

This is a YAML thing, you use boolean and it's translated to Python True. Just use quotes to make it string:

      env:
        BOOLEAN: 'true'
tinsjourney commented 11 months ago

Thanks @sshnaidm didn't know about this YAML specificity.

Sorry for the noise, I close the issue