Ansible For Linux by Examples
Ansible For Linux by Examples
200+ Automation Examples For Linux System Administrator and DevOps
About the Book
Ansible is an Open Source IT automation tool. This book contains all of the obvious and not-so-obvious best practices of Ansible automation. Every successful IT department needs automation nowadays for bare metal servers, virtual machines, could, containers, and edge computing. Automate your IT journey with Ansible automation technology.
You are going to start with the installation of Ansible in Enterprise and Community Linux using the most command package manager and archives.
Each of the 200+ lessons summarizes a module: from the most important parameter to some Ansible code and real-life usage. Each code is battle proved in the real life. Simplifying mundane activities like creating a text file, extracting and archiving, fetching a repository using HTTPS or SSH connections could be automated with some lines of code and these are only some of the long lists included in the course.
There are some Ansible codes usable in all the Linux systems, some specific for RedHat-like, Debian-like, and Suse-like.
The 20+ Ansible troubleshooting lesson teaches you how to read the error message, how to reproduce, and the process of troubleshooting and resolution.
Are you ready to automate your day with Ansible?
Examples in the book are tested with the latest version of Ansible 2.9+ and Ansible Core 2.11+.
Table of Contents
-
Introduction
- Modern IT Infrastructure
- Whois Luca Berton
-
Ansible For Beginners With Examples
- What is Ansible
- Getting Started
- Inventory
- Playbook
- Variables
- Facts and Magic Variables
- Vault
- Conditional
- Loop
- Handler
- Role
- Ansible Best Practices
-
Install Ansible
- Ansible terminology - ansible vs ansible-core packages
- How to install Ansible in RedHat Enterprise Linux (RHEL) 8 with Ansible Engine
- How to install Ansible in Ubuntu 22.04 LTS
- How to install Ansible in Fedora 36 - Ansible install
- How to install Ansible in CentOS 9 Stream
- How to install Ansible in SUSE Linux Enterprise Server (SLES) 15 SP3
- How to install Ansible with PIP
- How to install Ansible in RedHat Enterprise Linux (RHEL) 9 - Ansible install
- How to install Ansible in Amazon Linux 2 (AWS EC2)
- How to install Ansible in Debian 11
-
Ansible For Linux
- Test host availability - Ansible module ping
- How to print a text or a variable during the execution with Ansible
- Edit single-line text - Ansible module lineinfile
- Edit multi-line text - Ansible module blockinfile
- Read a file into a variable on host - Ansible lookup plugin file
- 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 Linux 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 from remote hosts - Ansible module slurp
- Read an environment variable - Ansible lookup plugin env”
- Permanently Set Remote System Wide Environment Variables on Linux - /etc/environment - Ansible module lineinfile
- Write a Variable to a File - Ansible module copy vs template
-
Ansible Tip & Tricks
- Pause execution - Ansible module pause
- How to Pass Variables to Ansible Playbook in 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
- 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 Magic Variables - Ansible Tip and Tricks
- Ansible Playbook Dry Run - check and diff mode
- 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
-
Ansible Code reuse: Roles and Collections with Ansible Galaxy
- Download and Use Ansible Galaxy Role - ansible-galaxy and requirements.yml
- Download and Use Ansible Galaxy Collection - ansible-galaxy and requirements.yml
-
Ansible for Linux Filesystem
- Create an empty file - Ansible module file
- Create a text file - Ansible module copy
- Check if a file exists - Ansible module stat
- How to create a directory with Ansible?
- How to check if a directory exists in Ansible?
- How to rename a file or directory using an Ansible task on a remote system?
- Change file permission - Ansible module file
- Add Execute Permission 755 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
- Find All Files with Extension - Ansible module find
- Search for a String in a File -Ansible module lineinfile
- Links
-
Ansible For Linux User Management
- Ansible create a user account
- Ansible remove user account
- Ansible change user password
- Ansible disable user account
- Ansible enable user account
- Ansible user password expiration
- Ansible creates a group
- Ansible deletes a group account
- Ansible changes the User Primary Group on Linux
- Ansible adds a user to a secondary group(s)
-
Ansible Playbook Code interact 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-service - Ansible module uri - Authentication request using the REST API token
-
Ansible For Linux Security
- Set sysctl kernel parameters - Ansible module sysctl
- Load and Unload Kernel Modules in Linux - Ansible module modprobe
- Set the SELinux Policy States and Modes on Linux - Ansible module selinux
- Configure Kernel Parameters in RedHat-like Linux systems - Ansible system role
- 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
-
Ansible Playbook Code for RedHat-like systems
- 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: RHEL, CentOS, CentOS Stream, Fedora - 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
-
Ansible Playbook Code for Debian-like systems
- 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
-
Ansible Playbook Code for Suse-like systems
- Install a package in Suse-like systems - Ansible module zypper
- Install Google Chrome in Suse-like systems - Ansible module rpm_key, zypper_repo
-
Ansible For Containers
- Ansible install Docker in Debian-like systems
- Ansible install Docker in RedHat-like systems
- 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 For Kubernetes
- Install Red Hat CodeReady Containers to run OpenShift 4 in macOS
- Create Kubernetes K8s or OpenShift OCP namespace project - Ansible module k8s
- Create Kubernetes K8s or OpenShift OCP Pod - nginx - Ansible module k8s
- Create Kubernetes K8s or OpenShift OCP Secret - Ansible module k8s
- Create Kubernetes K8s or OpenShift OCP service - 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 The Most Common Errors
- 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 - urlopen error
- Ansible troubleshooting - destination does not exist
- Ansible troubleshooting - “role not found” error
- Ansible troubleshooting - permission denied Errno 13
- Ansible troubleshooting - VARIABLE IS NOT DEFINED! ansible_hostname
- Ansible troubleshooting - This command has to be run under the root user
- Ansible troubleshooting - Kubernetes K8s or OpenShift OCP 401 Unauthorized
- Thank you
The Leanpub 60-day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
80% Royalties. Earn $16 on a $20 book.
We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earned$12,307,240writing, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Top Books
OpenIntro Statistics
David Diez, Christopher Barr, Mine Cetinkaya-Rundel, and OpenIntroA complete foundation for Statistics, also serving as a foundation for Data Science.
Leanpub revenue supports OpenIntro (US-based nonprofit) so we can provide free desk copies to teachers interested in using OpenIntro Statistics in the classroom and expand the project to support free textbooks in other subjects.
More resources: openintro.org.
Personal Finance
Jason AndersonThis textbook provides an in-depth analysis on personal finance that is both practical and straightforward in its approach. It has been written in such a way that the readers can gain knowledge without getting overwhelmed by the technical terms. Suitable for both beginners and advanced learners.
Getting to Know IntelliJ IDEA
Trisha Gee and Helen ScottIf we treat our IDE as a text editor, we are doing ourselves a disservice. Using a combination of tutorials and a questions-and-answers approach, Getting to Know IntelliJ IDEA will help you find ways to use IntelliJ IDEA that enable you to work comfortably and productively as a professional developer.
C++20 - The Complete Guide
Nicolai M. JosuttisAll new language and library features of C++20 (for those who know previous C++ versions).
The book presents all new language and library features of C++20. Learn how this impacts day-to-day programming, to benefit in practice, to combine new features, and to avoid all new traps.
Buy early, pay less, free updates.
Other books:
Mastering STM32 - Second Edition
Carmine NovielloWith more than 1200 microcontrollers, STM32 is probably the most complete ARM Cortex-M platform on the market. This book aims to be the most complete guide around introducing the reader to this exciting MCU portfolio from ST Microelectronics and its official CubeHAL and STM32CubeIDE development environment.
R Programming for Data Science
Roger D. PengThis book brings the fundamentals of R programming to you, using the same material developed as part of the industry-leading Johns Hopkins Data Science Specialization. The skills taught in this book will lay the foundation for you to begin your journey learning data science. Printed copies of this book are available through Lulu.
Machine Learning Q and AI
Sebastian Raschka, PhDHave you recently completed a machine learning or deep learning course and wondered what to learn next? With 30 questions and answers on key concepts in machine learning and AI, this book provides bite-sized bits of knowledge for your journey to becoming a machine learning expert.
Stats One
William FooteThe Rails 7 Way
Obie Fernandez, Lucas Dohmen, and Tom Henrik AadlandThe Rails™ 7 Way is the comprehensive, authoritative reference guide for professionals delivering production-quality code using modern Ruby on Rails. It illuminates the entire Rails 7 API, its most powerful idioms, design approaches, and libraries. Building on the previous editions, this edition has been heavily refactored and updated.
Gradual Modularization for Ruby and Rails
Stephan HagemannGet yourself a new tool to manage your Rails application and your growing engineering organization! Prevent the ball-of-mud (and fix it!). Go for microservices or SOA if it makes sense not just because you don't have any other tool. Do all this through a low-overhead tool: packages. Enable better conversations to make practical changes today.
Top Bundles
- #1
Software Architecture
2 Books
"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before... - #2
CCIE Service Provider Ultimate Study Bundle
2 Books
Piotr Jablonski, Lukasz Bromirski, and Nick Russo have joined forces to deliver the only CCIE Service Provider training resource you'll ever need. This bundle contains a detailed and challenging collection of workbook labs, plus an extensively detailed technical reference guide. All of us have earned the CCIE Service Provider certification... - #3
1500 QUIZ COMMENTATI (3 libri)
3 Books
Tre libri dei QUIZ MMG Commentati al prezzo di DUE! I QUIZ dei concorsi ufficiali di Medicina Generale relativi agli anni: 2000-2001-2003-2012-2013-2014-2015-2016-2017-2018-2019-2020-2021 +100 inediti Raccolti in unico bundle per aiutarvi nello studio e nella preparazione al concorso. All'interno di ogni libro i quiz sono stati suddivisi per... - #4
Pattern-Oriented Memory Forensics and Malware Detection
2 Books
This training bundle for security engineers and researchers, malware and memory forensics analysts includes two accelerated training courses for Windows memory dump analysis using WinDbg. It is also useful for technical support and escalation engineers who analyze memory dumps from complex software environments and need to check for possible... - #5
Practical FP in Scala + Functional event-driven architecture
2 Books
Practical FP in Scala (A hands-on approach) & Functional event-driven architecture, aka FEDA, (Powered by Scala 3), together as a bundle! The content of PFP in Scala is a requirement to understand FEDA so why not take advantage of this bundle!? - #6
Modern C++ Collection
3 Books
Get All about Modern C++C++ Standard Library, including C++20Concurrency with Modern C++, including C++20C++20Each book has about 200 complete code examples. Updates are included. When I update one of the books, you immediately get the updated bundle. You can expect significant updates to each new C++ standard (C++23, C++26, .. ) and also... - #7
Linux Administration Complet
4 Books
Ce lot comprend les quatre volumes du Guide Linux Administration :Linux Administration, Volume 1, Administration fondamentale : Guide pratique de préparation aux examens de certification LPIC 1, Linux Essentials, RHCSA et LFCS. Administration fondamentale. Introduction à Linux. Le Shell. Traitement du texte. Arborescence de fichiers. Sécurité... - #9
Development and Deployment of Multiplayer Online Games, Part ARCH. Architecture (Vol. I-III)
3 Books
What's the Big Idea? The idea behind this book is to summarize the body of knowledge that already exists on multiplayer games but is not available in one single place.And quite a fewof the issues discussed within this series (planned as three nine volumes ~300 pages each), while known in the industry, have not been published at all (except for... - #10
Growing Agile: The Complete Coach's Guide
7 Books
Growing Agile: Coach's Guide Series This bundle provides a collection of training and workshop plans for a variety of agile topics. The series is aimed at agile coaches, trainers and ScrumMasters who often find themselves needing to help teams understand agile concepts. Each book in the series provides the plans, slides, handouts and activity...