Learn Ansible
local graph
Learn Ansible
Section titled “Learn Ansible”chapter_01
Section titled “chapter_01”node-book_learn-ansible_chapter-01-installing-and-running-ansible — Installing and Running Ansible
chapter_02
Section titled “chapter_02”node-book_learn-ansible_chapter-02-exploring-ansible-galaxy — Exploring Ansible Galaxy
chapter_03
Section titled “chapter_03”node-book_learn-ansible_chapter-03-the-ansible-commands — The Ansible Commands
chapter_04
Section titled “chapter_04”node-book_learn-ansible_chapter-04-deploying-a-lamp-stack — Deploying a LAMP Stack
chapter_05
Section titled “chapter_05”node-book_learn-ansible_chapter-05-deploying-wordpress — Deploying WordPress
chapter_06
Section titled “chapter_06”node-book_learn-ansible_chapter-06-targeting-multiple-distributions — Targeting Multiple Distributions
chapter_07
Section titled “chapter_07”node-book_learn-ansible_chapter-07-ansible-windows-modules — Ansible Windows Modules
chapter_08
Section titled “chapter_08”node-book_learn-ansible_chapter-08-ansible-network-modules — Ansible Network Modules
chapter_09
Section titled “chapter_09”node-book_learn-ansible_chapter-09-moving-to-the-cloud — Moving to the Cloud
chapter_10
Section titled “chapter_10”node-book_learn-ansible_chapter-10-building-out-a-cloud-network — Building Out a Cloud Network
chapter_11
Section titled “chapter_11”node-book_learn-ansible_chapter-11-highly-available-cloud-deployments — Highly Available Cloud Deployments
chapter_12
Section titled “chapter_12”node-book_learn-ansible_chapter-12-building-out-a-vmware-deployment — Building Out a VMware Deployment
chapter_13
Section titled “chapter_13”node-book_learn-ansible_chapter-13-scanning-your-ansible-playbooks — Scanning Your Ansible Playbooks
chapter_14
Section titled “chapter_14”node-book_learn-ansible_chapter-14-hardening-your-servers-using-ansible — Hardening Your Servers Using Ansible
chapter_15
Section titled “chapter_15”node-book_learn-ansible_chapter-15-using-ansible-with-github-actions-and-azure-devops — Using Ansible with GitHub Actions and Azure DevOps
chapter_16
Section titled “chapter_16”node-book_learn-ansible_chapter-16-introducing-ansible-awx-and-red-hat-ansible-automation-platf — Introducing Ansible AWX and Red Hat Ansible Automation Platform
Preface
Section titled “Preface”Ansible, an open source orchestration tool, has experienced significant growth and is now a comprehensive orchestration and configuration management solution under Red Hat’s ownership. This book will guide you through writing playbooks using core, vendor-supplied, and community Ansible modules to deploy various systems, from simple LAMP stacks to highly available public cloud infrastructures.
By the end of this book, you will have acquired the following skills:
- A solid foundational knowledge of Ansible and its various supporting tools
- The ability to write your own custom playbooks to configure both Linux and Windows servers
- The ability to define highly available cloud infrastructures using code, enabling the easy distribution of your infrastructure configuration alongside your code base
- An understanding of how to use Ansible Galaxy, use community-contributed roles, and create and contribute your own roles
- The ability to run your Ansible playbooks using GitHub Actions and Azure DevOps
- The ability to deploy and configure Ansible AWX, a web-based interface for Ansible
- Various skills gained from exploring several use cases demonstrating how to integrate Ansible into your daily tasks and projects
You will have a solid understanding of how to incorporate Ansible into your everyday responsibilities as a system administrator, developer, or DevOps practitioner.
Who this book is for
Section titled “Who this book is for”This book is written for people in the following roles who want to streamline their workflows by leveraging Ansible’s capabilities:
- System administrators*:* This book will help you automate repetitive tasks and ensure consistent configurations across your systems if you manage and maintain servers, networks, and other infrastructure components.
- Developers*:* As a developer, you can benefit from this book by learning how to use Ansible to provision and manage development environments, deploy applications, and integrate infrastructure-as-code practices into your development workflow.
- DevOps practitioners*:* If you are a DevOps practitioner responsible for bridging the gap between development and operations, this book will provide the tools and knowledge to create efficient, repeatable, and scalable deployment processes using Ansible.
No prior experience with Ansible is necessary to get started with this book.
What this book covers
Section titled “What this book covers”Chapter 1, Installing and Running Ansible, discusses the problems Ansible was developed to solve. After covering its background, we will work through installing Ansible on macOS and Linux. We will also discuss why there is no native Windows installer and cover installing Ansible on the Windows Subsystem for Linux.
Chapter 2, Exploring Ansible Galaxy, discusses Ansible Galaxy, an online repository of community and vendor-contributed roles. In this chapter, we will discover some of the best roles available, how to use them, and how to create your role and have it hosted on Ansible Galaxy.
Chapter 3, The Ansible Commands, explains how we examine Ansible commands before writing and executing more advanced playbooks. Here, we will cover using the tools that make up Ansible.
Chapter 4, Deploying a LAMP Stack, discusses deploying a complete LAMP stack using the various core modules that ship with Ansible. We will target the Ubuntu machine that is running locally.
Chapter 5, Deploying WordPress, expands on the LAMP stack playbook, which we deployed in the previous chapter as our base. We will use Ansible to download, install, and configure WordPress – a popular CMS.
Chapter 6, Targeting Multiple Distributions, explains how we will adapt the playbook from the previous chapter so it can run against both Debian, which we have been targeting so far, and Red Hat-based Linux distributions.
Chapter 7, Ansible Windows Modules, explores the ever-growing collection of Ansible modules that support and interact with Windows-based servers.
Chapter 8, Ansible Network Modules, discusses network modules available from various vendors through Ansible Galaxy. Due to their requirements, we will only discuss the functionality of these modules.
Chapter 9, Moving to the Cloud, discusses how we can move from using local virtual machines to using Ansible to deploy network and compute resources in Microsoft Azure. Then, we will use the playbook from the previous chapters to install and configure a LAMP stack and WordPress.
Chapter 10, Building Out a Cloud Network, since we will have just launched a virtual machine in Microsoft Azure, moves on to Amazon Web Services; however, before launching any compute instances, we must create a network in which they can be hosted.
Chapter 11, Highly Available Cloud Deployments, continues our Amazon Web Services deployment. We will start deploying compute and storage services into the network we created in the previous chapter, and by the end of the chapter, we will have a highly available WordPress installation.
Chapter 12, Building Out a VMware Deployment, discusses the modules that allow you to interact with the various components of a typical VMware installation.
Chapter 13, Scanning Your Ansible Playbooks, provides practical examples of running two third-party tools, Checkov and KICS. These tools are designed to scan your Ansible playbook code for common mistakes and potential security problems.
Chapter 14, Hardening Your Servers Using Ansible, explains how to install and execute OpenSCAP. We will also automatically generate remediation Ansible playbooks and Bash scripts to resolve any problems found during the scan. We will also look at running WPScan and OWASP ZAP scans against the resources deployed using the playbooks from previous chapters.
Chapter 15, Using Ansible with GitHub Actions and Azure DevOps, will examine running our Ansible playbook books from these two CI/CD platforms. As neither has native Ansible support, we will discuss how to install and run Ansible to get the most out of the platforms.
Chapter 16, Introducing Ansible AWX and Red Hat Ansible Automation Platform, examines two web-based interfaces: we will discuss the commercial Red Hat Ansible Automation Platform and then take a deep dive into deploying and configuring the open source Ansible AWX.
Chapter 17, Next Steps with Ansible, discusses how Ansible can be integrated into our day-to-day workflows, from interacting with collaboration services to troubleshooting your playbooks with the built-in debugger. We will also look at real-world examples of how I have used Ansible across organizations I have worked with.
To get the most out of this book
Section titled “To get the most out of this book”To get the most out of this book, I assume that you have the following:
- Some experience of using the command line on both Linux-based machines and macOS
- A basic understanding of how to install and configure services on a Linux server
- A working knowledge of services and languages such as Git, YAML, and virtualization
Software/hardware covered in the book Operating system requirements Ansible macOS, Linux, or Windows via Subsystem for Linux Canonical Multipass macOS, Linux, or Windows Various CLIs for public cloud providers macOS, Linux, or Windows via Subsystem for Linux
If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.
Conventions used
Section titled “Conventions used”There are a number of text conventions used throughout this book.
Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “As you can see, it is calling a variable called {{ apache_packages }}, which is defined in roles/apache/defaults/main.yml as follows.”
A block of code is set as follows:
- name: "Install apache packages" ansible.builtin.apt: state: "present" pkg: "{{ apache_packages }}"When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
- name: "Install apache packages" ansible.builtin.apt: state: "present" pkg: "{{ apache_packages }}"Any command-line input or output is written as follows:
$ ansible-playbook -i hosts site.ymlBold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: “You can leave the remaining options at their defaults and then click on the Create repository button at the end of the form.”
Tips or important notes
Appear like this.
Source: