Practical Ansible: Learn how to automate infrastructure, manage configuration, and deploy applications

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Leverage the power of Ansible to gain complete control over your systems and automate deployments along with implementing configuration changes Key Features Orchestrate major cloud platforms such as OpenStack, AWS, and Azure Use Ansible to automate network devices Automate your containerized workload with Docker, Podman, or Kubernetes Book Description Ansible empowers you to automate a myriad of tasks, including software provisioning, configuration management, infrastructure deployment, and application rollouts. It can be used as a deployment tool as well as an orchestration tool. While Ansible provides simple yet powerful features to automate multi-layer environments using agentless communication, it can also solve other critical IT challenges, such as ensuring continuous integration and continuous deployment (CI/CD) with zero downtime. In this book, you'll work with the latest release of Ansible and learn how to solve complex issues quickly with the help of task-oriented scenarios. You'll start by installing and configuring Ansible on Linux and macOS to automate monotonous and repetitive IT tasks and learn concepts such as playbooks, inventories, and roles. As you progress, you'll gain insight into the YAML syntax and learn how to port between Ansible versions. Additionally, you'll understand how Ansible enables you to orchestrate multi-layer environments such as networks, containers, and the cloud. By the end of this Ansible book, you'll be well versed in writing playbooks and other related Ansible code to overcome all your IT challenges, from infrastructure-as-a-code provisioning to application deployments and handling mundane day-to-day maintenance tasks. What you will learn Explore the fundamentals of the Ansible framework Understand how collections enhance your automation efforts Avoid common mistakes and pitfalls when writing automation code Extend Ansible by developing your own modules and plugins Contribute to the Ansible project by submitting your own code Follow best practices for working with cloud environment inventories Troubleshoot issues triggered during Ansible playbook runs Who this book is for This book is for DevOps engineers, administrators, or any IT professionals looking to automate IT tasks using Ansible. Prior knowledge of Ansible is not a prerequisite.

Author(s): James Freeman, Fabio Alessandro Locati, Daniel Oh
Edition: 2
Publisher: Packt Publishing Pvt Ltd
Year: 2023

Language: English
Pages: 942

Practical Ansible
Contributors
About the authors
About the reviewers
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Conventions used
Get in touch
Share your thoughts
Download a free PDF copy of this book
Part 1:Learning the Fundamentals of Ansible
1
Getting Started with Ansible
Technical requirements
Installing and configuring Ansible
Understanding Ansible version numbers
Installing Ansible on Linux and FreeBSD
Working with virtual environments
Installing from GitHub
Installing Ansible on macOS
Configuring Windows hosts for Ansible
Getting to know your Ansible installation
Understanding how Ansible connects to hosts
Verifying the Ansible installation
Managed node requirements
Summary
Questions
Further reading
2
Understanding the Fundamentals of Ansible
Technical requirements
Getting familiar with the Ansible framework
Breaking down the Ansible components
Learning the YAML syntax
Organizing your automation code
Exploring the configuration file
Command-line arguments
Understanding ad hoc commands
Defining variables
Understanding Jinja2 filters
Summary
Questions
Further reading
3
Defining Your Inventory
Technical requirements
Creating an inventory file and adding hosts
Using host groups
Adding host and group variables to your inventory
Generating a dynamic inventory file
Using multiple inventory sources in the inventory directories
Using static groups with dynamic groups
Special host management using patterns
Summary
Questions
Further reading
4
Playbooks and Roles
Technical requirements
Understanding the playbook framework
Comparing playbooks and ad hoc tasks
Defining plays and tasks
Understanding roles – the playbook organizer
Setting up role-based variables and dependencies
Ansible Galaxy
Using conditions in your code
Repeating tasks with loops
Grouping tasks using blocks
Configuring play execution via strategies
Using ansible-pull
Summary
Questions
Further reading
Part 2:Expanding the Capabilities of Ansible
5
Creating and Consuming Modules
Technical requirements
Executing multiple modules using the command line
Reviewing the module index
Accessing module documentation from the command line
Module return values
Developing custom modules
Avoiding common pitfalls
Testing and documenting your module
The module checklist
Contributing upstream – submitting a GitHub pull request
Summary
Questions
Further reading
6
Creating and Consuming Collections
Technical requirements
Introduction to Ansible collections
Understanding fully qualified collection names
Managing collections on your control node
Updating your Ansible collections and core installation
Creating your own collections
Summary
Questions
Further reading
7
Creating and Consuming Plugins
Technical requirements
Discovering the plugin types
Finding included plugins
Creating custom plugins
Learning to integrate custom plugins with Ansible source code
Sharing plugins with the community
Summary
Questions
Further reading
8
Coding Best Practices
Technical requirements
The preferred directory layout
Differentiating between different environment types
The proper approach to defining group and host variables
Using top-level playbooks
Leveraging version control tools
Setting OS and distribution variances
Porting between Ansible versions
Summary
Questions
Further reading
9
Advanced Ansible Topics
Technical requirements
Asynchronous versus synchronous actions
Controlling play execution for rolling updates
Configuring the maximum failure percentage
Setting task execution delegation
Using the run_once option
Running playbooks locally
Working with proxies and jump hosts
Configuring playbook prompts
Placing tags in the plays and tasks
Securing data with Ansible Vault
Summary
Questions
Further reading
Part 3:Using Ansible in an Enterprise
10
Network Automation with Ansible
Technical requirements
Why automate network management?
How Ansible manages networking devices
How to enable network automation
The available Ansible networking modules
Connecting to network devices
Environment variables for network devices
Custom conditional statements for networking devices
Summary
Questions
Further reading
11
Container and Cloud Management
Technical requirements
Automating Docker and Podman with Ansible
Managing Docker
Managing Podman
Managing Kubernetes with Ansible
Installing Ansible Kubernetes dependencies
Listing Kubernetes namespaces with Ansible
Creating a Kubernetes namespace with Ansible
Creating a Kubernetes service with Ansible
Exploring container-focused modules
Automating with Amazon Web Services
Installation
Authentication
Creating your first machine
Complementing Google Cloud Platform with automation
Installation
Authentication
Creating your first machine
Seamless automation integration with Azure
Installation
Authentication
Creating your first machine
Using Ansible to orchestrate OpenStack
Installation
Authentication
Creating your first machine
Summary
Questions
Further reading
12
Troubleshooting and Testing Strategies
Technical requirements
Digging into playbook execution problems
Using host facts to diagnose failures
Testing with a playbook
Using check mode
Solving host connection issues
Passing working variables via the CLI
Limiting the host’s execution
Flushing the code cache
Checking for bad syntax
Summary
Questions
Further reading
13
Getting Started with Ansible Automation Controller
Technical requirements
Installing AWX
Running your first playbook from AWX
Creating an AWX project
Creating an inventory
Creating a job template
Running a job
Controlling access to AWX
Creating a user
Creating a team
Creating an organization
Assigning permissions in AWX
Summary
Questions
14
Execution Environments
Technical requirements
The importance of execution environments
Building an execution environment
Creating a minimal execution environment
Creating an execution environment with a specific Python interpreter
Creating an execution environment with additional dependencies
Running playbooks in an execution environment
Uploading execution environments to a container registry
Using execution environments in Ansible Automation Controller
Summary
Questions
Further reading
Assessments
Chapter 1
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 7
Chapter 8
Chapter 9
Chapter 10
Chapter 11
Chapter 12
Chapter 13
Chapter 14
Index
Why subscribe?
Other Books You May Enjoy
Packt is searching for authors like you
Share your thoughts
Download a free PDF copy of this book