Learn to install Ansible, create a static host inventory file, and configure Ansible with a custom configuration file.
In this lesson, you’ll learn how to install the Ansible control machine, set up a static host inventory file, and configure Ansible using a custom configuration file. The control node hosts the core Ansible software and stores all your playbooks. Remember that Ansible must be installed on a Linux machine. Although you can run Ansible from a Linux VM on Windows, it cannot be installed directly on Windows. However, Windows machines can be managed as target nodes in your Ansible environment.
Ansible can be installed using various methods. Use Linux package managers (yum, dnf, apt-get) for a quick setup, or use pip for the latest version and greater flexibility.
If you already have Python installed, pip allows you to install or upgrade Ansible. On enterprise Linux, you may need to install the extra EPEL-release packages first:
When Ansible is installed via a package manager, a default inventory file is created at /etc/ansible/hosts. If no other inventory file is specified, Ansible will use this file by default. However, you can create your own static inventory file anywhere, such as alongside your playbooks.
/etc/ansible/hosts# This is the default Ansible 'hosts' file.## Location: /etc/ansible/hosts## - Comments start with the '#' character# - Blank lines are ignored# - Groups of hosts are defined using [group_name] headers# - Hostnames or IP addresses can be specified## Example 1: Ungrouped hosts (specify before any group headers).## green.example.com## blue.example.com## 192.168.100.1## 192.168.100.10## [webservers]## alpha.example.org## beta.example.org## 192.168.1.100## 192.168.1.110
Ansible uses a default configuration file located at /etc/ansible/ansible.cfg when installed via a package manager. This file defines the default parameters and behaviors. You can modify these defaults directly or create a custom configuration file within your playbook directory with only the settings you wish to override.
When installing Ansible via pip, the default inventory and configuration files are not created automatically. You will need to create these files manually.
That’s it for this lesson. Feel free to explore installing Ansible in the hands-on labs and experiment with different configuration settings. Good luck, and see you in the next lesson!