Microservices
Total Page:16
File Type:pdf, Size:1020Kb
Implementing DevOps with Ansible 2 Build, develop, test, deploy, and monitor in seconds Jonathan McAllister BIRMINGHAM - MUMBAI Implementing DevOps with Ansible 2 Copyright © 2017 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: July 2017 Production reference: 1200717 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78712-053-2 www.packtpub.com Credits Author Copy Editors Jonathan McAllister Madhusudan Uchil Stuti Srivastava Reviewer Project Coordinator Matthew Fisher Virginia Dias Acquisition Editor Proofreader Meeta Rajani Safis Editing Content Development Editor Indexer Sharon Raj Aishwarya Gangawane Technical Editor Graphics Vishal Kamal Mewada Kirk D'Penha Production Coordinator Aparna Bhagat About the Author Jonathan McAllister has been creating software and automations since he was a child. As an avid computer technologist, he has had 13 years of professional experience in software development, testing, and delivery practices. During his career, he has architected and implemented software build, testing, and delivery solutions for cutting-edge technology organizations across diverse technology stacks. Jonathan has most recently been focusing on build pipelines, Continuous Integration, Continuous Delivery, microservice architecture, standardized processes, Agile and Kanban, and the implementation of highly scalable automation solutions. He has worked and consulted for some of the industry's most notable companies, including Microsoft, Merck, Logitech, and Oracle. His focus is entirely on designing scalable software build, delivery, and testing pipelines in an effort to streamline releases through standardization and help develop strategies that can elevate revenue through modern continuous practices. Acknowledgments This book wouldn't have been possible if it hadn't been for the support of my family, friends, previous managers and co-workers. I'd like to thank the following people for their love and support in writing this: Family and friends: Stephanie Kellogg – My wife and best friend. Renae Pittman – My sister and one of the only people I let yell at me. Adrian McAllister – My son. Richard Vasquez – My father. Caden McAllister – My son. Trisiann Vasquez – My aunt. Devin McAllister – My son. Toni Null – My mother. Kailey McAllister – My dearest princess. Carla Muniz – My Tia. Bryce McAllister – My son. Lauren Jones – She's stuck by me for I don't know how many years. Amazing mother and friend. Co-workers and management: Chris Hemphill – First taught me the constructs of SCM and Continuous Delivery. David Mueller – One of the best working leaders I've ever met. Shane McDougal – The sharpest Agile guru on the planet. Arsalan Baig – The most amazing designer I've ever met. Jonathan Krautter – Security excellence and overall security GOD! Charles Williams – One of the first people to mentor me and amazing human. "Let's work to make the world a better place to be. A unified world where we can see that love is the magic that sets us free" – Jonathan McAllister About the Reviewer Matthew Fisher has worked as a software developer for over 17 years in roles ranging from the Unix kernel to mobile phone development to DevOps. Matt has a passion for IT transformation projects—especially automation, self-service infrastructure, and the cloud. Matt was a contributing author on Common OpenStack Deployments: Real-World Examples for Systems Administrators and Engineers and has given many presentations on automating IT and deploying OpenStack. When not doing cool DevOps stuff, Matt enjoys hiking, camping, skiing, craft beer, and spending time with his family in Fort Collins, Colorado. www.PacktPub.com For support files and downloads related to your book, please visit www.PacktPub.com. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.comand as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. h t t p s ://w w w . p a c k t p u b . c o m /m a p t Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career. Why subscribe? Fully searchable across every book published by Packt Copy and paste, print, and bookmark content On demand and accessible via a web browser Customer Feedback Thanks for purchasing this Packt book. At Packt, quality is at the heart of our editorial process. To help us improve, please leave us an honest review on this book's Amazon page at h t t p s ://w w w . a m a z o n . c o m /d p /1787120538. If you'd like to join our team of regular reviewers, you can e-mail us at [email protected]. We award our regular reviewers with free eBooks and videos in exchange for their valuable feedback. Help us be relentless in improving our products! Table of Contents Preface 1 Chapter 1: DevOps Fundamentals 7 DevOps 101 8 Culture 9 Automation 9 Measurement 9 Sharing 10 The History of DevOps 10 Strides toward the future 13 DevOps in the Modern Software Organization 14 The DevOps assembly line 15 Correlations between a DevOps assembly line and manufacturing 16 DevOps architectures and practices 16 Encapsulated software development 17 Microservices 17 Continuous Integration and Continuous Delivery 19 Modularity 23 Horizontal scalability 24 Blue-green deployments 24 Artifact management and versioning 25 Symmetrical environments 26 Summary 26 Chapter 2: Configuration Management Essentials 28 Understanding Configuration Management 29 Origins of Configuration Management 31 The Aims of Configuration Management 32 Scenario 1 33 Scenario 2 33 Scenario 3 33 Scenario 4 33 Basic Principles of Configuration Management 34 Configuration Management Best Practices 35 How Ansible Simplifies DevOps Implementations 37 Binary Artifact Management and Ansible 40 Summary 42 Chapter 3: Installing, Configuring, and Running Ansible 43 Installing Ansible 44 Red Hat Enterprise Linux via Configuration Management 44 Apt for Debian/Apt for Ubuntu 45 Porting Ansible to Gentoo 45 PKG for FreeBSD 45 Pip for macOS 45 OpenCSW for Solaris/SunOS 46 Via Python pip 46 Once Ansible has been installed 46 Setting up authentication between the control server and hosts 47 The Ansible Architecture 47 Open source 48 Module-based 48 Agentless 49 Pluggable 49 Local automation execution using Ansible 49 Remote automation execution using Ansible 52 Container-oriented automation 55 The Ansible Command-Line Interface 57 Usage: ansible [options] 58 Ansible command-line examples 59 Configuring Ansible 60 Common base configuration items 61 The Ansible Inventory 62 Defined inventory groups 62 Loose inventory items/hosts/devices 63 Executing playbook's and targeting specific inventory files and groups 64 Summary 64 Chapter 4: Playbooks and Inventory Files 65 Ansible Playbook Constructs 66 The programming languages that make up a playbook 67 YAML 67 Jinja2 – a brief introduction 68 Constructing an Ansible playbook 69 Hosts 69 Variables (vars/vars_files) 70 Tasks/plays 70 [ ii ] Ansible Play's and Task's 70 Ansible plays 70 Ansible tasks 71 Multiline task parameters 72 Variables and Variable Files 74 Basic variable syntax 74 Variable files 75 Hosts and Inventory 77 Targeting Infrastructure 78 Ansible Modules 80 Managing packages in Ansible 83 Yum 83 The apt-get and dpkg 84 Managing users in Ansible 87 File and directory management in Ansible 87 Managing services in Ansible 88 Transferring files in Ansible 90 Summary 91 Chapter 5: Playbooks – Beyond the Fundamentals 92 playbook's and Conditional Logic 93 Iterators and Loops 96 Basic loops using with_items 97 Nested loops using with_nested 98 Looping over hashes using with_dict 99 Iterating over files using with_file 102 Iterating over sequential numbers 103 The do until iterator 104 Iterating over inventory hosts using play_hosts 105 Includes 106 Play-level includes 107 Task-level includes 108 Dynamic includes 109 Ansible Roles 110 Ansible Register Variables 113 Simple Ansible registers 114 Accessing registers 114 Additional conditional logic with registers 115 Null or empty comparisons 115 Vars and Ansible registers 115 Iterating over register contents 116 [ iii ] Ansible Handlers 116 Summary 118 Chapter 6: Jinja in Ansible 119 Introducing Jinja 120 Jinja2 Programming Constructs