Ansible 101 : Core Components
Ansible is a powerful, agentless, open source [link] tool that automate everything from code deployment to network configuration to cloud management.
Collections [link]
Ansible collections are a distribution format for Ansible content that can include playbooks, roles, modules, and plugins.
We can search for collection in the ansible galaxy [link] .
We install new collection or upgrade our installed collections by the command ansible-galaxy collection install my_namespace.my_collection:version
The ansible-galaxy
[link] utility perform various Role and Collection related operations.
Modules [link]
Modules are discrete units of code that can be used from the command line or in a playbook task, modules are hosted in collections. We can execute modules from the command line ansible -m ping localhost
.
The ansible-doc
[link] utility displays information on modules installed in Ansible libraries. example ansible-doc ping
.
Facts [link]
Ansible facts are data related to your remote systems, including operating systems, IP addresses, attached filesystems, and more. You can access this data in the ansible_facts
variable within your tasks.
To show the facts about the local server you can run the command ansible -m setup localhost
Inventories [link]
Ansible works against multiple hosts in your infrastructure at the same time, using a list or group of lists known as inventory, it can be written in ini, yaml, toml, json formats.
The location of the inventory file is by default in/etc/ansible/hosts
and we can define our inventories in the current folder or by Using multiple inventory sources, or pull inventory from dynamic or cloud sources as described in Working with dynamic inventory.
The ansible-inventory
[link] utility display or dump the configured inventory as Ansible sees it.
Configuration Files [link]
Ansible supports several sources for configuring its behavior which will be searched for in the following order:
ANSIBLE_CONFIG
(environment variable if set)ansible.cfg
(in the current directory)~/.ansible.cfg
(in the home directory)/etc/ansible/ansible.cfg
The ansible-config
[link] utility allows users to see all the configuration settings available, their defaults.
Playbooks [link]
Playbooks are expressed in YAML format, they are composed of one or multiple ‘plays’, and plays are composed of one or more tasks.
The ansible-playbook
[link] utility run ansible playbooks and executing the defined tasks on the targeted hosts.
Variables [link]
Ansible uses variables to manage differences between systems. You can define these variables in your playbooks, in your inventory, in re-usable files or roles, or at the command line. You can also create variables during a playbook run by registering the return value or values of a task as a new variable.
Roles [link]
Ansible role let us reuse already created vars, files, tasks, handlers, and other Ansible artifacts that has a defined directory structure with eight main standard directories.
We can search for roles in the ansible galaxy [link], and we can install it by the command ansible-galaxy install my_namespace.role_name,version