1

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?

4

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']
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.