Ansible Concepts: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 86: Line 86:


{{External|http://docs.ansible.com/ansible/glossary.html#term-facts}}
{{External|http://docs.ansible.com/ansible/glossary.html#term-facts}}
Facts are simply things that are discovered about remote nodes. While they can be used in playbooks and templates just like variables, facts are things that are inferred, rather than set. Facts are automatically discovered by Ansible when running plays by executing the internal setup module on the remote nodes. You never have to call the setup module explicitly, it just runs, but it can be disabled to save time if it is not needed or you can tell ansible to collect only a subset of the full facts via the gather_subset: option. For the convenience of users who are switching from other configuration management systems, the fact module will also pull in facts from the ohai and facter tools if they are installed. These are fact libraries from Chef and Puppet, respectively. (These may also be disabled via gather_subset:)

Revision as of 15:27, 25 May 2017

Internal

Inventory File

http://docs.ansible.com/ansible/intro_inventory.html#inventory

Ansible works against multiple systems at the same time. It does this by selecting portions of systems listed in Ansible’s inventory file. The default location of the inventory file is /etc/ansible/hosts.

A different location of the inventory file can be specified on the command line with:

-i <path>

Inventory File Structure

host1.example.com

[webservers]
web1.example.com
web2.example.com

[dbservers]
db1.example.com
db2.example.com

Groups

The headings in brackets are group names, which are used in classifying systems and deciding what systems you are controlling at what times and for what purpose. A host can be part of more than one group.

Default Groups

There are two default groups: "all" and "ungrouped". "all" contains every host. ungrouped contains all hosts that don’t have another group aside from all.

Recursive Groups

Recursive groups are declared with the [<group-name>:children].

[A]
host1
host2

[B]
host3
host4

[AandB:children]
A
B

[AandB:vars]
something=something-else

Group Variables

Group variables are declared with [<group-name>:vars]. If they are declared this way, the variables apply to an entire group at once.

[group-A]
host1
host2

[group-A:vars]
something=something-else

Host Variables

Variables that apply to a specific host are declared after the host name:

[group1]
host1 http_port=80 maxRequestsPerChild=808
host2 http_port=303 maxRequestsPerChild=909

Playbook

Fact

http://docs.ansible.com/ansible/glossary.html#term-facts


Facts are simply things that are discovered about remote nodes. While they can be used in playbooks and templates just like variables, facts are things that are inferred, rather than set. Facts are automatically discovered by Ansible when running plays by executing the internal setup module on the remote nodes. You never have to call the setup module explicitly, it just runs, but it can be disabled to save time if it is not needed or you can tell ansible to collect only a subset of the full facts via the gather_subset: option. For the convenience of users who are switching from other configuration management systems, the fact module will also pull in facts from the ohai and facter tools if they are installed. These are fact libraries from Chef and Puppet, respectively. (These may also be disabled via gather_subset:)