2012-08-01 04:19:04 +02:00
|
|
|
Tags
|
2013-09-30 01:03:51 +02:00
|
|
|
====
|
2012-08-07 04:32:40 +02:00
|
|
|
|
2015-02-13 03:15:44 +01:00
|
|
|
If you have a large playbook it may become useful to be able to run a
|
|
|
|
specific part of the configuration without running the whole playbook.
|
2013-10-03 04:06:56 +02:00
|
|
|
|
|
|
|
Both plays and tasks support a "tags:" attribute for this reason.
|
2012-08-01 04:19:04 +02:00
|
|
|
|
|
|
|
Example::
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
|
2013-07-15 19:50:48 +02:00
|
|
|
- yum: name={{ item }} state=installed
|
2012-08-01 04:19:04 +02:00
|
|
|
with_items:
|
|
|
|
- httpd
|
|
|
|
- memcached
|
|
|
|
tags:
|
|
|
|
- packages
|
|
|
|
|
2013-07-15 19:50:48 +02:00
|
|
|
- template: src=templates/src.j2 dest=/etc/foo.conf
|
2012-08-01 04:19:04 +02:00
|
|
|
tags:
|
|
|
|
- configuration
|
|
|
|
|
|
|
|
If you wanted to just run the "configuration" and "packages" part of a very long playbook, you could do this::
|
|
|
|
|
|
|
|
ansible-playbook example.yml --tags "configuration,packages"
|
2015-02-13 03:15:44 +01:00
|
|
|
|
2014-01-29 14:16:03 +01:00
|
|
|
On the other hand, if you want to run a playbook *without* certain tasks, you could do this::
|
|
|
|
|
|
|
|
ansible-playbook example.yml --skip-tags "notification"
|
2012-08-01 04:19:04 +02:00
|
|
|
|
2013-10-19 05:00:50 +02:00
|
|
|
You may also apply tags to roles::
|
2012-08-01 04:19:04 +02:00
|
|
|
|
2013-09-30 01:03:51 +02:00
|
|
|
roles:
|
|
|
|
- { role: webserver, port: 5000, tags: [ 'web', 'foo' ] }
|
2012-08-01 04:19:04 +02:00
|
|
|
|
2013-10-05 19:50:53 +02:00
|
|
|
And you may also tag basic include statements::
|
2012-05-13 17:56:09 +02:00
|
|
|
|
2013-09-30 01:03:51 +02:00
|
|
|
- include: foo.yml tags=web,foo
|
2012-05-13 17:00:02 +02:00
|
|
|
|
2013-09-30 01:03:51 +02:00
|
|
|
Both of these have the function of tagging every single task inside the include statement.
|
2012-05-13 17:00:02 +02:00
|
|
|
|
2015-02-13 03:15:44 +01:00
|
|
|
|
|
|
|
Special Tags
|
|
|
|
````````````
|
|
|
|
|
|
|
|
There is a special 'always' tag that will always run a task, unless specifically skipped (--skip-tags always)
|
|
|
|
|
|
|
|
Example::
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
|
|
|
|
- debug: msg="Always runs"
|
|
|
|
tags:
|
|
|
|
- always
|
|
|
|
|
|
|
|
- debug: msg="runs when you use tag1"
|
|
|
|
tags:
|
|
|
|
- tag1
|
|
|
|
|
|
|
|
There are another 3 special keywords for tags, 'tagged', 'untagged' and 'all', which run only tagged, only untagged
|
|
|
|
and all tasks respectively. By default ansible runs as if --tags all had been specified.
|
|
|
|
|
|
|
|
|
2013-10-05 18:31:16 +02:00
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
:doc:`playbooks`
|
|
|
|
An introduction to playbooks
|
|
|
|
:doc:`playbooks_roles`
|
|
|
|
Playbook organization by roles
|
|
|
|
`User Mailing List <http://groups.google.com/group/ansible-devel>`_
|
|
|
|
Have a question? Stop by the google group!
|
|
|
|
`irc.freenode.net <http://irc.freenode.net>`_
|
|
|
|
#ansible IRC chat channel
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-05-13 17:00:02 +02:00
|
|
|
|