<spanid="inventoryformat"></span><h2>Basic Inventory File Format<aclass="headerlink"href="#basic-inventory-file-format" title="Permalink to this headline">¶</a></h2>
<p>The format for /etc/ansible/hosts looks like this:</p>
<divclass="section"id="hosts-and-groups">
<spanid="inventoryformat"></span><h2>Hosts and Groups<aclass="headerlink"href="#hosts-and-groups" title="Permalink to this headline">¶</a></h2>
<p>The format for /etc/ansible/hosts is an INI format and looks like this:</p>
<h2>Selecting Targets<aclass="headerlink"href="#selecting-targets"title="Permalink to this headline">¶</a></h2>
@ -211,7 +214,7 @@ after the hostname with a colon. This requires Ansible 0.3 (integration branch)
<p>Such as:</p>
<divclass="highlight-python"><pre>ansible webservers -m service -a "name=httpd state=restarted"</pre>
</div>
<p>Within <aclass="reference internal"href="playbooks.html"><em>Playbooks</em></a>, these patterns can also be used, for even greater purposes.</p>
<p>Within <aclass="reference internal"href="playbooks.html"><em>Playbooks</em></a>, these patterns can be used for even greater purposes.</p>
<p>Anyway, to use Ansible, you’ll first need to know how to tell Ansible which hosts in your inventory file to talk to.
This is done by designating particular host names or groups of hosts.</p>
<p>The following patterns target all hosts in the inventory file:</p>
@ -239,20 +242,60 @@ wildcards:</p>
</div>
<divclass="admonition note">
<pclass="first admonition-title">Note</p>
<pclass="last">It is not possible to target a host not in the inventory file. This is a safety feature.</p>
<pclass="last">It is not possible to target a host not in the inventory file, unless using playbooks with –override-hosts. More on that later. This is a safety feature.</p>
</div>
<p>Easy enough. See <aclass="reference internal"href="examples.html"><em>Command Line Examples</em></a> and then <aclass="reference internal"href="playbooks.html"><em>Playbooks</em></a> for how to do things to selected hosts.</p>
</div>
<divclass="section"id="host-variables">
<h2>Host Variables<aclass="headerlink"href="#host-variables"title="Permalink to this headline">¶</a></h2>
<p>Using the 0.4 branch of Ansible, it is easy to assign variables to hosts that will be used
later in playbooks:</p>
<divclass="highlight-python"><pre>[atlanta]
host1 http_port=80 maxRequestsPerChild=808
host2 http_port=303 maxRequestsPerChild=909</pre>
</div>
</div>
<divclass="section"id="group-variables">
<h2>Group Variables<aclass="headerlink"href="#group-variables"title="Permalink to this headline">¶</a></h2>
<p>Using the 0.4 branch of Ansible, variables can also be applied to an entire group at once:</p>
<divclass="highlight-python"><pre>[atlanta]
host1
host2
[atlanta:vars]
ntp_server=ntp.atlanta.example.com
proxy=proxy.atlanta.example.com</pre>
</div>
</div>
<divclass="section"id="groups-of-groups">
<h2>Groups of Groups<aclass="headerlink"href="#groups-of-groups"title="Permalink to this headline">¶</a></h2>
<p>Using the 0.4 branch of Ansible, it is possible to make groups of groups:</p>
<divclass="highlight-python"><pre>[atlanta]
host1
host2
[raleigh]
host2
host3
[southeast:children]
alpha
beta
[southeast:vars]
some_server=foo.southeast.example.com
[usa:children]
southeast
northeast
southwest
southeast</pre>
</div>
</div>
<divclass="section"id="yaml-inventory-format">
<h2>YAML Inventory Format<aclass="headerlink"href="#yaml-inventory-format"title="Permalink to this headline">¶</a></h2>
<p>(temporary message: This features requires the master branch of Ansible, 0.3, and is currently
disabled on 0.4 (devel), pending some upgrades. It will be back in 0.4 soon, along with the ability
to assign variables more simply, even without the YAML inventory format, which will result in this
section being rewritten and clarified)</p>
<p>Once you read about playbooks you’ll quickly see how useful it will be to assign particular variables
to particular hosts and groups of hosts. While the default INI-style host format doesn’t allow this,
switching to the YAML inventory format can add some compelling capabilities. Just replace your INI
style file with a YAML one.:</p>
<p>For people using 0.3, or those that prefer to use it, the inventory file can also be expressed in
YAML:</p>
<divclass="highlight-python"><pre>---
# some ungrouped hosts, either use the short string form or the "host: " prefix
@ -289,10 +332,6 @@ style file with a YAML one.:</p>
- asdf: 1234</pre>
</div>
<p>Tip: Be sure to start your YAML file with the YAML record designator <ttclass="docutils literal"><spanclass="pre">---</span></tt>.</p>
<p>NOTE: variables specified in playbooks will override variables specified
in the host file. Further, if a host is in multiple groups, currently, the
variables set by the last loaded group will win over variables set in other
groups. This behavior may be refined in future releases.</p>
@ -9,10 +9,10 @@ Ansible's inventory file, which defaults to /etc/ansible/hosts.
.._inventoryformat:
Basic Inventory File Format
+++++++++++++++++++++++++++
Hosts and Groups
++++++++++++++++
The format for /etc/ansible/hosts looks like this::
The format for /etc/ansible/hosts is an INI format and looks like this::
mail.example.com
@ -29,7 +29,7 @@ The things in brackets are group names. You don't have to have them,
but they are useful.
If you have hosts that run on non-standard SSH ports you can put the port number
after the hostname with a colon. This requires Ansible 0.3 (integration branch)::
after the hostname with a colon.
four.example.com:5309
@ -44,7 +44,7 @@ Such as::
ansible webservers -m service -a "name=httpd state=restarted"
Within :doc:`playbooks`, these patterns can also be used, for even greater purposes.
Within :doc:`playbooks`, these patterns can be used for even greater purposes.
Anyway, to use Ansible, you'll first need to know how to tell Ansible which hosts in your inventory file to talk to.
This is done by designating particular host names or groups of hosts.
@ -78,22 +78,65 @@ It's also ok to mix wildcard patterns and groups at the same time::
one*.com:dbservers
..note::
It is not possible to target a host not in the inventory file. This is a safety feature.
It is not possible to target a host not in the inventory file, unless using playbooks with --override-hosts. More on that later. This is a safety feature.
Easy enough. See :doc:`examples` and then :doc:`playbooks` for how to do things to selected hosts.
Host Variables
++++++++++++++
Using the 0.4 branch of Ansible, it is easy to assign variables to hosts that will be used
later in playbooks::
[atlanta]
host1 http_port=80 maxRequestsPerChild=808
host2 http_port=303 maxRequestsPerChild=909
Group Variables
+++++++++++++++
Using the 0.4 branch of Ansible, variables can also be applied to an entire group at once::
[atlanta]
host1
host2
[atlanta:vars]
ntp_server=ntp.atlanta.example.com
proxy=proxy.atlanta.example.com
Groups of Groups
++++++++++++++++
Using the 0.4 branch of Ansible, it is possible to make groups of groups::
[atlanta]
host1
host2
[raleigh]
host2
host3
[southeast:children]
alpha
beta
[southeast:vars]
some_server=foo.southeast.example.com
[usa:children]
southeast
northeast
southwest
southeast
YAML Inventory Format
+++++++++++++++++++++
(temporary message: This features requires the master branch of Ansible, 0.3, and is currently
disabled on 0.4 (devel), pending some upgrades. It will be back in 0.4 soon, along with the ability
to assign variables more simply, even without the YAML inventory format, which will result in this
section being rewritten and clarified)
Once you read about playbooks you'll quickly see how useful it will be to assign particular variables
to particular hosts and groups of hosts. While the default INI-style host format doesn't allow this,
switching to the YAML inventory format can add some compelling capabilities. Just replace your INI
style file with a YAML one.::
For people using 0.3, or those that prefer to use it, the inventory file can also be expressed in
YAML::
---
@ -132,11 +175,6 @@ style file with a YAML one.::
Tip: Be sure to start your YAML file with the YAML record designator ``---``.
NOTE: variables specified in playbooks will override variables specified
in the host file. Further, if a host is in multiple groups, currently, the
variables set by the last loaded group will win over variables set in other
groups. This behavior may be refined in future releases.