skip-tags doesn't work for handlers

1,650 views
Skip to first unread message

Ivaylo Bratoev

unread,
Feb 23, 2015, 6:36:07 AM2/23/15
to ansible...@googlegroups.com
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.

Dick Davies

unread,
Feb 23, 2015, 6:55:19 AM2/23/15
to ansible list
shouldn't that be :

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

?
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/a9b783a3-ac34-4802-af8d-d9a3fa94de6d%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Ivaylo Bratoev

unread,
Feb 23, 2015, 7:15:53 AM2/23/15
to ansible...@googlegroups.com, di...@hellooperator.net
Both are the same... Just a different ways to write YAML.

Serge van Ginderachter

unread,
Feb 23, 2015, 8:04:40 AM2/23/15
to ansible...@googlegroups.com, di...@hellooperator.net

On 23 February 2015 at 13:15, Ivaylo Bratoev <ivaylo....@gmail.com> wrote:
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 :)

Brian Coca

unread,
Feb 23, 2015, 9:43:42 AM2/23/15
to ansible...@googlegroups.com, di...@hellooperator.net
Handlers ignore tags, they only run when notified and always run when notified
--
Brian Coca

Ivaylo Bratoev

unread,
Mar 5, 2015, 3:02:17 AM3/5/15
to ansible...@googlegroups.com, di...@hellooperator.net
So there is not way to skip a handler through ansible-playbook... Consider that a feature request ;)

Dan C

unread,
Jun 6, 2015, 6:14:50 AM6/6/15
to ansible...@googlegroups.com, di...@hellooperator.net
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?

Dan C

unread,
Jun 7, 2015, 6:18:23 AM6/7/15
to ansible...@googlegroups.com, di...@hellooperator.net
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.

Brian Coca

unread,
Jun 7, 2015, 5:47:35 PM6/7/15
to ansible...@googlegroups.com, di...@hellooperator.net
handlers are not affected by tags in general, but they should be
affected by when:

--
Brian Coca

Dan C

unread,
Jun 8, 2015, 4:46:21 AM6/8/15
to ansible...@googlegroups.com, di...@hellooperator.net
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?

Dan C

unread,
Jun 8, 2015, 8:37:07 AM6/8/15
to ansible...@googlegroups.com, di...@hellooperator.net
Sorry Brian,

My bad. It works with the "when" statement on the handler.
Reply all
Reply to author
Forward
0 new messages