Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Learn Ansible
Learn Ansible

Learn Ansible: Automate your cloud infrastructure, security configuration, and application deployment with Ansible , Second Edition

eBook
$9.99 $35.99
Paperback
$44.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Learn Ansible

Installing and Running Ansible

Welcome to this, our first chapter in the second edition of Learn Ansible. In this chapter, we will look at a few topics to introduce you to Ansible; these topics will familiarize you with the basics of what Ansible is and give you a few different use cases.

By the end of the chapter, you will have gotten hands-on with Ansible and covered the following:

  • Who is behind Ansible?
  • The differences between Ansible and other tools
  • The problem Ansible solves
  • How to install Ansible on macOS and Linux
  • Running Ansible on Windows 11 using the Windows Subsystem for Linux
  • Launching a test virtual machine
  • An introduction to playbooks

Before we start talking about Ansible, let’s quickly discuss my background, how I came to be writing a book about Ansible, and what you will need to install and run Ansible on your system.

Technical requirements

Later in this chapter, we will install Ansible, so you will need a machine capable of running it. I will go into more detail about these requirements in the second half of the chapter. We will also use Multipass to launch a virtual machine locally. A section walks through installing Multipass and downloading an Ubuntu image to use the virtual machine’s base, which is a download of a few hundred MBs. You can find all of the code used in this chapter at https://github.com/PacktPublishing/Learn-Ansible-Second-Edition/tree/main/Chapter01.

My story: part one

I have been working with servers, primarily ones that serve web pages, since the late 90s, and the landscape is unrecognizable. Here is a quick overview of my first few years running servers to give you an idea of how I used to operate my early servers.

Like most people at the time, I started with a shared hosting account where I had very little control over anything on the server side when the website I was running outgrew shared hosting due to the forum, which made up part of the site’s popularity. I moved to a dedicated server, where I thought I could flex my future system administrator muscles, but I was wrong.

The server I got was a Cobalt RaQ 3; this was a 1U server appliance that was ahead of its time. However, I did not have root-level access to the machine, and I had to use the web-based control panel for everything I needed to do. Eventually, I got a level of access where I could access the server using Telnet; I now know this isn’t...

Ansible’s story

Let’s take a quick look at who developed Ansible and what it actually is.

What is Ansible?

Before we discuss how Ansible started, we should quickly discuss the origin of the name. The term “Ansible” was penned by science fiction novelist Ursula K. Le Guin; it was first used in her novel Rocannon’s World, which was first published in 1966. In the story’s context, an Ansible is a fictional device that sends and receives messages faster than light.

Note

In 1974, Ursula K. Le Guin’s novel The Dispossessed: An Ambiguous Utopia was published. This book features the development of the Ansible technology by exploring the (fictional) details of the mathematical theory that would make such a device possible.

The term has since been used by several other notable authors within the genre to describe communication devices that are capable of relaying messages over interstellar distances, which, as you will discover...

Ansible versus other tools

If you look at the design principles in the first commit compared to the current version, you will notice that while there have been some additions and tweaks, the core principles remain pretty much intact:

  • Agentless: Everything should be managed by the SSH daemon using the WinRM protocol in the case of Windows machines or API calls—there should be no reliance on custom agents or additional ports that need to be opened or interacted with on the target host. The machine running Ansible should need line of sight of the target resource network-wise.
  • Minimal: You should be able to manage new remote machines without installing any new software on the target host; each Linux target host will typically have at least SSH and Python installed as part of a minimal installation, which is all needed to run Ansible.
  • Descriptive: You should be able to describe your infrastructure, stack, or task in a language readable by machines and humans.
  • ...

My story: part two

Before we finish this part of the chapter, I would like to finish the story of my journey. As mentioned earlier in the chapter, I moved from my collection of scripts and runbooks to Puppet, which was great until my requirements moved away from managing just server configuration and maintaining the servers’ state.

