Ansible tags - task not getting invoked

Viewed 71

This is very strange.

There are two tasks with the 'buffer' tag, and two tasks with the 'hmu' tag. If I run the below playbook with 'buffer' tag, it works and runs the two tasks tagged with 'buffer'. But If I run the playbook with tag 'hmu' it would not run the first task with the 'hmu' tag, however, it will run the last task tagged with 'hmu'. How can this outcome logically follow?

---
- hosts: LAB
  connection: local
  gather_facts: true
  serial: 1
  order: sorted

  tasks:
    - import_role:
        name: buffer_stats
      tags:
        - buffer
    - import_role:
        name: hmu_stats
      tags:
        - hmu

- hosts: localhost

  tasks:
    - import_role:
        name: buffer_stats
        tasks_from: notifications.yml
      tags:
        - buffer
    - import_role:
        name: hmu_stats
        tasks_from: notifications.yml
      tags:
        - hmu
1 Answers

The roles

shell> cat roles/buffer_stats/tasks/main.yml
- debug:
    msg: buffer_stats main.yml
shell> cat roles/buffer_stats/tasks/notifications.yml 
- debug:
    msg: buffer_stats notifications.yml
shell> cat roles/hmu_stats/tasks/main.yml
- debug:
    msg: hmu_stats main.yml
shell> cat roles/hmu_stats/tasks/notifications.yml 
- debug:
    msg: hmu_stats notifications.yml

and the playbook

shell> cat pb.yml 
- hosts: localhost
  tasks:
    - import_role:
        name: buffer_stats
      tags: buffer
    - import_role:
        name: hmu_stats
      tags: hmu

- hosts: localhost
  tasks:
    - import_role:
        name: buffer_stats
        tasks_from: notifications.yml
      tags: buffer
    - import_role:
        name: hmu_stats
        tasks_from: notifications.yml
      tags: hmu

work as expected

shell> ansible-playbook pb.yml -t buffer

PLAY [localhost] ****

TASK [buffer_stats : debug] ****
ok: [localhost] => 
  msg: buffer_stats main.yml

PLAY [localhost] ****

TASK [buffer_stats : debug] ****
ok: [localhost] => 
  msg: buffer_stats notifications.yml
shell> ansible-playbook pb.yml -t hmu

PLAY [localhost] ****

TASK [hmu_stats : debug] ****
ok: [localhost] => 
  msg: hmu_stats main.yml

PLAY [localhost] ****

TASK [hmu_stats : debug] ****
ok: [localhost] => 
  msg: hmu_stats notifications.yml
Related