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
274 stars 148 forks source link

Quadlet Label Value Truncation Due to Missing Quotes #807

Open tjmullicani opened 4 months ago

tjmullicani commented 4 months ago

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

/kind bug

Description When a Quadlet file is written, the "Label=" line values are not quoted. This causes issues if there are special or escape characters in the value.

For example, the following quadlet file is currently generated.

[Container]
ContainerName=testapp
...
Label=traefik.enable=True
Label=traefik.http.routers.testapp.rule=( Host(`test.com`) && PathPrefix(`/path`) )

When it should be (notice the extra quotes around Label=.

[Container]
ContainerName=testapp
...
Label=traefik.enable="True"
Label=traefik.http.routers.testapp.rule="( Host(`test.com`) && PathPrefix(`/path`) )"

Steps to reproduce the issue:

- containers.podman.podman_container:
     name: testapp
     state: quadlet
     quadlet_filename: container-testapp
     quadlet_options:
       - "AutoUpdate=registry"
       - "Pull=always"
       - |
         [Install]
         WantedBy=default.target
    network:
      - podman
    image: docker.io/containous/whoami
    labels:
      traefik.enable: true
      traefik.http.routers.testapp.rule: "( Host(`test.com`) && PathPrefix(`/path`) )"

Describe the results you received:

$ podman inspect testapp
...
      "Labels": {
        "traefik.http.routers.testapp.rule": "(",
      }

Describe the results you expected:

$ podman inspect testapp
...
      "Labels": {
        "traefik.http.routers.testapp.rule": "( Host(`test.com`) && PathPrefix(`/path`) )",
      }

Double quoting the label within containers.podman.podmain_container is a workaround.

...
- containers.podman.podman_container:
    ...
    labels:
      traefik.http.routers.testapp.rule: "\"( Host(`test.com`) && PathPrefix(`/path`)\""
...

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.15.4

Output of ansible --version:

ansible [core 2.15.10]

Output of podman version:

$ podman --version
podman version 4.9.4-rhel

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

$ rpm -q podman
podman-4.9.4-4.module+el8.10.0+21995+81e8507c.x86_64
sshnaidm commented 4 months ago

I think this workaround might be actually a legit way to do quotes inside, anyway we'll need to escape quotes in the label value if they exist.