Book Image

Implementing DevOps with Ansible 2

By : Jonathan McAllister
Book Image

Implementing DevOps with Ansible 2

By: Jonathan McAllister

Overview of this book

Thinking about adapting the DevOps culture for your organization using a very simple, yet powerful automation tool, Ansible 2? Then this book is for you! In this book, you will start with the role of Ansible in the DevOps module, which covers fundamental DevOps practices and how Ansible is leveraged by DevOps organizations to implement consistent and simplified configuration management and deployment. You will then move on to the next module, Ansible with DevOps, where you will understand Ansible fundamentals and how Ansible Playbooks can be used for simple configuration management and deployment tasks. After simpler tasks, you will move on to the third module, Ansible Syntax and Playbook Development, where you will learn advanced configuration management implementations, and use Ansible Vault to secure top-secret information in your organization. In this module, you will also learn about popular DevOps tools and the support that Ansible provides for them (MYSQL, NGINX, APACHE and so on). The last module, Scaling Ansible for the enterprise, is where you will integrate Ansible with CI and CD solutions and provision Docker containers using Ansible. By the end of the book you will have learned to use Ansible to leverage your DevOps tasks.
Table of Contents (20 chapters)
Title Page
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Preface

Ansible has taken the DevOps world by storm. Its highly scalable architecture and modular implementation have made it an ideal tool for implementing DevOps solutions at organizations large and small. Implementing DevOps with Ansible 2 will provide detailed tutorials and information on how to implement DevOps solutions at your organization.Implementing DevOps with Ansible 2 aims to help encourage good software development and delivery practices within organizations by educating you on both the practical technology side of DevOps implementations as well as the cultural and collaborative implementations.Throughout the course of this book, we walk through many examples and solutions for common DevOps implementation shortcomings and automation requirements. The book walks you step by step through the implementation of solutions using examples that are easy to read and follow and simple to understand.As the author of Implementing DevOps with Ansible 2, it is my sincerest hope that this book helps you in your quest to become more DevOps and Ansible proficient. As such, I have set up a website to help readers further their knowledge and reach out to me for any questions. The URL is http://www.ansibledevops.com.

What this book covers

Chapter 1, DevOps Fundamentals, introduces you to DevOps (a hybrid word connecting development and operations) and educates you on the DevOps movement and how DevOps has in recent years revolutionized software development and delivery at organizations around the globe.

Chapter 2, Configuration Management Essentials, will teach you how tools like Ansible can make developers, testers, and operations work easier by eliminating environment drift, automating the provisioning of infrastructure, and providing an easy and consistent way to spin up bug reproduction environments.

Chapter 3, Installing, Configuring, and Running Ansible, will educate you on where to get Ansible, how to install and set up a control server, how to authorize the control server with inventory items and how to use the Ansible command line to run a playbook or query an infrastructure group. Finally, the chapter will educate you on the core module set and how this provide an interactive interface to other technologies (Git, JIRA, Jenkins, and so on).

Chapter 4, Playbooks and Inventory Files, will further your knowledge on playbooks, playbook trees, roles, tasks, and inventory files. In this chapter, the reader will see some basic examples of simple playbooks and learn some of the various ways to run them.

Chapter 5, Playbooks: Beyond the Fundamentals, will help you learn the syntax requirements of the YAML markup language. Additionally, the chapter will educate you on the Ansible specific syntax for roles, includes, variables, loops, blocks, conditionals, registers, and facts.

Chapter 6, Jinja in Ansible, will dive into Jinja2 templating and how to make use of it in Ansible.

Chapter 7, Ansible Vault, will outline the Ansible way of managing and deploying sensitive information and how to best leverage the Ansible Vault utility to ensure sensitive data is kept secret. You will learn (by example) how to best control and manage highly secure information and learn the underpinnings of how Ansible keeps your information secure.

Chapter 8, Ansible Modules and Libraries, will focus on the wide array of modules provided by the Ansible solution. Modules in Ansible provide the ability for playbooks to connect to and control third party technologies (some open source, some closed source). In this chapter, we will discuss the most popular ones and dive into creating playbook tasks that help manage a suite of tools and services available to developers, testers, and operators.

Chapter 9, Integrating Ansible with CI and CD Solutions, we will teach you how to leverage other DevOps related tools to control Ansible. The specific topics covered will be Jenkins and TeamCity. The reader will learn how Ansible can be leveraged as a post build action, how Ansible fits into a Continuous Integration and Continuous Delivery pipeline, and some examples for each.

Chapter 10, Ansible and Docker, we will educate you on how to use Python to extend Ansible and create custom modules that integrate with unique specific technology stacks. This will be done by providing a set of tutorials that teach the reader to write and release custom Ansible modules. The chapter will teach you how to read input, manage facts, perform automated tasks, interact with REST APIs and generate documentation.

Chapter 11, Extending Ansible, will help you learn the popular features of both Galaxy and Tower and how to use and configure both. Upon completing this chapter, you will have the knowledge needed to act as an authority in your organization for both of the unique and vibrant technologies.

Chapter 12, Ansible Galaxy, will teach how to provision Docker containers using Ansible, how to integrate Ansible with Docker's service, how to manage Docker image facts, and how to gain full control over Docker images.

What you need for this book

This book was written with Ubuntu used for the control server and SSH access to target servers. As such you will need an Ubuntu machine or VM to use the tutorials within this book. For the module and plugin creation chapter you will need Python on the Ubuntu system.

Who this book is for

This book is for anyone who is curious about DevOps implementations and how to leverage Ansible to create automated solutions.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning. Code words in the text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "If SSH key sharing is not available Ansible also offers the option to ask for a password using the --ask-become-pass command-line argument."

A block of code is set as follows:

# File name: hellodevopsworld.yml
---
- hosts: all
 tasks:
 - shell: echo "hello DevOps world"

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

[databaseservers]
mydbserver105.example.org
mydbserver205.example.org
[webservers]
mywbserver105.example.org
mywbserver205.example.org

Any command-line input or output is written as follows:

$ sudo apt-get install software-properties-common
$ sudo apt-add-repository ppa:ansible/ansible
$ sudo apt-get update
$ sudo apt-get install ansible

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "To install the Ansible plugin. simply navigate to Plugin Manager (as a Jenkins administrator) and select Ansible plugin from the Available plugins tab and install the plugin."

Note

Warnings or important notes appear in a box like this.

Note

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply email [email protected], and mention the book's title in the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you. You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.
  2. Hover the mouse pointer on the SUPPORT tab at the top.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box.
  5. Select the book for which you're looking to download the code files.
  6. Choose from the drop-down menu where you purchased this book from.
  7. Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows
  • Zipeg / iZip / UnRarX for Mac
  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Implementing-DevOps-with-Ansible-2. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/ImplementingDevOpswithAnsible2_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title. To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy. Please contact us at [email protected] with a link to the suspected pirated material. We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.