1-Day1-1-Installation
Lab Exercise: Install Ansible and Explore Its Directory Structure
This lab exercise will guide you through installing Ansible on a control node, understanding its default directory structure, and verifying its setup. The lab aims to provide hands-on experience with the basics of Ansible.
Step 1: Set Up a Control Node and Managed Nodes
Prepare a Virtual Machine (VM), Container, or Physical System as Control Node:
Use an Ubuntu/Debian-based or CentOS/RHEL-based system.
Ensure the system has at least 1 GB of RAM and 10 GB of storage.
Prepare 2-3 Managed Nodes:
Use additional VMs or containers (e.g., Docker containers).
Ensure SSH is enabled on managed nodes for remote communication.
Step 2: Install Ansible on the Control Node
On Ubuntu/Debian Systems:
Run the following commands:
sudo apt update
sudo apt install ansible -yOn CentOS/RHEL Systems:
Enable the EPEL repository and install Ansible:
Step 3: Validate the Installation
Verify Ansible Installation:
Check the output for installed version, Python version, and configuration file path.
Check Installed Modules (Optional):
This lists the modules available for use with Ansible.
Step 4: Explore Ansible’s Default Directory Structure
Locate the Default Configuration File: The default configuration file is located at
/etc/ansible/ansible.cfg.Inspect the Default Configuration File: View the contents of the
ansible.cfgfile:Note the default settings for:
Inventory file path
Remote user
SSH configuration
Module options
Examine the Default Inventory File: The default inventory file is located at
/etc/ansible/hosts.This file is used to define the managed nodes (hosts).
Explore the
/usr/share/ansibleDirectory: This directory contains Ansible-provided roles, plugins, and modules.Investigate subdirectories for collections and roles.
Check Logs Directory (Optional): By default, logs might not be enabled. Modify the configuration to log actions:
Edit the
ansible.cfgfile:Uncomment and set
log_pathto a file (e.g.,/var/log/ansible.log):Verify logging after running any command.
Step 5: Test Ansible Setup with Ad-Hoc Commands
Ping All Managed Nodes: Add managed nodes to the default inventory (
/etc/ansible/hosts):Run the
pingmodule to verify connectivity:
Run a Simple Command on Managed Nodes: Example: Check disk space on all managed nodes:
Interactive Examples for Exploration
Example 1: Modify ansible.cfg and Test its Impact
Change the
timeoutvalue inansible.cfgto 5 seconds.Run a long-running command like:
Observe the impact of the timeout setting by chaning the timeout value and increasing the sleep time.
Expected Outcomes
Ansible is installed and functional.
Directory structure and configuration files are understood.
Basic commands are successfully executed on managed nodes.
This interactive lab ensures participants not only set up Ansible but also gain confidence exploring its environment.
Last updated