Ansible For Beginners With Examples
Ansible Installation
Ansible Tip & Tricks
Ansible Playbook Code For Linux
Ansible Code To Interact With Linux Filesystem
Ansible Code to Interact with Linux Storage
Ansible Code to Interact with PostgreSQL
Ansible Code For User Management On Linux Systems
Ansible Code reuse: Roles and Collections with Ansible Galaxy
Ansible Playbook Code interact with Web Services API
Ansible Playbook Code for Linux Security
Ansible Playbook Code For RedHat, Debian and SUSE Linux Systems
Ansible Playbook Code For Windows
Ansible Code For Containers
Ansible Code For Kubernetes and OpenShift
Ansible for Network Automation
Ansible For VMware
Ansible Troubleshooting Of The Most Common Errors
Ansible For Beginners With Examples
Ansible Basics, Architecture And Terminology.
- Getting started
- Inventory
- Playbooks
- Variables
- Facts and magic variables
- Vault
- Conditional
- Loop
- Handler
- Roles
Ansible Installation
Install Ansible In The Most Common Operating Systems
- Ansible terminology – ansible vs ansible-core packages
- How to install Ansible in RedHat Enterprise Linux (RHEL) 8
- How to install Ansible in Fedora 34
- How to install Ansible in Fedora 35
- How to install Ansible in CentOS 8
- How to install Ansible in CentOS 8 Stream
- How to install Ansible in CentOS 9 Stream
- How to install Ansible in Ubuntu 20.04 LTS
- How to install Ansible in Ubuntu 21.10
- How to install Ansible in macOS
- How to install Ansible in Debian 11
- How to install Ansible with PIP
- How to install Ansible in Windows 10
- How to install Ansible in Windows 11
- How to install Ansible in OpenSUSE Leap 15
- How to install Ansible in ArchLinux 2021.12.01
- How to install Ansible in Gentoo Linux
- How to install Ansible in AlmaLinux 8
- How to install Ansible in SUSE Linux Enterprise Server (SLES) 15 SP3
- How to install Ansible in Oracle Linux 8
- How to install Ansible in RedHat Enterprise Linux (RHEL) 9 Beta
- How to install Ansible in Ubuntu 22.04 LTS Jammy Jellyfish
- How to install Ansible in Fedora 36 – Ansible install
Ansible Tip & Tricks
Ansible Tip & Tricks
- Print text or variable during execution – Ansible module debug
- Pause execution – Ansible module pause
- How to Pass Variables to Ansible Playbook in the command line? – Ansible extra variables
- Break a string over multiple lines – Ansible Literal and Folded Block Scalar operators
- Ansible terminology – ansible_hostname vs inventory_hostname vs ansible_fqdn
- Set remote environment per task or play – Ansible environment statement
- Execute command on the Ansible host – Ansible localhost
- Three options to Safely Limit Ansible Playbooks Execution to a Single Machine
- Ansible modules – command vs shell
- Write a Variable to a File – Ansible module copy vs template
- How to Run Only One Task in Ansible Playbook? – Ansible tags statement
- Filter A List By Its Attributes – Ansible selectattr filter
- Using Date, Time and Timestamp in Ansible Playbook – Ansible Tip and Tricks
- Using Date, Time and Timestamp without Facts in Ansible Playbook – Ansible date and lookup plugin
- Ansible Playbook Dry Run – check and diff mode
- Ansible Magic Variables – Ansible Tip and Tricks
Ansible Playbook Code For Linux
Ansible Modules To Automate Linux Tasks
- System Administrator examples
- Test host availability – Ansible module ping
- Edit single line text – Ansible module lineinfile
- Edit multi-line text – Ansible module blockinfile
- Reboot remote hosts – Ansible module reboot
- Checkout git repository via HTTPS – Ansible module git
- Checkout git repository via SSH – Ansible module git
- Copy files to remote hosts – Local to Remote – Ansible module copy
- Copy files from remote hosts – Remote to Local – Ansible module fetch
- Start and enable services on boot on remote hosts – Ansible module service_facts, service
- Restart services on remote hosts – Ansible module service
- Stop and disable services on boot on remote hosts – Ansible module service_facts, service
- Apply a file template – Ansible module template – HTML placeholder
- Loop in file template – Ansible module template – Generate hosts file
- Schedule a Cron Job task in Linux – Ansible module cron
- Read a file into a variable on host – Ansible lookup plugin file
- Read an environment variable – Ansible lookup plugin env
- Download a file using an HTTPS proxy via environment variables – Ansible get_url and environment
- Permanently Set Remote System Wide Environment Variables on Linux – /etc/environment – Ansible module lineinfile
- Ansible modules – command vs shell
Ansible Code To Interact With Linux Filesystem
Ansible Module To Interact With Filesystem, File And Directory Creation, Permission And Delete
- Create an empty file – Ansible module file
- Create a text file – Ansible module copy
- Check if a file exists – Ansible module stat
- Create a directory in Linux – Ansible module file
- Check if a directory exists – Ansible module stat
- Rename file or directory – Ansible module copy and file
- Change file permission – Ansible module file
- Add Execute Permission 755 on Linux file – Ansible module file
- Delete file or directory – Ansible module file
- Download a file – Ansible module get_url
- Extract an archive – Ansible module unarchive
- Create a symbolic link (also symlink or soft link) in Linux – Ansible module file
- Create a hard link in Linux – Ansible module file
- Mount a Windows share in Linux SMB/CIFS – Ansible module mount
- Mount an NFS share in Linux – Ansible module mount
- Concatenate multiple files in a specific order – Ansible module template and YAML
- Backup With Rsync – Local to Remote – Ansible module synchronize
- How to Delete Only Files Inside a Directory – Ansible module find
Ansible Code to Interact with Linux Storage
Ansible Module to Interact with Storage Devices, Partitions, Filesystem, LVM, etc.
- Create a New LVM Partition – Ansible module parted
Ansible Code to Interact with PostgreSQL
Ansible Module to Interact with PostgreSQL RDBMS: create database, user, grant permission, backup and restore
- Install PostgreSQL in RedHat-like systems – Ansible modules yum, stat, shell, service
- Install PostgreSQL in Debian-like systems – Ansible modules apt, stat, shell, service
- Create a PostgreSQL Database – Ansible module postgresql_db
- Create a PostgreSQL User or Role – Ansible module postgresql_user
- Allow md5 Connection for a PostgreSQL User / Role – Ansible module postgresql_pg_hba
- Grant Privileges to User/Role on PostgreSQL Database – Ansible module postgresql_privs
- Backup a PostgreSQL Database – Ansible module postgresql_db
- Restore a PostgreSQL Database — Ansible module postgresql_db
- Drop a PostgreSQL Database — Ansible module postgresql_db
- Rename a PostgreSQL Database – Ansible module postgresql_db
- Run a SQL Command/Query on PostgreSQL – Ansible module postgresql_query
Ansible Code For User Management On Linux Systems
Perform User Management Under Linux System: User Creation, Deletion, Change Attributes, Disable And Enable
- Create a user account – Ansible module user
- Remove user account – Ansible module user
- Change user password – Ansible module user
- Disable user account – Ansible module user
- Enable user account – Ansible module user
- User password expiration – Ansible module user
- Create a group in Linux – Ansible module group
- Delete a group in Linux – Ansible module group
- Ansible Playbook Code For RedHat-Like Systems
- Add a User to a Second Group on Linux – Ansible module user
- Change the User Primary Group on Linux – Ansible module user
Ansible Code reuse: Roles and Collections with Ansible Galaxy
How To Download And Use Ansible Roles And Collection From Ansible Galaxy Directory
- Download and Use Ansible Galaxy Role – ansible-galaxy and requirements.yml
- Download and Use Ansible Galaxy Collection – ansible-galaxy and requirements.yml
Ansible Playbook Code interact with Web Services API
Ansible Modules To Automate Interaction With Web Services API
- Submit a GET request to a REST API endpoint – Interact with web services – Ansible module uri
- Token-Based Authentication in REST API – Interact with web services – Ansible module uri – Authentication request using the REST API token
Ansible Playbook Code for Linux Security
Ansible Modules To Automate Linux Security Tasks
- Set sysctl kernel parameters – Ansible module sysctl
- Load and Unload Kernel Modules in Linux – Ansible module modprobe
- Configure Kernel Parameters in RedHat-like Linux systems – Ansible system role
- Set the SELinux Policy States and Modes on Linux – Ansible module selinux
- Enable or Disable SELinux Boolean on Linux – Ansible module seboolean
- Enable or Disable Permissive Domain in SELinux policy on Linux – Ansible module selinux_permissive
- Vulnerability Scanner/Detector Log4Shell Remote Code Execution Log4j (CVE-2021–44228) — Ansible log4j-cve-2021–44228
- How to mitigate Polkit Privilege Escalation – PWNKIT (CVE-2021-4034) on RedHat-like systems – Ansible playbook mitigation
Ansible Playbook Code For RedHat, Debian and SUSE Linux Systems
How To Manage Some RedHat-Like (Fedora, CentOS, Oracle Linux, Amazon Linux) Specific Configuration
- Register a system with Red Hat Subscription-Manager – Ansible module redhat_subscription
- Install a package in RedHat like systems – Ansible module yum
- Rolling Update RedHat like systems – Ansible module yum
- Open firewall ports in RedHat like systems – Ansible module firewalld
- Install Google Chrome in RedHat-like systems – Ansible module rpm_key, yum_repos
- Install Microsoft Edge in RedHat-like systems – Ansible module rpm_key, yum_repository and yum
- NFS Server — Export an NFS Share in RedHat-like systems — Ansible modules yum, file, lineinfile, command, firewalld, service
- Deploy a web server apache httpd on RedHat-like systems – Ansible modules yum, copy, service firewalld
- Deploy a proxy server squid on RedHat-like systems – Ansible modules yum, template, service and firewalld
- Deploy a web server apache httpd virtualhost on RedHat-like systems – Ansible modules yum, file, copy, template, service and firewalld
How To Manage Some Debian-Like (Ubuntu, Mint) Specific Configuration
- Install a package in Debian like systems – Ansible module apt
- Rolling Update Debian-like systems – Ansible module apt
- Open firewall ports in Debian like systems – Ansible module ufw
- Install Google Chrome in Debian-like systems – Ansible module apt_key, apt_repos
- Install Microsoft Edge in Debian-like systems – Ansible module apt_key, apt_repository and apt
- Deploy a web server apache httpd on Debian-like systems – Ansible modules apt, copy, service and ufw
- Deploy a web server apache httpd virtual host on Debian-like systems – Ansible modules apt, file, copy, template, command, ufw and service
How To Manage Some Suse-Like Specific Configuration
- Install a package in Suse-like systems – Ansible module zypper
- Install Google Chrome in Suse-like systems – Ansible module rpm_key, zypper_repo
Ansible Playbook Code For Windows
Ansible Playbook Code For Windows-Like Systems
- Configure a Windows Host for Ansible – ansible winrm
- Test Windows host availability – Ansible module win_ping
- Create an empty file in Windows-like systems – Ansible module win_file
- Check if a file exists on Windows-like systems – Ansible module win_stat
- Install Windows software – Ansible module win_chocolatey
- Copy files to Windows remote hosts – Local to Remote – Ansible module win_copy
- Copy files from Windows remote hosts – Ansible module fetch
- Reboot Windows hosts Ansible module win_reboot
- Install Google Chrome in Windows-like systems – Ansible module win_chocolatey
- Install Docker in Windows-like systems – Ansible module win_chocolatey
- Extract an archive in Windows-like systems – Ansible module win_unzip
- Download a file in Windows-like systems – Ansible module win_get_url
- Create a directory on Windows-like systems – Ansible module win_file
- Check if a directory exists on Windows-like systems – Ansible module win_stat
- Check Registry .NET Framework version on Windows-like systems – Ansible module win_reg_stat
- Add Windows Registry on Windows-like systems – Ansible module win_regedit
- Remove Windows Registry path or key on Windows-like systems – Ansible module win_regedit
- Rolling Update Windows-like systems – Ansible module win_updates
- Create a local group on Windows-like systems – Ansible module win_group
- Remove a local group on Windows-like systems – Ansible module win_group
- Create a local user on Windows-like systems – Ansible module win_user
- Remove a local user on Windows-like systems – Ansible module win_user
- Change local user password on Windows-like systems – Ansible module win_user
- Backup With Robocopy on Windows – Ansible module win_robocopy
- Ansible modules – win_command vs win_shell
Ansible Code For Containers
Ansible Modules To Automate Containers Tasks
- Install Docker in Debian-like systems – Ansible module apt_key, apt_repository, and apt
- Install Docker in RedHat-like systems – Ansible module rpm_key, yum_repository, and yum
- Install Docker in Windows-like systems – Ansible module win_chocolatey
- Install Red Hat CodeReady Containers to run OpenShift 4 in macOS
- Create Kubernetes K8s or OpenShift OCP 4 namespace project – Ansible module k8s
- Install Zoom flatpak in Debian-like systems – Ansible module flatpak
- Install Zoom flatpak in RedHat-like systems – Ansible module flatpak
- Update Zoom flatpak(s) in Linux systems – Ansible module command
- Install Spotify snap in Debian-like systems – Ansible module snap
- Install Spotify snap in RedHat-like systems – Ansible module snap
- Deploy Apache Web Server in a Docker Container for Debian-like systems – Ansible modules docker_image and docker_container
- Deploy Apache Web Server in a Podman Container for RedHat-like systems – Ansible modules podman_image and podman_container
Ansible Code For Kubernetes and OpenShift
Ansible Modules To Automate Kubernetes K8s and OpenShift OCP Tasks
- Install Red Hat CodeReady Containers/OpenShift Local to run OpenShift 4 in macOS
- Create Kubernetes K8s or OpenShift OCP 4 Namespace Project – Ansible module k8s
- Create Kubernetes K8s or OpenShift OCP Pod – nginx – Ansible module k8s
- Create Kubernetes K8s or OpenShift OCP Service – Ansible module k8s
- Create Kubernetes K8s or OpenShift OCP Secret – Ansible module k8s
- Assign CPU Resources to Kubernetes K8s or OpenShift OCP Containers and Pods — Ansible module k8s
- Assign Memory Resources to Kubernetes K8s or OpenShift OCP Containers and Pods – Ansible module k8s
- Configure a Pod to Use a Volume for Storage — Ansible module k8s
- Apply Multiple YAML Files at Once on Kubernetes K8s or OpenShift OCP – Ansible module k8s and lookup plugin fileglob
- Ansible troubleshooting – Kubernetes K8s or OpenShift OCP 401 Unauthorized
Ansible for Network Automation
Ansible Modules To Automate Network stack, test and validate network state
- Backup Config on Dell EMC Networking Operating System DNOS 6 – Ansible Network dellemc.os6
- Backup Config on Dell EMC Networking Operating System DNOS 10 – Ansible Network dellemc.os10
- Backup Config on Mikrotik RouterOS – Ansible Network community.routeros
Ansible For VMware
Ansible Modules To Automate the VMware infrastructure: datacenter, cluster, host system, and virtual machines
- Configure Ansible for VMware – ansible collection community.vmware
- Configure a Python Virtual Environment for Ansible VMware – ansible collection community.vmware
- Ansible troubleshooting – VMware Failed to Import PyVmomi
- Ansible troubleshooting – VMware Unknown error while connecting to vCenter or ESXi
- Create a VMware vSphere Virtual Machine – Ansible module vmware_guest
- Deploy a VMware vSphere Virtual Machine from a Template – Ansible module vmware_guest
- Start a VMware vSphere Virtual Machine – Ansible module vmware_guest_powerstate
- Stop a VMware vSphere Virtual Machine – Ansible module vmware_guest_powerstate
- Take a VMware Virtual Machine Snapshot – Ansible module vmware_guest_snapshot
- Delete a VMware Virtual Machine Snapshot – Ansible module vmware_guest_snapshot
- Add a New Hard Disk to VMware vSphere Virtual Machine – Ansible module vmware_guest_disk
- Expand a Virtual Disk in VMware vSphere Virtual Machine – Ansible module vmware_guest_disk
- Ansible Dynamic Inventory For VMware – Ansible community.vmware.vmware_vm_inventory
- Gather Info about all VMware ESX/ESXi Hosts in a given Cluster – Ansible module vmware_host_config_info
- Get VMware vSphere Virtual Machine UUID – Ansible module vmware_guest_info
Ansible Troubleshooting Of The Most Common Errors
The Most Commons Ansible Errors, How To Troubleshoot And Fix.
- Ansible troubleshooting – connection failed
- Ansible troubleshooting – macOS fork error
- Ansible troubleshooting – indentation error
- Ansible troubleshooting – Syntax Error
- Ansible troubleshooting – undefined variable
- Ansible troubleshooting – invalid argument
- Ansible troubleshooting – privilege escalation error
- Ansible troubleshooting – missing sudo password and incorrect sudo password
- Ansible troubleshooting – missing module parameter
- Ansible troubleshooting – failure downloading
- Ansible troubleshooting – chgrp failed
- Ansible troubleshooting – not a valid attribute for a Play error
- Ansible troubleshooting – fatal template error while templating string
- Ansible troubleshooting – PowerShell incompatible with the sudo become plugin
- Ansible troubleshooting – passwordless account
- Ansible troubleshooting – user module password_expiry_min bug
- Ansible troubleshooting – Windows 10 Error 0x80370102 WSL: Windows Subsystem for Linux
- Ansible troubleshooting – Windows 11 Error 0x80370102 WSL: Windows Subsystem for Linux
- Ansible troubleshooting – urlopen error
- Ansible troubleshooting – destination does not exist
- Ansible troubleshooting – role not found error
- Ansible troubleshooting – Module Failure on Windows-target
- Ansible troubleshooting – Permission denied Errno 13
- Ansible troubleshooting – VARIABLE IS NOT DEFINED! ansible_hostname
- Ansible troubleshooting – Unhandled exception while executing module win_user
- Ansible troubleshooting – This command has to be run under the root user
- Ansible troubleshooting – Kubernetes K8s or OpenShift OCP 401 Unauthorized
- Ansible troubleshooting – VMware Failed to Import PyVmomi
- Ansible troubleshooting – VMware Unknown error while connecting to vCenter or ESXi