I needed to start managing infrastructure in public clouds. This requirement quickly started to frustrate me when using Puppet. At the time, Puppet’s coverage of the APIs I needed to use for my infrastructure needed to be improved. I am assured it is a lot better now, but also, I found myself having to build too much logic into my manifests about the order in which each task was executed.

It was around this time, which was December 2014, that I decided to look at Ansible. I know the date because I wrote a blog post entitled First Steps With Ansible; I don’t think I have looked back since. I have since introduced several of my work...

Installing and running Ansible

Let’s dive straight in and install Ansible. Throughout this book, I will assume you are running a macOS host machine or a Linux machine with an Ubuntu LTS release. While we will cover running Ansible on Windows 11 using the Linux subsystem for Windows, this book will not support using Windows as a host machine.

Installing on macOS

You can install Ansible on your macOS host machine in a few different ways. I will cover both here. As we are discussing two different ways of installing Ansible, I recommend reading through this section and the Pros and cons subsection before choosing which installation method to use on your local machine.

Installing with Homebrew

The first installation method is to use a package manager called Homebrew.

Note

Homebrew is a package manager of macOS. It can be used to install command-line tools and desktop packages. It describes itself as “The missing package manager for macOS”, and it usually...

Launching a virtual machine

To launch a virtual machine to run our first set of Ansible commands against, we will use a tool called Multipass. This tool allows you to run Ubuntu virtual machines on your local host. It works with macOS, Linux, and Windows.

To install Multipass on macOS, we can use Homebrew and run the following command:

$ brew install multipass

To install on Ubuntu, you can run the following command:

$ snap install multipass

Finally, for Windows 11 users, you will have to first download and install the VirtualBox Windows executable from https://www.virtualbox.org/wiki/Downloads and then download and install Multipass from https://multipass.run/install. I recommend reading through the installation notes for Windows, which can be found at the following URL https://multipass.run/docs/installing-on-windows before installing.

Note

While you can run the same commands in Ubuntu running under Windows Subsystem for Linux, you will need to replace all references...

An introduction to playbooks

Typically, in IT, a playbook is a set of instructions run by someone when something happens; a little vague, I know, but stay with me. These range from building and configuring new server instances to deploying code updates and dealing with problems when they occur.

In the traditional sense, a playbook is typically a collection of scripts or instructions for a user to follow, and while they are meant to introduce consistency and conformity across systems, even with the best intentions, this is seldom the case.

This is where Ansible comes in. Using an Ansible playbook, you are telling it to apply these changes and commands against these sets of hosts rather than having to log in and start working your way through the playbook manually.

Before we run a playbook, let’s discuss how we provide Ansible with a list of hosts to target. To do this, we will be using the ansible.builtin.setup module. This connects to a host and then fetches as much...

Summary

In this chapter, we have taken our first steps with Ansible by installing it locally and then, using Vagrant, launching a virtual machine to interact with. We learned about basic host inventory files and used the Ansible command to execute a single task against our virtual machine.

We then looked at playbooks, starting with a basic playbook that returned some information on our target before progressing to a playbook that updates all the installed operating system packages before installing and configuring the NTP service.

By the end of the chapter, we had launched a second virtual machine and quickly brought it up to the same configuration level as our first virtual machine.

In the next chapter, we will look at Ansible Galaxy and discuss how Ansible packages up and maintains its community modules.

Further reading

In this chapter, we mentioned Puppet and SaltStack:

  • Puppet is a configuration management tool that runs a server/agent configuration. It comes in two flavors—an open source version and an enterprise version that Puppet, the company, supports. It is a declarative system and is closely tied to Ruby. For more information on Puppet, see https://www.puppet.com/.
  • SaltStack is another configuration management tool. It is highly scalable and, while it shares a design approach with Ansible, it works in a similar way to Puppet in that it has a server/agent approach. You can find more information on SaltStack at https://www.vmware.com/support/acquisitions/saltstack.html.
  • I also mentioned my personal blog, which you can find at https://www.russ.foo/.

