# Other settings
- name: Remove leftovers from other tests
  containers.podman.podman_container:
    name: idempotency
    state: absent

- name: Run container
  containers.podman.podman_container:
    image: "{{ idem_image }}"
    name: idempotency
    state: present
    command: 1h

- name: Run container again
  containers.podman.podman_container:
    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:
    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:
    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:
    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 level
  containers.podman.podman_container:
    image: "{{ idem_image }}"
    name: idempotency
    state: present
    log_level: debug
    command: 1h
  register: test5

- name: Check info with log level
  assert:
    that: test5 is changed

- name: Run container with log level again
  containers.podman.podman_container:
    image: "{{ idem_image }}"
    name: idempotency
    state: present
    log_level: debug
    command: 1h
  register: test6

- name: Check info with log level again
  assert:
    that: test6 is not changed

- name: Run container with changed log level
  containers.podman.podman_container:
    image: "{{ idem_image }}"
    name: idempotency
    state: present
    log_level: fatal
    command: 1h
  register: test7

- name: Check info with changed log level
  assert:
    that: test7 is changed

- name: Run container with default log level
  containers.podman.podman_container:
    image: "{{ idem_image }}"
    name: idempotency
    state: present
    command: 1h
  register: test8

- name: Check info with default log level
  assert:
    that: test8 is changed

- name: Run container with log opt tag
  containers.podman.podman_container:
    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:
    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:
    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:
    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:
    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:
    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:
    image: "{{ idem_image }}"
    name: idempotency
    state: present
    log_driver: journald
    log_opt:
      path: /tmp/container3.log
      max_size: 100mb
      tag: sometag
    command: 1h

- name: Remove test container
  containers.podman.podman_container:
    name: idempotency
    state: absent
