summaryrefslogtreecommitdiff
path: root/docsite/rst/playbooks_tags.rst
blob: a03b975a4eb04a50b0dd4f4f431477bb7785df7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
Tags
====

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.

Both plays and tasks support a "tags:" attribute for this reason.

Example::

    tasks:

        - yum: name={{ item }} state=installed
          with_items:
             - httpd
             - memcached
          tags:
             - packages

        - template: src=templates/src.j2 dest=/etc/foo.conf
          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"

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"

You may also apply tags to roles::

    roles:
      - { role: webserver, port: 5000, tags: [ 'web', 'foo' ] }

And you may also tag basic include statements::

    - include: foo.yml tags=web,foo

Both of these have the function of tagging every single task inside the include statement.


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.


.. 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