Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Learn Ansible
Learn Ansible

Learn Ansible: Automate cloud, security, and network infrastructure using Ansible 2.x

eBook
$29.99 $43.99
Paperback
$54.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
Table of content icon View table of contents Preview book icon Preview Book

Learn Ansible

Installing and Running Ansible

Now that we know a little about the background of Ansible, we will work on installing it and, once installed, we will run our first set of playbooks against a test virtual machine running CentOS 7.

The following topics will be covered in this chapter:

  • How to install Ansible on macOS and Linux
  • Running Ansible on Windows 10 Professional using the Linux subsystem
  • Launching a test virtual machine
  • An introduction to playbooks

Technical requirements

In this chapter, we will be installing Ansible, so you will need a machine capable of running it. I will go into more details about these requirements in the next part of the chapter. We will also be using Vagrant to launch a virtual machine locally. There is a section that walks through installing Vagrant as well as downloading a CentOS 7 Vagrant box, which is around 400 MB.

You can find complete versions of all of the playbooks in the GitHub repository that accompanies this book at https://github.com/PacktPublishing/Learn-Ansible/tree/master/Chapter02.

You can also find the code bundle in author's repository: https://github.com/russmckendrick/learn-ansible-fundamentals-of-ansible-2x.

Installing Ansible

Let's dive straight in and install Ansible. Throughout this book, I will be assuming that you are running a macOS host machine running macOS High Sierra or a Linux machine with Ubuntu 18.04 LTS installed. While we will cover running Ansible on Windows 10 Professional using the Linux subsystem for Windows, using Windows as a host machine will not be supported in this book.

Installing on macOS

There are a few different ways you can install Ansible on your macOS High Sierra host machine. I will cover them both.

As we are discussing two different ways of installing Ansible, I would recommend reading through this section and also the Pros and cons section at the end before choosing which installation method...

Launching a virtual machine

In order to launch a virtual machine to run our first set of Ansible commands against, we are going to use Vagrant.

Please note that these instructions may not work if you are running WSL.

Vagrant is a virtual machine manager developed by HashiCorp. It can manage both local and remote virtual machines, and supports hypervisors, such as VirtualBox, VMware, and Hyper-V.

To install Vagrant on macOS, we can use Homebrew along with cask. To install cask, run the following command:

$ brew install cask
VirtualBox is an open source hypervisor for x86-based computers. It is currently being developed by Oracle and supports both software- and hardware-based virtualization.

By default, Vagrant uses VirtualBox. Once cask is installed, you can use VirtualBox and Vagrant by running the following command:

$ brew cask install virtualbox vagrant

To install on Ubuntu...

An introduction to playbooks

Normally 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 everything to building and configuring new server instances, to how to deploy code updates and how to deal 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 almost never the case.

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

Before we run a playbook, let's discuss how we provide Ansible with a list...

Summary

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

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

In the next chapter, we are going to take a look at other Ansible commands we can use.

Questions

  1. What is the command to install Ansible using pip?
  2. True or false: You can choose exactly which version of Ansible to install or roll back to when using Homebrew.
  3. True or false: The Windows Subsystem for Linux runs in a virtual machine.
  4. Name three hypervisors that are supported by Vagrant.
  5. State and explain what a host inventory is.
  6. True or false: Indentation in YAML files is extremely important to their execution and isn't just cosmetic.
  7. Update the final playbook to install a service of your choice and have it notify a handler to start the service with its default configuration.

Further reading

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Build your learning curve using Ansible
  • Automate cloud, network, and security infrastructures with ease
  • Gain hands-on exposure on Ansible

Description

Ansible has grown from a small, open source orchestration tool to a full-blown orchestration and configuration management tool owned by Red Hat. Its powerful core modules cover a wide range of infrastructures, including on-premises systems and public clouds, operating systems, devices, and services—meaning it can be used to manage pretty much your entire end-to-end environment. Trends and surveys say that Ansible is the first choice of tool among system administrators as it is so easy to use. This end-to-end, practical guide will take you on a learning curve from beginner to pro. You'll start by installing and configuring the Ansible to perform various automation tasks. Then, we'll dive deep into the various facets of infrastructure, such as cloud, compute and network infrastructure along with security. By the end of this book, you'll have an end-to-end understanding of Ansible and how you can apply it to your own environments.

