Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
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

Arrow left icon
Profile Icon Russ McKendrick
Arrow right icon
Free Trial
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (3 Ratings)
Paperback May 2024 414 pages 2nd Edition
eBook
Mex$516.99 Mex$738.99
Paperback
Mex$922.99
Subscription
Free Trial
Arrow left icon
Profile Icon Russ McKendrick
Arrow right icon
Free Trial
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (3 Ratings)
Paperback May 2024 414 pages 2nd Edition
eBook
Mex$516.99 Mex$738.99
Paperback
Mex$922.99
Subscription
Free Trial
eBook
Mex$516.99 Mex$738.99
Paperback
Mex$922.99
Subscription
Free Trial

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781835088913
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : May 31, 2024
Length: 414 pages
Edition : 2nd
Language : English
ISBN-13 : 9781835088913
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 Mex$85 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 Mex$85 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total Mex$ 3,077.97
Learn Ansible
Mex$922.99
Mastering Linux Administration
Mex$1025.99
The Ultimate Kali Linux Book
Mex$1128.99
Total Mex$ 3,077.97 Stars icon

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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.