mirror of https://github.com/ansible/ansible.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
3.2 KiB
ReStructuredText
93 lines
3.2 KiB
ReStructuredText
11 years ago
|
Patterns
|
||
|
++++++++
|
||
13 years ago
|
|
||
11 years ago
|
.. contents::
|
||
|
:depth: 2
|
||
|
|
||
11 years ago
|
Patterns in Ansible are how we decide which hosts to manage. This can mean what hosts to communicate with, but in terms
|
||
|
of :doc:`playbooks` it actually means what hosts to apply a particular configuration or IT process to.
|
||
13 years ago
|
|
||
11 years ago
|
We'll go over how to use the command line in :doc:`intro_adhoc` section, however, basically it looks like this::
|
||
13 years ago
|
|
||
|
ansible <pattern_goes_here> -m <module_name> -a <arguments>
|
||
12 years ago
|
|
||
13 years ago
|
Such as::
|
||
|
|
||
|
ansible webservers -m service -a "name=httpd state=restarted"
|
||
|
|
||
11 years ago
|
A pattern usually refers to a set of groups (which are sets of hosts) -- in the above case, machines in the "webservers" group.
|
||
|
|
||
11 years ago
|
Anyway, to use Ansible, you'll first need to know how to tell Ansible which hosts in your inventory to talk to.
|
||
13 years ago
|
This is done by designating particular host names or groups of hosts.
|
||
|
|
||
11 years ago
|
The following patterns are equivalent and target all hosts in the inventory::
|
||
13 years ago
|
|
||
|
all
|
||
12 years ago
|
*
|
||
13 years ago
|
|
||
11 years ago
|
It is also possible to address a specific host or set of hosts by name::
|
||
13 years ago
|
|
||
|
one.example.com
|
||
|
one.example.com:two.example.com
|
||
13 years ago
|
192.168.1.50
|
||
|
192.168.1.*
|
||
12 years ago
|
|
||
11 years ago
|
The following patterns address one or more groups. Groups separated by a colon indicate an "OR" configuration.
|
||
11 years ago
|
This means the host may be in either one group or the other::
|
||
13 years ago
|
|
||
|
webservers
|
||
|
webservers:dbservers
|
||
|
|
||
11 years ago
|
You can exclude groups as well, for instance, all machines must be in the group webservers but not in the group phoenix::
|
||
13 years ago
|
|
||
|
webservers:!phoenix
|
||
|
|
||
11 years ago
|
You can also specify the intersection of two groups. This would mean the hosts must be in the group webservers and
|
||
|
the host must also be in the group staging::
|
||
12 years ago
|
|
||
|
webservers:&staging
|
||
|
|
||
|
You can do combinations::
|
||
|
|
||
11 years ago
|
webservers:dbservers:&staging:!phoenix
|
||
12 years ago
|
|
||
11 years ago
|
The above configuration means "all machines in the groups 'webservers' and 'dbservers' are to be managed if they are in
|
||
|
the group 'staging' also, but the machines are not to be managed if they are in the group 'phoenix' ... whew!
|
||
|
|
||
|
You can also use variables if you want to pass some group specifiers via the "-e" argument to ansible-playbook, but this
|
||
|
is uncommonly used::
|
||
12 years ago
|
|
||
12 years ago
|
webservers:!{{excluded}}:&{{required}}
|
||
12 years ago
|
|
||
11 years ago
|
You also don't have to manage by strictly defined groups. Individual host names, IPs and groups, can also be referenced using
|
||
13 years ago
|
wildcards::
|
||
13 years ago
|
|
||
13 years ago
|
*.example.com
|
||
|
*.com
|
||
13 years ago
|
|
||
13 years ago
|
It's also ok to mix wildcard patterns and groups at the same time::
|
||
13 years ago
|
|
||
13 years ago
|
one*.com:dbservers
|
||
13 years ago
|
|
||
11 years ago
|
Most people don't specify patterns as regular expressions, but you can. Just start the pattern with a '~'::
|
||
12 years ago
|
|
||
|
~(web|db).*\.example\.com
|
||
12 years ago
|
|
||
11 years ago
|
While we're jumping a bit ahead, additionally, you can add an exclusion criteria just by supplying the "--limit" flag to /usr/bin/ansible or /usr/bin/ansible-playbook::
|
||
12 years ago
|
|
||
11 years ago
|
ansible-playbook site.yml --limit datacenter2
|
||
13 years ago
|
|
||
11 years ago
|
Easy enough. See :doc:`intro_adhoc` and then :doc:`playbooks` for how to apply this knowledge.
|
||
13 years ago
|
|
||
13 years ago
|
.. seealso::
|
||
|
|
||
11 years ago
|
:doc:`intro_adhoc`
|
||
13 years ago
|
Examples of basic commands
|
||
|
:doc:`playbooks`
|
||
|
Learning ansible's configuration management language
|
||
13 years ago
|
`Mailing List <http://groups.google.com/group/ansible-project>`_
|
||
|
Questions? Help? Ideas? Stop by the list on Google Groups
|
||
|
`irc.freenode.net <http://irc.freenode.net>`_
|
||
|
#ansible IRC chat channel
|
||
13 years ago
|
|