Learn Ansible....2
Contributors....3
About the author....3
About the reviewer....4
Preface....21
Who this book is for....22
What this book covers....23
To get the most out of this book....24
Download the example code files....25
Conventions used....25
Get in touch....26
Share Your Thoughts....26
Download a free PDF copy of this book....26
Part 1: Introducing, Installing, and Running Ansible....28
Chapter 1: Installing and Running Ansible....29
Technical requirements....29
My story: part one....30
Ansible’s story....31
What is Ansible?....31
Ansible, the software....32
Ansible versus other tools....33
Declarative versus imperative....34
Configuration versus orchestration....37
Looking at some code....37
My story: part two....40
Installing and running Ansible....40
Installing on macOS....40
Installing on Linux....45
Installing on Windows 11....47
Launching a virtual machine....49
An introduction to playbooks....51
Host inventories....52
Playbooks....54
Summary....61
Further reading....62
Chapter 2: Exploring Ansible Galaxy....63
Technical requirements....63
The Ansible release life cycle....63
The life cycle of a release....65
Introduction to Ansible Galaxy....66
What is a role?....67
Publishing to and using Ansible Galaxy roles....71
Publishing your roles to Ansible Galaxy....72
Using roles from Ansible Galaxy....75
Ansible collections....78
Ansible Galaxy commands....78
Summary....80
Further reading....80
Chapter 3: The Ansible Commands....81
Inbuilt commands....81
Ansible....81
The ansible-config command....87
The ansible-console command....88
The ansible-inventory command....90
What is ansible-pull?....91
Using the ansible-vault command....92
Third-party commands....97
The ansible-inventory-grapher command....97
Summary....99
Further reading....99
Part 2: Deploying Applications....101
Chapter 4: Deploying a LAMP Stack....102
Technical requirements....102
The playbook structure....103
The LAMP stack....104
The common role....104
The Apache role....108
The MariaDB role....112
The PHP role....117
The LAMP playbook....120
Summary....124
Further reading....124
Chapter 5: Deploying WordPress....125
Technical requirements....125
Preinstallation tasks....125
The stack_install role....126
Enabling the NGINX repository....127
The stack_config role....129
WordPress system user....129
NGINX configuration....130
The wordpress role....136
Some facts....136
WordPress CLI installation....137
Creating the WordPress database....137
Downloading, configuring, and installing WordPress....138
WordPress plugins installation....140
Running the WordPress playbook....141
Summary....145
Further reading....145
Chapter 6: Targeting Multiple Distributions....147
Technical requirements....147
Debian and Red Hat....148
Multi-distribution considerations....149
The Stack Install role....149
The Stack Config role....150
The WordPress role....150
Adapting the roles....151
Operating system family....151
The Stack Install role....153
The Stack Config role....154
The WordPress role....157
Running the playbook....157
Summary....159
Further reading....159
Chapter 7: Ansible Windows Modules....160
Technical requirements....160
Launching a Windows server in Azure....160
Ansible preparation....164
The ping module....166
The setup module....166
The Windows Playbook roles....168
Enabling Windows features....168
Creating a user....171
Installing applications using Chocolatey....171
Information role....172
Running the Playbook....172
Summary....174
Further reading....175
Part 3: Network and Cloud Automation....176
Chapter 8: Ansible Network Modules....177
Manufacturer and device support....177
The collections....178
Summary....184
Further reading....184
Chapter 9: Moving to the Cloud....185
Technical requirements....185
An introduction to Microsoft Azure....185
Launching instances in Microsoft Azure....186
Preparing Ansible for Microsoft Azure....187
Reviewing the variables....187
The resource group task....190
The networking tasks....191
Bootstrapping WordPress....197
The site and host environment files....197
The secrets role....198
Other changes....199
Running the playbook....199
Summary....200
Chapter 10: Building Out a Cloud Network....202
Technical requirements....202
An introduction to AWS....202
Amazon VPC overview....204
Creating an access key and secret....205
Getting Ansible ready for targeting AWS....206
The AWS playbook....207
The playbook variables....208
The VPC role....209
The subnets role....210
The gateway role....213
The security group’s role....214
Running the playbook....216
Summary....218
Further reading....218
Chapter 11: Highly Available Cloud Deployments....219
Technical requirements....219
Planning the deployment....219
Costing the deployment....220
WordPress considerations and high availability....221
The Playbook....222
The variables....224
EC2 configuration....226
The Playbook roles....229
Running the Playbook....245
Playbook run highlights....246
Terminating all the resources....251
Summary....253
Chapter 12: Building Out a VMware Deployment....254
Technical requirements....254
An introduction to VMware....254
The VMware REST modules....255
VMware REST appliance modules....255
VMware REST content modules....259
vCenter modules....259
Summary....262
Part 4: Ansible Workflows....263
Chapter 13: Scanning Your Ansible Playbooks....264
Technical requirements....264
Why scan your playbooks?....264
Docker overview and installation....265
Installing Docker Desktop on macOS....265
Installing Docker Desktop on Windows....266
Installing Docker Desktop on Linux....266
Exploring Checkov....266
Exploring KICS....271
Running the scan....271
Reviewing the results....272
Re-running the scan....276
Output files....276
Summary....278
Further reading....278
Chapter 14: Hardening Your Servers Using Ansible....279
Technical requirements....279
The scanning tools....279
OpenSCAP....279
WPScan....281
OWASP ZAP....281
The playbook....282
The common role....283
The Docker role....283
The WordPress roles....284
The scan role....284
The OpenSCAP role....287
Running the playbook....294
Summary....296
Chapter 15: Using Ansible with GitHub Actions and Azure DevOps....298
Technical requirements....298
GitHub Actions....298
Preparation....299
Understanding the GitHub Action workflow....303
Committing the code....308
Azure DevOps....312
Creating and configuring our project....313
Cloning the repository and uploading the code....315
The Azure DevOps pipeline....316
Summary....324
Further reading....324
Chapter 16: Introducing Ansible AWX and Red Hat Ansible Automation Platform....325
Technical requirements....325
Red Hat Ansible Automation Platform versus AWX....325
Ansible AWX....327
Deploying and configuring the Ansible AWX Operator....327
Setting up our playbook....331
Running our playbooks....337
Terminating the Kubernetes cluster....339
Playbook considerations....340
Ansible AWX’s advantages and disadvantages....342
Summary....343
Further reading....344
Chapter 17: Next Steps with Ansible....345
Technical requirements....345
Integrating with third-party services....345
Slack....345
Other integrations....351
Summary of third-party services....353
The Ansible playbook debugger....355
Debugging the task....355
Summary of the Ansible debugger....357
Some real-world examples....357
Automating a complex deployment....358
Combining Ansible and other tools....358
Summary....362
Index....364
Why subscribe?....384
Other Books You May Enjoy....384
Packt is searching for authors like you....387
Share Your Thoughts....387
Download a free PDF copy of this book....387
Learn how to write and run Ansible Playbooks, from the basics to launching complex multi-tier applications across public cloud platforms such as Amazon Web Services (AWS) and Microsoft Azure
Are you tired of manually deploying and managing your infrastructure and looking for ways to streamline your deployments, introduce consistency and collaboration, and save time? If so, then Learn Ansible is for you. Written by a DevOps practitioner and system administrator with 30+ years of experience, this book will teach you how to automate repetitive tasks and effortlessly manage several resources from a single code base.
From installing Ansible and writing your first playbook to deploying multi-tier applications across different cloud platforms, this book will take you on an exciting learning journey. By learning the art of defining highly available cloud infrastructure using code, you’ll find it easy to distribute configurations alongside your application. You’ll explore Ansible Galaxy, learn about community-contributed Ansible roles, and discover how to create and share your own roles. Later, the book delves into the capabilities of Ansible AWX and integrating Ansible with your CI/CD pipelines, using Azure DevOps and GitHub Actions. With real-world examples and hands-on tutorials, you’ll build a solid foundation to tackle any automation project.
By the end of this book, you'll be able to confidently implement Ansible in your environment and day-to-day workflows, taking your deployments to the next level.
Learn Ansible is for system administrators, developers, and infrastructure engineers who want to implement infrastructure automation and configuration management using Ansible. The hands-on tutorials make this book ideal for both beginners as well as intermediate users looking to take their Ansible skills to the next level. Technology professionals working with public cloud platforms like AWS and Azure will also find valuable insights into automating deployments.