Among the many configuration management tools available, Ansible has some distinct advantages: It's minimal in nature. You don't need to install anything on your nodes. And it has an easy learning curve. With this updated third edition, you'll quickly learn how to be productive with this tool, wheth
Ansible: Up and Running, 3rd Edition
β Scribed by Bas Meijer, Lorin Hochstein, RenΓ© Moser
- Publisher
- O'Reilly Media, Inc.
- Year
- 2022
- Tongue
- English
- Leaves
- 590
- Edition
- 6th early release
- Category
- Library
No coin nor oath required. For personal study only.
β¦ Synopsis
Among the many configuration management tools available, Ansible has some distinct advantages: It's minimal in nature. You don't need to install anything on your nodes. And it has an easy learning curve. With this updated third edition, you'll quickly learn how to be productive with this tool, whether you're a developer deploying code to production or a system administrator looking for a better automation solution. Authors Bas Meijer, Lorin Hochstein, and Rene Moser show you how to write playbooks (Ansible's configuration management scripts), manage remote servers, and explore the tool's real power: built-in declarative modules. You'll learn how Ansible has all the functionality you need and the simplicity you desire. Explore Ansible configuration management and deployment Learn how to apply Ansible best practices Understand how to use the new collections format Create a local development environment Generate reusable Ansible content for open source middleware Build container images, images for cloud instances, and cloud computing instances Ready to use Ansible for mission-critical work? With this new edition, you'll learn how to eliminate the guesswork and assumptions when using software engineering methods to validate code quality.
β¦ Table of Contents
- Introduction
A Note About Versions
Ansible: What Is It Good For?
How Ansible Works
Whatβs So Great About Ansible?
Simple
Powerful
Secure
Is Ansible Too Simple?
What Do I Need to Know?
What Isnβt Covered
Installing Ansible
Setting Up a Server for Testing
Using Vagrant to Set Up a Test Server
Telling Ansible About Your Test Server
Simplifying with the ansible.cfg File
Kill your darlings
Moving Forward - Playbooks: A Beginning
Preliminaries
A Very Simple Playbook
Running the Playbook
Playbooks Are YAML
Anatomy of a Playbook
Plays
Did Anything Change? Tracking Host State
Getting Fancier: TLS Support
Conclusion - Inventory: Describing Your Servers
Inventory/Hosts Files
Preliminaries: Multiple Vagrant Machines
Behavioral Inventory Parameters
ansible_connection
ansible_shell_type
ansible_python_interpreter
ansible_*_interpreter
Changing Behavioral Parameter Defaults
Groups and Groups and Groups
Example: Deploying a Django App
Aliases and Ports
Groups of Groups
Numbered Hosts (Pets versus Cattle)
Hosts and Group Variables: Inside the Inventory
Host and Group Variables: In Their Own Files
Dynamic Inventory
Inventory Plugins
Amazon EC2
Azure Resource Manager
The Interface for a Dynamic Inventory Script
Writing a Dynamic Inventory Script
Breaking the Inventory into Multiple Files
Adding Entries at Runtime with add_host and group_by
add_host
group_by - Variables and Facts
Defining Variables in Playbooks
Viewing the Values of Variables
Registering Variables
Facts
Viewing All Facts Associated with a Server
Viewing a Subset of Facts
Any Module Can Return Facts
Local Facts
Using set_fact to Define a New Variable
Built-in Variables
hostvars
inventory_hostname
Groups
Setting Variables on the Command Line
Precedence - Introducing Mezzanine: Our Test Application
Why Is Deploying to Production Complicated?
PostgreSQL: The Database
Gunicorn: The Application Server
Nginx: The Web Server
Supervisor: The Process Manager - Deploying Mezzanine with Ansible
Listing Tasks in a Playbook
Organization of Deployed Files
Variables and Secret Variables
Installing Multiple Packages
Adding the Become Clause to a Task
Updating the Apt Cache
Checking Out the Project Using Git
Installing Mezzanine and Other Packages into a Virtual Environment
Complex Arguments in Tasks: A Brief Digression
Configuring the Database
Generating the local_settings.py File from a Template
Running django-manage Commands
Running Custom Python Scripts in the Context of the Application
Setting Service Configuration Files
Enabling the Nginx Configuration
Installing TLS Certificates
Installing Twitter Cron Job
The Full Playbook
Running the Playbook Against a Vagrant Machine
Troubleshooting
Cannot Check Out Git Repository
Cannot Reach 192.168.33.10.nip.io
Bad Request (400)
Deploying Mezzanine on Multiple Machines - Roles: Scaling Up Your Playbooks
Basic Structure of a Role
Example: Deploying Mezzanine with Roles
Using Roles in Your Playbooks
Pre-Tasks and Post-Tasks
A database Role for Deploying the Database
A mezzanine Role for Deploying Mezzanine
Creating Role Files and Directories with ansible-galaxy
Dependent Roles
Ansible Galaxy
Web Interface
Command-Line Interface
Roles Requirements in Practice
Contributing Your Own Role - Complex Playbooks
Dealing with Badly Behaved Commands: changed_when and failed_when
Filters
The Default Filter
Filters for Registered Variables
Filters That Apply to File Paths
Writing Your Own Filter
Lookups
file
pipe
env
password
template
csvfile
dnstxt
redis
Writing Your Own Lookup Plugin
More Complicated Loops
With Lookup Plugin
with_lines
with_fileglob
with_dict
Looping Constructs as Lookup Plugins
Loop Controls
Setting the Variable Name
Labeling the Output
Imports and Includes
Dynamic Includes
Role Includes
Role Flow Control
Blocks
Error Handling with Blocks
Encrypting Sensitive Data with Vault - Customizing Hosts, Runs, and Handlers
Patterns for Specifying Hosts
Limiting Which Hosts Run
Running a Task on the Control Machine
Manually Gathering Facts
Retrieving an IP Address from the Host
Running on One Host at a Time
Running on a Batch of Hosts at a Time
Running Only Once
Limiting Which Tasks Run
Step
Start-at-Task
Running Tags
Skipping Tags
Running Strategies
Linear
Free
Mitogen
Advanced Handlers
Handlers in Pre and Post Tasks
Flush Handlers
Handlers Notifying Handlers
Handlers Listen - Callback Plugins
Stdout Plugins
ARA
debug
default
dense
json
minimal
null
oneline
Notification and Aggregate Plugins
Python requirements
foreman
hipchat
jabber
junit
log_plays
logentries
logstash
mail
profile_roles
profile_tasks
say
slack
splunk
timer - Making Ansible Go Even Faster
SSH Multiplexing and ControlPersist
Manually Enabling SSH Multiplexing
SSH Multiplexing Options in Ansible
More SSH Tuning
Algorithm Recommendations
Pipelining
Enabling Pipelining
Configuring Hosts for Pipelining
Mitogen for Ansible
Fact Caching
JSON File Fact-Caching Backend
Redis Fact-Caching Backend
Memcached Fact-Caching Backend
Parallelism
Concurrent Tasks with Async - Custom Modules
Example: Checking That You Can Reach a Remote Server
Using the Script Module Instead of Writing Your Own
can_reach as a Module
Should You Develop A Module?
Where to Put Your Custom Modules
How Ansible Invokes Modules
Generate a Standalone Python Script with the Arguments (Python Only)
Copy the Module to the Host
Create an Arguments File on the Host (Non-Python Only)
Invoke the Module
Expected Outputs
Output Variables that Ansible Expects
Implementing Modules in Python
Parsing Arguments
Accessing Parameters
Importing the AnsibleModule Helper Class
Argument Options
AnsibleModule Initializer Parameters
Returning Success or Failure
Invoking External Commands
Check Mode (Dry Run)
Documenting Your Module
Debugging Your Module
Implementing the Module in Bash
Specifying an Alternative Location for Bash
Example Modules - Ansible and Containers
Kubernetes
Docker Application Life Cycle
Registries
Ansible and Docker
Connecting to the Docker Daemon
Example Application: Ghost
Running A Docker Container Our Local Machine
Building an Image from a Dockerfile
Pushing Our Image to the Docker Registry
Orchestrating Multiple Containers on Our Local Machine
Querying Local Images
Deploying the Dockerized Application
Provisioning MySQL
Deploying the Ghost Database
Frontend
Frontend: Ghost
Frontend: Nginx
Cleaning Out Containers
Conclusion - Quality Assurance with Molecule
Installation and Setup
Configuring Molecule Drivers
Creating an Ansible Role
Scenarios
Configuring Scenarios in Molecule
Managing Virtual Machines
Managing Containers
Molecule Commands
Linting
YAMLlint
Ansible-lint
Ansible-later
Verifiers
Ansible
Goss
TestInfra
Conclusion - Collections
Installing Collections
Listing Collections
Using Collections in a Playbook
Developing a Collection
Conclusion - Debugging Ansible Playbooks
Humane Error Messages
Debugging SSH Issues
Common SSH Challenges
PasswordAuthentication no
SSH As a Different User
Host Key Verification Failed
Private Networks
The Debug Module
Playbook Debugger
The Assert Module
Checking Your Playbook Before Execution
Syntax Check
List Hosts
List Tasks
Check Mode
Diff (Show File Changes)
Limiting Which Tasks Run
Step
Start-at-Task
Tags
Limits - Ansible Automation Platform
Subscription Models
Ansible Automation Platform Trial
What Ansible Automation Platform Solves
Access Control
Projects
Inventory Management
Run Jobs by Job Templates
RESTful API
AWX.AWX
Installation
Create an Organization
Create an Inventory
Running a Playbook with a Job Template
Using Containers to run Ansible
Creating Execution Environments - Vagrant
Convenient Vagrant Configuration Options
Port Forwarding and Private IP Addresses
Enabling Agent Forwarding
The Docker Provisioner
The Ansible Provisioner
When the Provisioner Runs
Vagrant Plugins
Hostmanager
VBGuest
VirtualBox Customization
Vagrantfile Is Ruby
Conclusion - Managing Windows Hosts
Connection to Windows
PowerShell
Windows Modules
Our Java Development Machine
Adding a Local User
Windows Features
Installing Software with Choco
Configuration of Java
Updating Windows
Conclusion - Creating Images
Creating Images with Packer
Docker Image: GCC 11
Vagrant VirtualBox VM
Cloud Images
Google Cloud Platform
Azure
Vagrantfile
The Playbook - Cloud Infrastructure
Terminology
Instance
Amazon Machine Image
Tags
Specifying Credentials
Environment Variables
Configuration Files
Prerequisite: Boto3 Python Library
Dynamic Inventory
Inventory Caching
Other Configuration Options
Defining Dynamic Groups with Tags
Applying Tags to Existing Resources
Nicer Group Names
Virtual Private Clouds
Configuring ansible.cfg for Use with ec2
Launching New Instances
EC2 Key Pairs
Creating a New Key
Uploading Your Public Key
Security Groups
Permitted IP Addresses
Security Group Ports
Getting the Latest AMI
Create a New Instance and Add it to a Group
Waiting for the Server to Come Up
Putting It All Together
Specifying a Virtual Private Cloud
Dynamic Inventory and VPC
Other Modules - CI/CD and Ansible
Continuous Integration
Elements in a CI System
Jenkins and Ansible
Jenkins Configuration as Code
Jenkins Job Configurations as Code
Running CI for Ansible Roles
Staging
Ansible Plugin
Ansible Tower Plugin
Conclusion
About the Authors
π SIMILAR VOLUMES
Among the many configuration management tools available, Ansible has some distinct advantages: It's minimal in nature. You don't need to install anything on your nodes. And it has an easy learning curve. With this updated third edition, you'll quickly learn how to be productive with this tool, wheth
In just five years, Kubernetes has radically changed the way developers and ops personnel build, deploy, and maintain applications in the cloud. With this book's updated third edition, you'll learn how this popular container orchestrator can help your company achieve new levels of velocity, agility,
Among the many configuration management tools available, Ansible has some distinct advantagesit's minimal in nature, you don't need to install anything on your nodes, and it has an easy learning curve. This practical guide shows you how to be productive with this tool quickly, whether you're a devel