The Ansible Workshop
Minimum price
Suggested price

The Ansible Workshop

Hands-On Learning For Rapid Mastery

About the Book

In "The Ansible Workshop," you will deep dive into the world of Ansible, the amazing automation tool that converts complex IT tasks into a set of easy, simple-to-repeat steps. This guide is your roadmap to mastering Ansible, whether you are a novice just starting to use Ansible or an intermediate user who has already used Ansible and is looking for additional information and tricks to enhance your skills.

To start with, we will unwrap the essence of Ansible. You will explore what Ansible is, its declarative vs imperative automation approach, and dive into its architecture that exposes Ansible's inner workings. This is basically building the foundation for everything shown henceforth.

At its core, Ansible is configuration management and application deployment. You will learn how to use ad-hoc commands and playbooks to automate server configurations and application deployment. We will cover creating simple playbooks and developing advanced ones, giving you the tools required to manage multiple scenarios and orchestrate complex tasks.

In today's dynamic containerized environment, the integration of Ansible with Docker and Kubernetes is crucial. You will learn how to build, tag, and push Docker images, as well as manage Docker containers, networks, and volumes, and even orchestrate Docker using Ansible. For the fans of Kubernetes out there, we dive into deploying and managing Kubernetes clusters using Ansible and Kubespray, then we explore how to deploy your workloads to Kubernetes using Ansible.

This guide provides comprehensive coverage of each and every minute part of Ansible:

  • Inventory: know and make use of advanced inventories.
  • Facts: How to locate and utilize Ansible facts.
  • Vaults: The art of managing sensitive data in a better way.
  • Blocks: Managing errors gracefully, using Ansible blocks.
  • Modules and plugins: Expanding the horizon of Ansible.
  • Filters: Using Ansible filters for data transformation.
  • Roles: Running many playbooks through Ansible roles.
  • Collections: Discovering and using collections of Ansible.
  • Ansible Galaxy: Everything about Ansible Galaxy and how it can be used, explained.
  • Developing your modules: Briefing on how one can develop their Ansible module.
  • Develop custom filters: Learn how to develop your own Ansible filters.
  • Integrate other tools with Ansible (e.g. Kubernetes, Docker, ChatGPT, or whatever).
  • And much more!

Every concept is supported by examples from real-world use and best practices. You will find out how to use IDEs for better writing playbooks, debugging, and optimizing Ansible performance. We also cover how to create custom modules and filters – including a special module leveraging generative AI (ChatGPT).

  • Share this book

  • Categories

    • Computers and Programming
    • Cloud Computing
    • DevOps
    • Ansible
    • Software Engineering
  • Feedback

    Email the Author(s)

About the Author

Aymen El Amri
Aymen El Amri

Aymen El Amri is an author, entrepreneur, trainer, and polymath software engineer who has excelled in a range of roles and responsibilities in the field of technology including DevOps & Cloud Native, Cloud Architecture, Python, NLP, Data Science, and more.

Aymen has trained hundreds of software engineers and written multiple books and courses read by thousands of other developers and software engineers.

Aymen El Amri has a practical approach to teaching based on breaking down complex concepts into easy-to-understand language and providing real-world examples that resonate with his audience.

Some projects he founded are FAUN,, and Marketto. You can find Aymen on Twitter and Linkedin.

