diff --git a/plugins/module_utils/podman/podman_container_lib.py b/plugins/module_utils/podman/podman_container_lib.py index 52dc2f8..d84d5d1 100644 --- a/plugins/module_utils/podman/podman_container_lib.py +++ b/plugins/module_utils/podman/podman_container_lib.py @@ -1043,9 +1043,12 @@ class PodmanContainerDiff: # TODO(sshnaidm) Need to add port ranges support def diffparam_publish(self): def compose(p, h): - return ":".join( - [h['hostip'], str(h["hostport"]), p.replace('/tcp', '')] + s = ":".join( + [str(h["hostport"]), p.replace('/tcp', '')] ).strip(":") + if h['hostip']: + return ":".join([h['hostip'], s]) + return s ports = self.info['hostconfig']['portbindings'] before = [] @@ -1057,7 +1060,9 @@ class PodmanContainerDiff: image_ports = self.image_info['config'].get('exposedports', {}) if image_ports: after += list(image_ports.keys()) - after = [i.replace("/tcp", "") for i in after] + after = [ + i.replace("/tcp", "").replace("[", "").replace("]", "") + for i in after] # No support for port ranges yet for ports in after: if "-" in ports: diff --git a/plugins/module_utils/podman/podman_pod_lib.py b/plugins/module_utils/podman/podman_pod_lib.py index ac0b5cc..aba037d 100644 --- a/plugins/module_utils/podman/podman_pod_lib.py +++ b/plugins/module_utils/podman/podman_pod_lib.py @@ -380,7 +380,9 @@ class PodmanPodDiff: i.replace('/tcp', '') ]).strip(':') for i, j in ports.items()] after = self.params['publish'] or [] - after = [i.replace("/tcp", "") for i in after] + after = [ + i.replace("/tcp", "").replace("[", "").replace("]", "").strip(":") + for i in after] # No support for port ranges yet for ports in after: if "-" in ports: diff --git a/tests/integration/targets/podman_container_idempotency/tasks/root-podman.yml b/tests/integration/targets/podman_container_idempotency/tasks/root-podman.yml index eccc4e8..b3939d5 100644 --- a/tests/integration/targets/podman_container_idempotency/tasks/root-podman.yml +++ b/tests/integration/targets/podman_container_idempotency/tasks/root-podman.yml @@ -151,3 +151,43 @@ assert: that: - info7 is not changed + +- name: Run container with publishing ports and ipv6 + containers.podman.podman_container: + image: "{{ idem_image }}" + name: root-idempotency + state: present + command: 1h + ports: + - "4444:4444/tcp" + - "1212:5555" + - "8888:19191/udp" + - "127.0.0.1:7671:7676/udp" + - "127.0.0.3:43423:8872" + - "[::1]:34523:35425" + register: info8 + +- name: Check that it is recreated + assert: + that: + - info8 is changed + +- name: Run container with publishing ports and ipv6 again + containers.podman.podman_container: + image: "{{ idem_image }}" + name: root-idempotency + state: present + command: 1h + ports: + - "4444:4444/tcp" + - "1212:5555" + - "8888:19191/udp" + - "127.0.0.1:7671:7676/udp" + - "127.0.0.3:43423:8872" + - "[::1]:34523:35425" + register: info9 + +- name: Check that it is recreated + assert: + that: + - info9 is not changed diff --git a/tests/integration/targets/podman_pod/tasks/root-pod.yml b/tests/integration/targets/podman_pod/tasks/root-pod.yml index d002741..1a33041 100644 --- a/tests/integration/targets/podman_pod/tasks/root-pod.yml +++ b/tests/integration/targets/podman_pod/tasks/root-pod.yml @@ -107,6 +107,42 @@ that: - pod7_info is changed + - name: Start pod with ports for idempotency and ipv6 + containers.podman.podman_pod: + name: pod1 + state: started + ports: + - "4444:4444/tcp" + - "8888:19191/udp" + - "127.0.0.1:7671:7676/udp" + - "127.0.0.1:13122:8871/tcp" + - "127.0.0.1:43423:8872" + - "[::1]:8743:8745" + register: pod8_info + + - name: Check info + assert: + that: + - pod8_info is changed + + - name: Start pod with ports for idempotency and ipv6 again + containers.podman.podman_pod: + name: pod1 + state: started + ports: + - "4444:4444/tcp" + - "8888:19191/udp" + - "127.0.0.1:7671:7676/udp" + - "127.0.0.1:13122:8871/tcp" + - "127.0.0.1:43423:8872" + - "[::1]:8743:8745" + register: pod9_info + + - name: Check info + assert: + that: + - pod9_info is not changed + always: - name: Delete all pods leftovers from tests