We used the following Ansible modules, and you can find out more information on each module at the following links:

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Write roles to automate everything, from basic apps to the entire cloud infrastructure
  • Leverage Ansible's module ecosystem to streamline tasks across cloud platforms, operating systems, and apps
  • Adopt DevOps practices and integrate Ansible with CI/CD platforms to streamline automation workflows
  • Purchase of the print or Kindle book includes a free PDF eBook

Description

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.

Who is this book for?

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.

What you will learn

  • Understand how to install and configure Ansible on Linux, macOS, and Windows
  • Write Ansible playbooks to automate system configuration and deployment
  • Deploy applications such as LAMP stacks and WordPress using Ansible
  • Create reusable roles and use Ansible Galaxy for sharing
  • Automate infrastructure deployments on cloud platforms such as AWS and Azure
  • Execute your Ansible playbooks with GitHub Actions and Azure DevOps
  • Scan playbooks for security issues and secure systems using Ansible
  • Centralize and manage Ansible deployments using Ansible AWX

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : May 31, 2024
Length: 414 pages
Edition : 2nd
Language : English
ISBN-13 : 9781835082171
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : May 31, 2024
Length: 414 pages
Edition : 2nd
Language : English
ISBN-13 : 9781835082171
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 149.97
Learn Ansible
$44.99
Mastering Linux Administration
$49.99
The Ultimate Kali Linux Book
$54.99
Total $ 149.97 Stars icon
Banner background image

Table of Contents

23 Chapters
Part 1: Introducing, Installing, and Running Ansible Chevron down icon Chevron up icon
Chapter 1: Installing and Running Ansible Chevron down icon Chevron up icon
Chapter 2: Exploring Ansible Galaxy Chevron down icon Chevron up icon
Chapter 3: The Ansible Commands Chevron down icon Chevron up icon
Part 2: Deploying Applications Chevron down icon Chevron up icon
Chapter 4: Deploying a LAMP Stack Chevron down icon Chevron up icon
Chapter 5: Deploying WordPress Chevron down icon Chevron up icon
Chapter 6: Targeting Multiple Distributions Chevron down icon Chevron up icon
Chapter 7: Ansible Windows Modules Chevron down icon Chevron up icon
Part 3: Network and Cloud Automation Chevron down icon Chevron up icon
Chapter 8: Ansible Network Modules Chevron down icon Chevron up icon
Chapter 9: Moving to the Cloud Chevron down icon Chevron up icon
Chapter 10: Building Out a Cloud Network Chevron down icon Chevron up icon
Chapter 11: Highly Available Cloud Deployments Chevron down icon Chevron up icon
Chapter 12: Building Out a VMware Deployment Chevron down icon Chevron up icon
Part 4: Ansible Workflows Chevron down icon Chevron up icon
Chapter 13: Scanning Your Ansible Playbooks Chevron down icon Chevron up icon
Chapter 14: Hardening Your Servers Using Ansible Chevron down icon Chevron up icon
Chapter 15: Using Ansible with GitHub Actions and Azure DevOps Chevron down icon Chevron up icon
Chapter 16: Introducing Ansible AWX and Red Hat Ansible Automation Platform Chevron down icon Chevron up icon
Chapter 17: Next Steps with Ansible Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(3 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Teja Sep 13, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
"Learn Ansible" is an excellent resource for beginners and intermediate users looking to enhance their Ansible skills. Covering everything from basics to advanced topics with practical examples and over 200 automation scenarios, it provides hands-on tutorials and a GitHub repository for easy application. This book is a must-read for anyone aiming to improve their automation capabilities and streamline workflows.
Amazon Verified review Amazon
Boondock Saint Oct 08, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
It covered how ansible is used on multiple platforms and cloud technologies.Explained from beginner level to advanced level.Great book
Amazon Verified review Amazon
Sridevi Sep 09, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Well organized chapters with great contents for anyone who wants to learn Ansible.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.