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.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
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.
Installing Ansible
You have two main options for installing Ansible: using your system’s package manager or the Python package manager pip.Using Package Managers
For systems based on different distributions, execute the following commands: For Red Hat or CentOS:Using pip
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:Creating an Inventory File
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.
Default Inventory File Example
Custom Inventory File Example
-i option.
Creating and Overriding the Configuration File
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.
Default Configuration File Example
Custom Configuration File Example
When installing Ansible via pip, the default inventory and configuration files are not created automatically. You will need to create these files manually.
Quick Reference
| Task | Command Example |
|---|---|
| Install Ansible on CentOS/Red Hat | sudo yum install ansible |
| Install Ansible on Fedora | sudo dnf install ansible |
| Install Ansible on Ubuntu/Debian | sudo apt-get install ansible |
| Install Ansible with pip | sudo pip install ansible |
| Upgrade Ansible with pip | sudo pip install --upgrade ansible |
| Install Specific Version (2.4) | sudo pip install ansible==2.4 |