Configuration Management Tool

Topics

Getting Started with Ansible

Overview on Ansible

  • Why use Ansible

Ansible Architecture

  • Control node
  • Managed nodes
  • Inventory
  • Modules
  • Tasks
  • Playbooks
  • Lab Environment

Pre-requisites to setup Ansible

  • Control node requirements
  • Managed node requirements
  • Update /etc/hosts on all the hosts
  • Install mandatory prerequisites on Ansible client nodes

Installing Ansible

  • Install using package manager on RHEL 8
  • Install using package manager on CentOS 8
  • Install using pip

Configuring Ansible

  • Create normal user
  • Configure passwordless authentication
  • Verify passwordless SSH authentication
  • Configure privilege escalation using sudo
  • Verify Ansible connectivity

Ansible configuration file (ansible.cfg)

  • [defaults] section
  • [ssh_connection] section
  • [persistent_connection] section
  • [colors] section

Using Ansible ad-hoc commands

  • Overview
  • Sample ad-hoc command examples
  • How Ansible works with modules
  • Control the number of hosts for parallel execution (forks)
  • Transfer file from Ansible Engine to Managed Nodes
  • Download file from managed nodes to controller node
  • Copy files locally on the remote server (managed node)
  • Create or Remove file and directory
  • Remove a file from the managed nodes
  • Execute commands with root privileges
  • Working with packages using yum module
  • Execute ad-hoc commands as a different user

Ansible inventory files

  • Dynamic inventory
  • Static inventory
  • Provide hosts as an input argument
  • Groups in an inventory file
  • Groups of groups
  • Regular expressions with an inventory file
  • Variables in inventory

Working with managed nodes without Python

Working with managed nodes with a password (not passphrase)

Jinja2 templates and syntax

  • Variables
  • Use built-in filters
  • Configure VSFTPD using Jinja2 templates

Ansible facts

  • System default facts
  • User-defined facts

Ansible variables and data types

  • Creating valid variable names
  • Built-in variables
  • Defining variables in inventory
  • Defining variable in project
  • Defining variables in playbook
  • Defining variables using command line
  • Accessing Variables
  • Using register module to store the output of any command
  • Using set_fact module to create a new variable
  • Prompt for user input with vars_prompt
  • Read and access variables from a separate YAML or JSON file
  • Precedence

YAML syntax in Ansible playbooks

  • What is YAML?
  • YAML file formatting
  • Create or Modify .vimrc
  • Constructing your Ansible playbook

Introduction to Ansible playbooks

  • What are Ansible Playbooks
  • Example-1: Your first playbook to install a single package
  • Example-2: Install multiple packages on different managed nodes
  • Example-3: Disable gathering facts module
  • Example-4: Assign custom name to the play and tasks
  • Example-5: Execute playbook as shell scripts
  • Example-6: Print debug message with playbooks
  • Example-7: Increase verbosity level of playbook
  • Example-8: Perform syntax check
  • Example-9: Perform a dry run of playbooks

Use Visual Code Studio to write playbooks (GUI)

  • Download Visual Studio Code Repo
  • Access Visual Code Studio
  • Install Ansible Extension
  • Configure Visual Studio to use Ansible
  • Create a playbook using Visual Studio

Using operators in Ansible

  • Arithmetic Operators
  • Comparison Operators
  • Test operators
  • Logical Operators

Ansible conditional statements

  • Using when statement
  • Using failed_when statement
  • Print message with fail
  • Using changed_when statement