# Other settings
- name: Remove leftovers from other tests
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    name: idempotency
    state: absent

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

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

- name: Check info when running container again
  assert:
    that: test1 is not changed

- name: Run container with environment vars
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    image: "{{ idem_image }}"
    name: idempotency
    state: present
    env:
      mykey: "amazing value"
      ENV1: "one=two=three"
    command: 1h
  register: test2

- name: Check info with environment vars
  assert:
    that: test2 is changed

- name: Run container with environment vars again
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    image: "{{ idem_image }}"
    name: idempotency
    state: present
    env:
      mykey: "amazing value"
      ENV1: "one=two=three"
    command: 1h
  register: test3

- name: Check info with environment vars again
  assert:
    that: test3 is not changed

- name: Run container with changed environment vars
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    image: "{{ idem_image }}"
    name: idempotency
    state: present
    env:
      mykey: "amazing value1"
      ENV1: "one=two=three"
    command: 1h
  register: test4

- name: Check info with changed environment vars
  assert:
    that: test4 is changed

- name: Run container with log opt tag
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    image: "{{ idem_image }}"
    name: idempotency
    state: present
    log_opt:
      tag: nonotag
    log_driver: journald
    command: 1h
  register: test9

- name: Check info with log opt tag
  assert:
    that: test9 is changed

- name: Run container with log opt tag - again
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    image: "{{ idem_image }}"
    name: idempotency
    state: present
    log_opt:
      tag: nonotag
    log_driver: journald
    command: 1h
  register: test10

- name: Check info with log opt tag - again
  assert:
    that: test10 is not changed

- name: Run container with default log opt tag
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    image: "{{ idem_image }}"
    name: idempotency
    state: present
    command: 1h
    log_driver: journald
  register: test11

- name: Check info with default log opt tag
  assert:
    that: test11 is changed

- name: Run container with log opt path
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    image: "{{ idem_image }}"
    name: idempotency
    state: present
    log_opt:
      path: /tmp/container.log
    log_driver: journald
    command: 1h
  register: test12

- name: Check info with log opt path
  assert:
    that: test12 is changed

- name: Run container with changed log opt path
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    image: "{{ idem_image }}"
    name: idempotency
    state: present
    log_opt:
      path: /tmp/container2.log
    log_driver: journald
    command: 1h
  register: test13

- name: Check info with changed log opt path
  assert:
    that: test13 is changed

- name: Run container with default log opt path
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    image: "{{ idem_image }}"
    name: idempotency
    state: present
    log_driver: journald
    command: 1h
  register: test14

# We can't guess the default log path
- name: Check info with default log opt path
  assert:
    that: test14 is not changed

- name: Run container with all log-opts
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    image: "{{ idem_image }}"
    name: idempotency
    state: present
    log_driver: journald
    log_opt:
      path: /tmp/container3.log
      max_size: 100mb
      tag: sometag
    command: 1h

- name: Run container with mounted /dev/fuse
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    image: "{{ idem_image }}"
    name: idempotency
    state: started
    command: 1h
    device:
      - /dev/fuse
  register: test15

- name: Run container with mounted /dev/fuse again
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    image: "{{ idem_image }}"
    name: idempotency
    state: started
    command: 1h
    device:
      - /dev/fuse
  register: test16

- name: Run container with mounted /dev/fuse:/dev/fuse
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    image: "{{ idem_image }}"
    name: idempotency
    state: started
    command: 1h
    device:
      - /dev/fuse:/dev/fuse
  register: test17

- name: Run container with mounted /dev/fuse third time
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    image: "{{ idem_image }}"
    name: idempotency
    state: started
    command: 1h
    device:
      - /dev/fuse
  register: test18

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

- name: Check info with mounted devices
  assert:
    that:
      - test15 is changed
      - test16 is not changed
      - test17 is not changed
      - test18 is not changed
      - test19 is changed

- name: Remove test container
  containers.podman.podman_container:
    executable: "{{ test_executable | default('podman') }}"
    name: idempotency
    state: absent
