Ansible task with tag ‘never’ inside role executed when the role is executed using another tag

ansibleansible-playbook

I have a playbook which has three roles netdata, netdata_master, netdata_slaves:

---
- hosts: netdata_master
  become: yes
  roles: 
    - role: netdata
    - role: netdata_master
  tags: ['netdata_master']

- hosts: netdata_slaves
  become: yes
  roles:
    - role: netdata
    - role: netdata_slave
  tags: ['netdata_slave']

Inside the netdata role I have a task which has tag never and update_netdata in order to be executed only when I pass the tag update_netdata:

- name: Generating Netdata prebuilt script
  template:
    src: kickstart-static64.sh.j2
    dest: /tmp/kickstart-static64.sh
    mode: 0744
- name: update netdata
  shell: /opt/netdata/usr/libexec/netdata/netdata-updater.sh
  tags: ['never', 'update_netdata']

The problem is when I execute the ansible playbook with no tags, everything works fine and update netdata is not executed but when I run the ansible playbook with netdata_slave tag, the update netdata task also gets executed.

I'm using ansible 2.9.2

How can I fix this?

Best Answer

Q: "When I run the ansible playbook with netdata_slave tag, the update netdata task also gets executed."

A: This works as expected. Quoting from Tag Inheritance:

Adding tags: to a play, or to statically imported tasks and roles, adds those tags to all of the contained tasks.

The directive tags: ['netdata_slave'] adds this tag to all of the contained tasks of the role: netdata

  roles:
    - role: netdata
  tags: ['netdata_slave']

This makes the task to look effectively

- name: update netdata
  shell: /opt/netdata/usr/libexec/netdata/netdata-updater.sh
  tags: ['never', 'update_netdata', 'netdata_slave']