Table of Contents

    • Preface
    • The Ansible Workshop
      • What Are You Going To Learn?
      • To Whom Is This Guide For?
      • About The Author
      • Join The Community
    • Overview Of Ansible
      • What Is Ansible?
      • The Tale Of Ansible
      • Declarative vs Imperative Automation
      • Ansible Architecture
        • Inventory
        • Playbooks
        • Modules
        • Plugins
        • Roles
        • Ansible Vault
        • Ansible Engine
      • How Ansible Works?
      • Pros Of Ansible
      • Cons Of Ansible
      • Ansible vs Other Tools
        • Chef vs Ansible
        • Puppet vs Ansible
        • SaltStack vs Ansible
    • Introduction To Ansible
      • Prerequisites
      • Installing And Configuring Ansible
    • Ansible Inventory
      • Understanding The Ansible Inventory
      • Creating Advanced Ansible Inventories
      • Advanced Techniques To Target Specific Managed Nodes
      • Using The Default Inventory
      • Dynamic Inventories
    • Creating And Using Playbooks
      • Ad-hoc Commands vs Playbooks
      • Creating A Playbook
      • Playbook, Play, And Tasks
      • Creating Advanced Playbooks - Part 1
      • Creating Advanced Playbooks - Part 2
    • Ansible Facts
      • What Are Ansible Facts And Why Do We Need Them?
      • Finding Ansible Facts
      • How To Use Ansible Facts
      • Advanced Usage Of Ansible Facts
    • Debugging Ansible
      • Enabling Debugging
      • Debugging Tasks
        • Identify The Task That Failed
        • List The Task Variables
        • Identify The Host Where The Task Has Failed
        • Print The Execution Result of The Task
        • List All Task Arguments
        • Getting A Single Task Argument
        • Using The Debugger To Fix The Error
      • Enabling Debugging For All Tasks
      • Choosing When To Debug
      • Low-Level Debugging
      • Dry Run: Testing Playbooks Without Executing Them
      • Callback Plugins
      • Printing Variables
      • Printing The Output Of A Command
      • Printing The Output Of A Task
      • Using Your IDE To Write Better Playbooks
    • Ansible Vault And Sensitive Data Management
      • What Is Ansible Vault?
      • How To Use Ansible Vault
      • Using Password Files
      • Using Vault IDs
    • Ansible Blocks
      • What Are Ansible Blocks?
      • How To Use Ansible Blocks
      • Error Handling With Ansible Blocks
      • Using “Rescue” And “Always” Together
      • Ansible Blocks With Asynchronous Tasks
    • Ansible Modules, Plugins And Filters
      • What Is An Ansible Module?
      • What Is An Ansible Plugin?
      • Modules vs Plugins
      • Installing Ansible Modules And Plugins
      • Exploring The Lookup Plugins
      • Creating Ansible Modules
        • Documenting Your Module
        • Using The AnsibleModule Utility Class
        • A Full Example
        • Imports And Metadata
        • Function run_module()
        • Function main()
        • Execution Check
      • Developing An Ansible Module That Uses Generative AI
      • What Is An Ansible Filter?
      • Using Ansible Filters
      • Creating Ansible Filters
    • Ansible Roles
      • Role Directory Structure
        • Using “defaults”
        • Using “files”
        • Using “handlers”
        • Using “meta”
        • Using “tasks”
        • Using “templates”
        • Using “tests”
        • Using “vars”
      • Creating A Role
    • Making Ansible Faster
      • Disable SSH Host Key Checking
      • Disable Fact Gathering
      • Use More Forks
      • Optimize How Ansible Uses SSH
      • Use Asynchronous Tasks
      • Sequential vs Batch Mode
      • Using Execution Strategies
    • Managing Docker And Docker Compose with Ansible
      • Installation And Prerequisites
      • Building Docker Images From Ansible Playbooks
      • Tagging And Pushing Docker Images
      • Managing Docker Containers From Ansible Playbooks
      • Managing Docker Networks From Ansible Playbooks
      • Managing Docker Volumes From Ansible Playbooks
      • Docker Compose Up And Running With Ansible
    • Automating Kubernetes with Ansible
      • What Is A Highly Available Kubernetes Cluster?
        • Etcd Nodes
        • Control Plane Nodes
        • Worker Nodes
      • Creating A Highly Available Kubernetes Cluster With Kubespray And Ansible
        • Available Options To Deploy Kubernetes
        • Prerequisites And Initial Setup
        • Creating The Inventory
        • Creating The Cluster
        • How Kubespray Works
          • Step 1: Pre-Configuration Checks and Setup
          • Step 2: Setting Up Container Runtime
          • Step 3: Network Plugin Installation
          • Step 4: Kubernetes Components Installation
          • Step 5: Initialization of the First Control Plane Node
          • Step 6: Setting Up etcd Cluster
          • Step 7: Joining Additional Control Plane Nodes
          • Step 8: Joining Worker Nodes
          • Step 9: Cluster Configuration With Addons
          • Step 10: Cluster Verification And Health Checks
          • Step 11: Security Configuration
          • Step 12: Applying Custom Configurations
          • Step 13: Cluster Ready For Deployment
        • Start Using The Cluster
      • Deploying To Kubernetes With Ansible
      • Deploying To Kubernetes With Ansible And The K8s Module
        • Using Remote Manifests
        • Inline Manifests
        • Validating Kubernetes Definitions
        • Managing Multiple Clusters
        • Patching Resources
        • Restarting Deployments
      • Deploying To Kubernetes With Ansible And Helm
      • Templating Kubernetes Resources With Ansible
      • Troubleshooting Kubernetes With Ansible
        • Creating Generic Debug Tasks To View Kubernetes Resources
        • Viewing Kubernetes Pod Logs With Ansible
      • Ansible + Kubernetes = A Powerful Combination
    • Ansible Cheat Sheet
      • Installing Ansible
        • On Linux
        • On macOS
        • On Windows
      • Configuring Ansible
      • Inventory
        • Setting Up the Inventory File (INI)
        • Setting Up the Inventory File (YAML)
      • Ansible Host Variables
      • Testing Your Setup
      • Playbook Structure
      • Playbook Keywords
      • Common Modules
        • Running a Command
        • Running a Shell Command
        • Running a Raw Command
        • Copying a File
        • Installing a Package
        • Restarting a Service
        • Copying a File with Permissions
        • Copying a File with Permissions and Context
      • Playbooks
        • Running a Playbook
        • Run a Playbook with Inventory
        • Run a Playbook with Inventory and Limit
        • Running a Playbook with Limit
        • Running a Playbook with Tags
        • Running a Playbook with Skip Tags
        • Running a Playbook with Extra Variables
        • Running a Playbook with Vault Password File
        • Running a Playbook with Ask Vault Password
        • Running a Playbook with Ask Sudo Password
        • Running a Playbook with Ask Pass
        • Run a Playbook with Check Mode
        • Run a Playbook with Diff Mode
        • Run a Playbook with Verbose Mode
        • Run a Playbook with Extra Verbose Mode
        • Run a Playbook with Extra Extra Verbose Mode
        • Run a Playbook with Extra Extra Extra Verbose Mode
        • Run a Playbook with Extra Extra Extra Extra Verbose Mode
        • Run a Playbook with Forks
        • Run a Playbook with Timeout
      • Jinja2
        • Using Jinja2
        • Using Jinja2 with Filters
        • Jinja2 Template
        • Jinja2 Template with Variables
        • Templates with Loops
        • Templates with Conditionals
        • Templates with Filters
      • Host Patterns
      • Debugging
        • Syntax Check a Playbook
        • Check Hosts Are Reachable
        • Check Hosts Are Reachable with SSH
        • Check Hosts Are Reachable with WinRM
        • Check Hosts Are Reachable with Local
        • Verbose Mode
        • Debug Mode
        • Capture Output
        • Capture Output and Show Only Specific Fields
        • Capture Output and Show Only Specific Fields with Jinja2
      • Gathering Facts
        • Gathering Facts for All Hosts
        • Gathering Facts for a Specific Host
        • Gathering Facts for a Specific Host and Saving to a File
      • Variables
        • Setting a Variable
        • Setting a Variable with Multiple Lines
        • Setting a Variable with Multiple Lines and Indentation
      • Conditionals
        • When
        • When with Multiple Conditions
      • Loops
        • Looping Over a List
        • Looping Over a Dictionary
        • Looping Over a Dictionary using “with_dict”
        • Looping Over a List with “with_items”
      • Handlers
        • Using Handlers
        • Using Handlers with Multiple Tasks
        • Using Handlers with Multiple Tasks and Different Handlers
      • Conditional Execution
        • Using “ignore_errors” to Continue Execution Even After Failures
        • Using “changed_when” to Control When a Task Is Considered Changed
        • Using “failed_when” to Control When a Task Is Considered Failed
        • Failing a Playbook with “fail”
      • Vault
        • Editing an Encrypted File
        • Updating Encryption Password
        • Viewing an Encrypted File
        • Encrypting a File
        • Encrypting a File with a Password File
        • Decrypting a File
        • Encrypting a String
        • Encrypting a String with a Password File
      • Asynchronous Tasks
        • Running a Task Asynchronously
        • Checking the Status of Asynchronous Tasks
      • Roles
        • Creating a Role
        • Using a Role
        • Using a Role with Variables
        • Using a Role with Multiple Variables
        • Using a Role with Tags
      • Ansible Galaxy
        • Searching for Roles
        • Installing a Role
        • Installing a Role with a Specific Version
      • Ansible Collections
        • Installing a Collection
        • Installing a Collection with a Specific Version
        • Installing a Collection from a File
        • Installing a Collection from a Directory
      • Resources About Ansible
        • Official Ansible Documentation
        • Ansible Blogs and Articles
        • Ansible Community and Forums
        • Ansible GitHub Repository
        • Ansible Videos
        • Ansible Tools
        • IDE Extensions
          • VSCode
          • PyCharm
          • Sublime
          • Vim
        • Newsletters
    • Afterword

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.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

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 earnedover $13 millionwriting, 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

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub