skip-tags doesn't work for handlers

Is it expected for ansible-playbook with –skip-tags to not skip handlers tagged properly?

Let me give an example. If you have the following handler:

`

  • name: NGINX reload
    service:
    name: nginx
    state: reloaded
    tags: reload

`

And you run:
ansible-playbook ... --skip-tags reload

Is it expected the handler to be skipped?

For me, it is not expected and I would consider it bug but want to double check that before posing an issue.

shouldn't that be :

- name: NGINX reload
  service: name=nginx state=reloaded
  tags: reload

?

Both are the same… Just a different ways to write YAML.

​Not exactly, both are equivalen notations that ansible parses​, the former
being pure yaml :slight_smile:

Handlers ignore tags, they only run when notified and always run when notified

So there is not way to skip a handler through ansible-playbook… Consider that a feature request :wink:

I would like the same feature.

I don’t know if there is another way to do what I am trying to do.
My case of use would be to be able to use the same roles/playbooks to mantain the configuration along all my servers and for the AMI creation. In the case of an ami creation I don’t want the services to start o restart, I don’t want to execute a restart when copying the config file.

Is there any other way to do taht without skiping handlers?

I tried with a “when” statement on the handler definition (with a variable defined by me) but id didn’t seem to work either, the handler is executed anyway, and the AMI creation fails for that.

handlers are not affected by tags in general, but they should be
affected by when:

Thanks Brian,

Is there a minimum version for the “when” statment to work with handlers?
The ansible version I am using for this test is 1.7.2

I have:

file: roles/beaver-configure/handlers/main.yml

  • name: restart beaver
    service: name=beaver.sh state=restarted
    when: flag_not_restart is not defined

file: roles/beaver-configure/tasks/main.yml

  • name: Copy conf beaver
    template: src=…/templates/conf.j2 dest=/etc/beaver/conf group=root owner=root mode=0644
    notify: restart beaver
  • name: Start a enable beaver
    service: name=beaver.sh enabled=yes state=started

I call an ansible playbook which calls the beaver role with:
/usr/local/bin/ansible-playbook /tmp/ansible-local/php.yml --extra-vars ‘flag_not_restart=1’ -c local -i /tmp/ansible-local/localhost.inv

If I debug the “flag_not_restart” I can see it exist and is “1”.
And yet the “restart beaver” handler is called and executed.

So, am I doing something wrong?

Sorry Brian,

My bad. It works with the “when” statement on the handler.