---
####################################################################
## basic ###########################################################
####################################################################

- name: Make sure image is not there
  docker_image:
    name: "quay.io/ansible/docker-test-containers:hello-world"
    state: absent
    force_absent: yes
  register: absent_1

- name: Make sure image is not there (idempotency)
  docker_image:
    name: "quay.io/ansible/docker-test-containers:hello-world"
    state: absent
  register: absent_2

- assert:
    that:
    - absent_2 is not changed

- name: Make sure image is there
  docker_image:
    name: "quay.io/ansible/docker-test-containers:hello-world"
    state: present
    source: pull
  register: present_1

- name: Make sure image is there (idempotent)
  docker_image:
    name: "quay.io/ansible/docker-test-containers:hello-world"
    state: present
    source: pull
  register: present_2

- assert:
    that:
    - present_1 is changed
    - present_2 is not changed

- name: Make sure tag is not there
  docker_image:
    name: "quay.io/ansible/docker-test-containers:alias"
    state: absent

- name: Tag image with alias
  docker_image:
    source: local
    name: "quay.io/ansible/docker-test-containers:hello-world"
    repository: "quay.io/ansible/docker-test-containers:alias"
  register: tag_1

- name: Tag image with alias (idempotent)
  docker_image:
    source: local
    name: "quay.io/ansible/docker-test-containers:hello-world"
    repository: "quay.io/ansible/docker-test-containers:alias"
  register: tag_2

- name: Tag image with alias (force, still idempotent)
  docker_image:
    source: local
    name: "quay.io/ansible/docker-test-containers:hello-world"
    repository: "quay.io/ansible/docker-test-containers:alias"
    force_tag: yes
  register: tag_3

- assert:
    that:
    - tag_1 is changed
    - tag_2 is not changed
    - tag_3 is not changed

- name: Cleanup alias tag
  docker_image:
    name: "ansible/docker-test-containers:alias"
    state: absent