Who is this book for?

Learn Ansible is perfect for system administrators and developers who want to take their current workflows and transform them into repeatable playbooks using Ansible. No prior knowledge of Ansible is required.

What you will learn

  • Write your own playbooks to configure servers running CentOS, Ubuntu, and Windows
  • Identify repeatable tasks and write playbooks to automate them
  • Define a highly available public cloud infrastructure in code, making it easy to distribute your infrastructure configuration
  • Deploy and configure Ansible Tower and Ansible AWX
  • Learn to use community contributed roles
  • Use Ansible in your day-to-day role and projects

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 28, 2018
Length: 578 pages
Edition : 1st
Language : English
ISBN-13 : 9781788999328
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

Product Details

Publication date : Jun 28, 2018
Length: 578 pages
Edition : 1st
Language : English
ISBN-13 : 9781788999328
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 $ 131.97
Hands-On Enterprise Automation with Python
$43.99
Learn Ansible
$54.99
Ansible Quick Start Guide
$32.99
Total $ 131.97 Stars icon

Table of Contents

19 Chapters
An Introduction to Ansible Chevron down icon Chevron up icon
Installing and Running Ansible Chevron down icon Chevron up icon
The Ansible Commands Chevron down icon Chevron up icon
Deploying a LAMP Stack Chevron down icon Chevron up icon
Deploying WordPress Chevron down icon Chevron up icon
Targeting Multiple Distributions Chevron down icon Chevron up icon
The Core Network Modules Chevron down icon Chevron up icon
Moving to the Cloud Chevron down icon Chevron up icon
Building Out a Cloud Network Chevron down icon Chevron up icon
Highly Available Cloud Deployments Chevron down icon Chevron up icon
Building Out a VMware Deployment Chevron down icon Chevron up icon
Ansible Windows Modules Chevron down icon Chevron up icon
Hardening Your Servers Using Ansible and OpenSCAP Chevron down icon Chevron up icon
Deploying WPScan and OWASP ZAP Chevron down icon Chevron up icon
Introducing Ansible Tower and Ansible AWX Chevron down icon Chevron up icon
Ansible Galaxy Chevron down icon Chevron up icon
Next Steps with Ansible Chevron down icon Chevron up icon
Assessments 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 Half star icon 4.5
(4 Ratings)
5 star 75%
4 star 0%
3 star 25%
2 star 0%
1 star 0%
Erik J. Schott May 17, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I used this product as part of a Proof Of Concept for work.
Amazon Verified review Amazon
Domenico Gagliano Jul 06, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I just started reading this book and so far it uses a clear language and doesn't make many assumption.I am enjoying it so far!
Amazon Verified review Amazon
Daniel Haskin Nov 09, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Ansible has changed dramatically in the last few years, expanding from an excellent configuration managment tool to include orchestration -- spinning up VMs, creating networks, etc. This book reflects this change.This is a no-nonsense guide on the "new" ansible. It was written by someone with lots of sysadmin experience and it's a great guide to get from 0 to 60 with ansible, even if you have no coding experience.By going through a solid example (LAMP stack) and taking it through to the cloud, then back to VMware, I'm learning idiomatic ansible and I'm feeling like I'm getting a strong foundation in it.
Amazon Verified review Amazon
SirM Feb 19, 2019
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
For somoeone new to automation using Ansible I would advice patience by getting the basics in place from online tutorials and free courses from other sites as this book is more like a guide on how to fly an airplane using autopilot. If you weigh a book by it's page count you'll be deceived as the content is more of the fill-in-the gaps kind of material. Also this is a kind of book that you'll read part time as some sections are only relavant if you have access to cloud service providers that are included within.
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.