'My playbook is not downloading the updated images with same tag name

I have been using jenkins to build docker images and push to docker hub with the tag latest in everytime. I have written a ansible playbook which will deploy the docker images by pulling the latest image from docker hub.Now issue is new latest images has not been pulled by ansible once it deployed its previous version with same tag.Can you please check the playbook and let me know which part should i update to get the desired work.

Playbook:

---
- hosts: flask04
  tasks:
  - name: Pull Flask app  image
    docker_image:
      name: taybur/flaskapp_27032019
      tag: latest
      state: present 

  - name: remove flask app container
    docker_container:
     name: first_flaskapp
     image: taybur/flaskapp_27032019
     state: absent

  - name: Create flask app container
    docker_container:
     name: first_flaskapp
     image: taybur/flaskapp_27032019
     ports:
       - "5001:5001"
     state: started


Solution 1:[1]

Ideally, we should have our tasks/roles idempotent(skip duplicate work if ran repeatedly). So, I think it is cleaner to tag your builds with version numbers and use the version number in your deployment instead of latest.

Solution 2:[2]

I usually remove the old image as part of cleaning up before installing. You should first remove the image, just like you remove the container. This will force ansible to pull the new version of the image.

---
- hosts: flask04
  tasks:
  - name: Remove Flask app  image
    docker_image:
      name: taybur/flaskapp_27032019
      tag: latest
      force: true
      state: absent 

  - name: Pull Flask app  image
    docker_image:
      name: taybur/flaskapp_27032019
      tag: latest
      state: present 

  - name: remove flask app container
    docker_container:
     name: first_flaskapp
     image: taybur/flaskapp_27032019
     state: absent

  - name: Create flask app container
    docker_container:
     name: first_flaskapp
     image: taybur/flaskapp_27032019
     ports:
       - "5001:5001"
     state: started

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Purushotham Kumar
Solution 2 Zeitounator