---
# Ulimits testing
- name: Make sure container doesn't exist
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    name: root-idempotency
    state: absent

- name: Run container as is
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    image: "{{ idem_image }}"
    name: root-idempotency
    state: started
    command: 1h

- name: Run container as is again
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    image: "{{ idem_image }}"
    name: root-idempotency
    state: present
    command: 1h
  register: info_a

- name: Check that it is not recreated
  assert:
    that:
      - info_a is not changed

- name: Run containers with ulimits
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    image: "{{ idem_image }}"
    name: root-idempotency
    state: present
    command: 1h
    ulimit:
      - 'nofile=55535:55535'
      - 'memlock=-1:-1'
  register: info

- name: Check that it is recreated
  assert:
    that:
      - info is changed

- name: Run containers with ulimits - idempotency
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    image: "{{ idem_image }}"
    name: root-idempotency
    state: present
    command: 1h
    ulimit:
      - 'nofile=55535:55535'
      - 'memlock=-1:-1'
  register: info1

- name: Check that it is recreated
  assert:
    that:
      - info1 is not changed

- name: Run containers with changed ulimits
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    image: "{{ idem_image }}"
    name: root-idempotency
    state: present
    command: 1h
    ulimit:
      - 'nofile=55535:65535'
      - 'memlock=-1:-1'
  register: info2

- name: Check that it is recreated
  assert:
    that:
      - info2 is changed

- name: Run containers with changed ulimits - idempotency
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    image: "{{ idem_image }}"
    name: root-idempotency
    state: present
    command: 1h
    ulimit:
      - 'nofile=55535:65535'
      - 'memlock=-1:-1'
  register: info3

- name: Check that it is recreated
  assert:
    that:
      - info3 is not changed

- name: Run default container
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    image: "{{ idem_image }}"
    name: root-idempotency
    state: started
    command: 1h

- name: Run containers with MAC address
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    image: "{{ idem_image }}"
    name: root-idempotency
    state: started
    command: 1h
    mac_address: 44:55:66:77:88:99
  register: info4

- name: Check that it is not recreated
  assert:
    that:
      - info4 is changed
      - info4.container['NetworkSettings']['MacAddress'] == '44:55:66:77:88:99'

- name: Run containers with MAC address again - idempotency
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    image: "{{ idem_image }}"
    name: root-idempotency
    state: present
    command: 1h
    mac_address: 44:55:66:77:88:99
  register: info5

- name: Check that it is not recreated
  assert:
    that:
      - info5 is not changed

- name: Run containers with MAC address changed
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    image: "{{ idem_image }}"
    name: root-idempotency
    state: present
    command: 1h
    mac_address: 44:55:66:77:88:33
  register: info6

- name: Check that it is recreated
  assert:
    that:
      - info6 is changed

- name: Run again default container
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    image: "{{ idem_image }}"
    name: root-idempotency
    state: present
    command: 1h
  register: info7

- name: Check that it is recreated
  assert:
    that:
      - info7 is not changed

- name: Run container with publishing ports and ipv6
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    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:
    executable: "{{ test_executable | default('podman') }}"
    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

- name: Make sure container doesn't exist
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    name: root-idempotency
    state: absent
