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
€8.99 €26.99
Paperback
€33.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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

Shipping Address

Billing Address

Shipping Methods
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
Estimated delivery fee Deliver to Luxembourg

Premium delivery 7 - 10 business days

€17.95
(Includes tracking information)

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 Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Luxembourg

Premium delivery 7 - 10 business days

€17.95
(Includes tracking information)

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
€18.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
€189.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
€264.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 113.97
Learn Ansible
€33.99
Mastering Linux Administration
€37.99
The Ultimate Kali Linux Book
€41.99
Total 113.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

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela