Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish option short-hand always recreates container #116

Closed
roxifas opened this issue Oct 5, 2020 · 6 comments · Fixed by #120
Closed

Publish option short-hand always recreates container #116

roxifas opened this issue Oct 5, 2020 · 6 comments · Fixed by #120
Labels
bug Something isn't working documentation Improvements or additions to documentation

Comments

@roxifas
Copy link

roxifas commented Oct 5, 2020

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

/kind bug

Description

The publish option will always trigger a container recreate if it's defined in the short-hand form, for example:

publish:
  - "3306"

But the below works correctly:

publish:
  - "3306:3306"

Steps to reproduce the issue:

  1. This playbook content:
  - name: Create mysql container
    containers.podman.podman_container:
      name: db
      image: docker.io/mysql
      state: present
      publish:
        - "3306"

Describe the results you received:

Container is always recreated despite configuration not being changed.

Describe the results you expected:

Container should not be recreated if the configuration is the same.

Output of ansible --version:

ansible 2.9.13
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/roxifas/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.7.9 (default, Aug 19 2020, 17:05:11) [GCC 9.3.1 20200408 (Red Hat 9.3.1-2)]

Output of podman version:

Version:      2.1.1
API Version:  2.0.0
Go Version:   go1.13.15
Built:        Sun Sep 27 23:37:44 2020
OS/Arch:      linux/amd64

Output of podman info --debug:

Content
host:
  arch: amd64
  buildahVersion: 1.16.1
  cgroupManager: cgroupfs
  cgroupVersion: v1
  conmon:
    package: conmon-2.0.21-1.el8.x86_64
    path: /usr/bin/conmon
    version: 'conmon version 2.0.21, commit: 3460cd1ad859a79bd27df1714f39c76926ac1b39-dirty'
  cpus: 1
  distribution:
    distribution: '"centos"'
    version: "8"
  eventLogger: journald
  hostname: **REDACTED**
  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-193.19.1.el8_2.x86_64
  linkmode: dynamic
  memFree: 171679744
  memTotal: 1915719680
  ociRuntime:
    name: runc
    package: runc-1.0.0-145.rc91.git24a3cf8.el8.x86_64
    path: /usr/bin/runc
    version: 'runc version spec: 1.0.2-dev'
  os: linux
  remoteSocket:
    path: /run/user/1000/podman/podman.sock
  rootless: true
  slirp4netns:
    executable: /usr/bin/slirp4netns
    package: slirp4netns-1.1.4-2.el8.x86_64
    version: |-
      slirp4netns version 1.1.4
      commit: b66ffa8e262507e37fca689822d23430f3357fe8
      libslirp: 4.3.1
      SLIRP_CONFIG_VERSION_MAX: 3
  swapFree: 0
  swapTotal: 0
  uptime: 3h 22m 41.11s (Approximately 0.12 days)
registries:
  search:
  - registry.fedoraproject.org
  - registry.access.redhat.com
  - registry.centos.org
  - docker.io
store:
  configFile: /home/roxifas/.config/containers/storage.conf
  containerStore:
    number: 4
    paused: 0
    running: 4
    stopped: 0
  graphDriverName: overlay
  graphOptions:
    overlay.mount_program:
      Executable: /usr/bin/fuse-overlayfs
      Package: fuse-overlayfs-1.1.2-1.el8.x86_64
      Version: |-
        fusermount3 version: 3.2.1
        fuse-overlayfs: version 1.1.0
        FUSE library version 3.2.1
        using FUSE kernel interface version 7.26
  graphRoot: /home/roxifas/.local/share/containers/storage
  graphStatus:
    Backing Filesystem: extfs
    Native Overlay Diff: "false"
    Supports d_type: "true"
    Using metacopy: "false"
  imageStore:
    number: 6
  runRoot: /run/user/1000
  volumePath: /home/roxifas/.local/share/containers/storage/volumes
version:
  APIVersion: 2.0.0
  Built: 1601239064
  BuiltTime: Sun Sep 27 23:37:44 2020
  GitCommit: ""
  GoVersion: go1.13.15
  OsArch: linux/amd64
  Version: 2.1.1

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

podman-2.1.1-4.el8.x86_64

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

  - name: Create mysql container
    containers.podman.podman_container:
      name: db
      image: docker.io/mysql
      state: present
      publish:
        - "3306"

Command line and output of ansible run with high verbosity:
Redacted because it contained sensitive information, but I think this diff tells the story rather accurately:

--- before
+++ after
@@ -1 +1 @@
-publish - ['3306:3306']
+publish - ['3306']

Additional environment details (AWS, VirtualBox, physical, etc.):
Target environment is a CentOS VPS.

@sshnaidm sshnaidm added bug Something isn't working bug/idempotency Bug related to idempotency of modules labels Oct 7, 2020
@sshnaidm
Copy link
Member

sshnaidm commented Oct 7, 2020

Seems like in podman 1.x versions the host port is random and in 2.x versions it's equal to container port. So in 1.x versions it will be like 3306:43728, while in 2.x it's 3306:3306. Need to workaround both versions.
Unfortunately it's impossible to know if 3306:43728 was set by user or it was random port, so the fix will be for 2.x versions only.

@sshnaidm
Copy link
Member

sshnaidm commented Oct 7, 2020

@roxifas ok, so after some clarifications in containers/podman#7947 we found out that if you set only one port 3360 it can be assigned to any random host port, for example 45362. The fact it's assigned to the same 3360 is actually a bug and will be fixed by containers/podman#7951 soon.
Given that, I'm not sure what is the point to set only one port? It will be assigned to random host port and we can't know what it can be.

@sshnaidm sshnaidm added the needs_info More information about case is required label Oct 7, 2020
@roxifas
Copy link
Author

roxifas commented Oct 8, 2020

Well that's good to know, I had actually started building my scripts with the thought that the port would be the same 🤔 I guess there are some usecases where people will want to have a random port, and they would have their containers constantly recreated by ansible. So perhaps the fix would be to ignore a non-matching host port if the ansible playbook has only the container port defined, because it means that the host port will be random anyway and should not be a reason to recreate the container. What do you think? @sshnaidm

@sshnaidm
Copy link
Member

sshnaidm commented Oct 8, 2020

@roxifas the problem in this case that we can't detect for sure was it random port assigned by podman or non-random port assigned by user. For example some user can assign - 3360:43234 and other user can do - 3360. In both cases in info it will be

"PortBindings": {
                "3360/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "43234"
                    }
                ]
            },

and no way to know if there is chosen by podman or user port.
The more I think about it the less I understand the logic behind the "randomness" of host port. But this is better to discuss in containers/podman#7947

@roxifas
Copy link
Author

roxifas commented Oct 8, 2020

If this information, about host port being random or not, is not stored anywhere, then this cannot really be fixed in the ansible module. It would be worth to mention this in the docs however, so that users do not get surprised by containers getting recreated unexpectedly.

@sshnaidm sshnaidm removed the needs_info More information about case is required label Oct 8, 2020
@sshnaidm
Copy link
Member

sshnaidm commented Oct 8, 2020

Yes, it's worth to mention in docs.

@sshnaidm sshnaidm added documentation Improvements or additions to documentation and removed bug/idempotency Bug related to idempotency of modules labels Oct 8, 2020
sshnaidm added a commit to sshnaidm/ansible-podman-collections that referenced this issue Oct 8, 2020
sshnaidm added a commit that referenced this issue Oct 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants