Book Image

DevOps Automation Cookbook

By : Michael Duffy
Book Image

DevOps Automation Cookbook

By: Michael Duffy

Overview of this book

<p>There has been a recent explosion in tools that allow you to redefine the delivery of infrastructure and applications, using a combination of automation and testing to deliver continuous deployment. DevOps has garnered interest from every quarter, and is rapidly being recognized as a radical shift, as large as the Agile movement for the delivery of software.</p> <p>This book takes a collection of some of the coolest software available today and shows you how to use it to create impressive changes to the way you deliver applications and software. It tackles the plethora of tools that are now available to enable organizations to take advantage of the automation, monitoring, and configuration management techniques that define a DevOps-driven infrastructure.</p> <p>Starting off with the fundamental command-line tools that every DevOps enthusiast must know, this book will guide you through the implementation of the Ansible tool to help you facilitate automation and perform diverse tasks. You will explore how to build hosts automatically with the creation of Apt mirrors and interactive pre-seeds, which are of the utmost importance for Ubuntu automation. You will also delve into the concept of virtualization and creating and manipulating guests with ESXi. Following this, you will venture into the application of Docker; learn how to install, run, network, and restore Docker containers; and also learn how to build containers in Jenkins and deploy apps using a combination of Ansible, Docker, and Jenkins. You will also discover how to filter data with Grafana and the usage of InfluxDB along with unconventional log management. Finally, you will get acquainted with cloud infrastructure, employing the Heroku and Amazon AWS platforms.</p> <p>By tackling real-world issues, this book will guide you through a huge variety of tools, giving new users the ability to get up and running and offering advanced users some interesting recipes that may help with existing issues.</p>
Table of Contents (19 chapters)
DevOps Automation Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Restarting services using Ansible


Now that we have defined our inventory, we are ready to use Ansible to perform actions. Arguably, one of the most important adhoc actions you can take is to restart services on target nodes. At first, this might seem a bit of an overkill compared to simply logging on to the server and doing it, but when you realize that this action can be scaled anywhere from one to one million servers, its power becomes apparent.

Getting ready

You'll need an inventory file before you try this, so if you have not got it already, go ahead and set one up. The following examples are based on the inventory set out in the preceding recipe, so you'll need to change the examples to match your environments.

How to do it…

To restart a service, we can use the Ansible service module. This supports various activities such as starting, stopping, and restarting services:

  • For example, issue the following command to restart MySQL:

    ansible mysql -m service -a "name=mysql state=restarted"
    
  • You...