Shaun R Smith
Hong Kong, New Territories, Hong Kong
Peter Membrey
Kowloon, Hong Kong
ISBN 978-1-4842-8172-7 e-ISBN 978-1-4842-8173-4
https://doi.org/10.1007/978-1-4842-8173-4
Shaun R Smith and Peter Membrey 2022
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.
The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use.
The publisher, the authors and the editors are safe to assume that the advice and information in this book are believed to be true and accurate at the date of publication. Neither the publisher nor the authors or the editors give a warranty, expressed or implied, with respect to the material contained herein or for any errors or omissions that may have been made. The publisher remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
This Apress imprint is published by the registered company APress Media, LLC part of Springer Nature.
The registered company address is: 1 New York Plaza, New York, NY 10004, U.S.A.
Introduction
This book is our attempt to help those who are new to the challenge of managing multiple servers and distributed applications. Most of us start off quite happily with a VM or two, and with a bit of help from Google, we manage to get things up and running. Usually, that means things are tweaked by hand with a little trial and error, but eventually all is well, and we are in production.
It may not happen right away, and it might not happen for a year, but at some point, sooner or later, something is going to go badly wrong, and youre going to have a crisis on your hands. Perhaps, youve already experienced the joy of sitting alone in the office at 4 a.m. with a stale cup of coffee (that sounds bad, but it beats being in a freezing cold server room), and thats why youve picked up this book. Perhaps, youve heard the horror stories and are adamant that you dont want any part of that. Or perhaps you think there just has to be a better way than doing this all by hand or writing lots of custom complicated scripts. Youd be right
In this book, we will show you how to use Ansible to be able to build and manage servers and services in a simple and effective way. We will help you build your skills by introducing you to new techniques in each chapter that build on what youve learned before. This approach helps to make you immediately productive in the real world while still being able to explore and understand more complicated topics.
What Is Ansible?
At its heart, Ansible is a configuration management tool. These tools are now ubiquitous in modern computing environments, but although they actually had their beginnings in the 1950s at the US Department of Defense, it has taken a long time for them to be applied to computing environments. Until quite recently, configuration management was a rather manual process of checks and balances, with strict change management controls. These days, weve moved a few layers beyond this, where we describe the end state we require and allow the tools to figure out the best way to make that happen.
And this is where Ansible shines. Whether youre managing a single VM hosted in the cloud or 10,000 devices spread across the globe in physical data centers, Ansible can do it all.
Written in Python, with extensibility in mind, Ansible started with a few core modules for managing and configuring Linux servers. Thanks to the foresight and ingenuity of the developers, it has grown into a huge ecosystem capable of managing almost any system under the sun from Linux and Windows servers, to routers and switches, to OpenShift and AWS services, and much much more. All with the same familiar syntax and ease of use youll come to expect through your journey learning this amazingly flexible tool.
Having Ansible knowledge in your arsenal is more than just a nice to have. Its a critical skill on any developers resume. It enables you to talk about various complex topics such as idempotence and declarative configuration, which well get into in the following chapters. It means youre able to automate your infrastructure and build it repeatedly. Many businesses, small and large alike, use Ansible in some way thanks to its simple syntax and the ability for it to be run from anywhere to anywhere without much overhead.
Unlike more traditional configuration management tools, which rely on constant communication between the controller and the hosts, Ansible does not. It can be run once only, or every day, by an individual, automation, or even many people on a team it will always bring your hosts in line with the latest configuration. Whats more, Ansible does not require the installation of a special piece of software called an Agent on the host that is being configured. This is a huge win for Ansible, since it enables the management of otherwise manually managed devices such as routers, switches, firewalls, and load balancers. It is also a huge win for those operating in a secure environment, where an Agent may introduce a new threat vector to their infrastructure. Ansible is different. It connects to hosts using the ubiquitous SSH, which in most cases will have already been locked down and closely monitored by any good security policy.
But Why Ansible?
Thats a fair question. After all, Ansible is certainly not alone in the world of configuration management and administration. It is however one of the simplest tools out there. It has very minimal requirements on the target nodes in terms of requirements to run, and doesnt require an actual presence on the machine itself. This combined with the power that we can leverage from existing modules, custom inventories, and fact discovery (all things we cover later in the book), it really is a compelling choice for the needs of most people who need to get up and running quickly but have the room to expand.
Sounds Great What Do We Cover?
Although this book is meant as a hands-on introduction to Ansible, we have taken a slightly different approach by building your skills up layer by layer and covering all the things we wished we knew when we were first navigating Ansible ourselves. Heres what weve got in store for you.
Chapter : Getting Setup and Running
As the title suggests, this chapter is all about getting you up and running with Ansible so that you can follow the exercises and examples throughout the rest of the book. We provide setup instructions for Linux, Windows, and Mac and briefly introduce Vagrant, an infrastructure tool that well use to build your Ansible environment.