---
- name: Test podman tag
  block:
    - name: Pull image
      containers.podman.podman_image:
        name: docker.io/library/alpine

    - name: Tag image
      containers.podman.podman_tag:
        image: docker.io/library/alpine
        target_names:
          - openjdk8
          - jdk8

    - name: Get tagged image info
      containers.podman.podman_image_info:
        name: docker.io/library/alpine
      register: tagged_image_result

    - name: Check results
      assert:
        that:
          - tagged_image_result.images | length == 1
          - "'docker.io/library/alpine' in tagged_image_result.images[0]['RepoTags'][0]"
          - "'localhost/openjdk8:latest' in tagged_image_result.images[0]['RepoTags'][1]"
          - "'localhost/jdk8:latest' in tagged_image_result.images[0]['RepoTags'][2]"

  always:
    - name: Cleanup image
      containers.podman.podman_image:
        name: "{{ item }}"
        state: absent
      loop:
        - docker.io/library/alpine
        - localhost/openjdk8
        - localhost/jdk8
