ebook img

Practical Ansible: Configuration Management from Start to Finish PDF

276 Pages·2021·3.015 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Practical Ansible: Configuration Management from Start to Finish

Practical Ansible Configuration Management from Start to Finish — Vincent Sesto Practical Ansible Configuration Management from Start to Finish Vincent Sesto Practical Ansible: Configuration Management from Start to Finish Vincent Sesto Auckland, New Zealand ISBN-13 (pbk): 978-1-4842-6484-3 ISBN-13 (electronic): 978-1-4842-6485-0 https://doi.org/10.1007/978-1-4842-6485-0 Copyright © 2021 by Vincent Sesto 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. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Aditee Mirashi Development Editor: Matthew Moodie Coordinating Editor: Aditee Mirashi Cover designed by eStudioCalamar Cover image designed by Freepik (www.freepik.com) Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 New York Plaza, Suite 4600, New York, NY 10004-1562, USA. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail [email protected]; for reprint, paperback, or audio rights, please e-mail [email protected]. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the book’s product page, located at www.apress.com/ 978-1-4842-6484-3. For more detailed information, please visit http://www.apress.com/ source-code. Printed on acid-free paper This book is dedicated to Kirsty and our two cats Tim Tam and Rusty. Thanks for always keeping me company while I’m writing and generally helping me get the most out of life. Table of Contents About the Author ���������������������������������������������������������������������������������ix About the Technical Reviewer �������������������������������������������������������������xi Preface ����������������������������������������������������������������������������������������������xiii Introduction ��������������������������������������������������������������������������������������xvii Chapter 1: Configuration Management with Ansible ����������������������������1 Getting Started with Configuration Management2 Why Ansible? 3 Getting Started with Ansible 6 Installing Ansible 7 Ansible Support for SSH 9 Finally, Our First Ansible Command 12 Basic Ansible Playbooks 13 Ansible Configuration and Inventory Files 16 Running Ansible Modules 20 Ping 20 Setup 21 Git 22 Shell23 Apt (or Yum) 24 Service 25 get_url 26 v Table of ConTenTs file27 user 28 find 29 Running Ansible on Different Servers 30 Different Versions of Ansible 32 Ansible Projects 32 Basic LAMP Stack 32 Splunk Server Environment 33 Summary34 Chapter 2: Ansible Playbooks �������������������������������������������������������������35 Ansible and YAML Syntax 36 Command-Line Modules to Ansible Playbooks 39 Ansible Playbook Verbose Output 46 Ansible Syntax in Finer Detail 47 Hosts and Remote Users 47 Tasks 49 Notify 50 Adding More Playbook Functionality with Variables and Loops 51 Plugging In Our LAMP Stack 58 Organizing Larger Playbooks with Include and Import 66 Summary69 Chapter 3: Extending Playbooks with Roles and Templates ���������������71 Ansible Roles 72 Creating the Web Server Role 73 Creating the Database Server Role 80 Ansible Command-Line Variables and Options 84 vi Table of ConTenTs Expanding Our LAMP with Django 85 Conditional Tasks in Ansible 94 Using Tags to Run Specific Tasks 97 Summary101 Chapter 4: Custom Ansible Modules, Vaults, and Galaxies ���������������103 Keeping Secret with Ansible Vault 104 Ansible Galaxy 110 Searching and Working with Ansible Galaxy Roles 111 Downloading and Installing Multiple Roles from Galaxy 120 Moving Further with Ansible Galaxy 123 Contributing to Ansible Galaxy 127 Building Your Own Ansible Modules 135 Summary142 Chapter 5: Working with Ansible in the Amazon Cloud ��������������������143 So Why Amazon Web Services 144 AWS Is Not Free 145 AWS Pricing 145 Gaining Access to AWS145 Using Environment Variables to Access AWS 153 Ansible AWS Modules to Implement Our New Project 153 Our New Splunk Implementation Project 154 Creating Our AWS Instance 159 Deploying Splunk with User Data 170 Failures on Amazon Web Services 176 Summary178 vii Table of ConTenTs Chapter 6: Ansible Templates and CloudFormation Scripts �������������179 One Final Word on AWS Costs 180 Ansible Templates in AWS Instances 181 Pulling Code with Ansible189 Ansible Pull GitHub Repository Deployment Explained 195 Build AWS Images for Quicker Deployments 196 Using CloudFormation with Ansible 203 Summary213 Chapter 7: Ansible Tests and Variables ��������������������������������������������215 AWS Modules Run Differently 216 Using the Debug Module with Registered Variables 218 Ansible Facts 224 Testing Ansible As You Develop 228 Ansible Start At Option 229 Ansible Step 230 Ansible Lint 231 List Ansible Tasks 239 Ansible Check Mode 240 Ansible Playbook Syntax Check 243 Ansible Testing with Molecule244 Summary257 Index �������������������������������������������������������������������������������������������������259 viii About the Author Vincent Sesto is a DevOps engineer, endurance athlete, and author. As a DevOps engineer, he specializes working with Linux and open source applications. He is particularly interested in helping people get more from the tools they have and is currently developing his skills in DevOps, continuous integration, security, Splunk (UI and Reporting), and Python development. ix About the Technical Reviewer Lamodar Ray is an IT professional in the United States. He is a database specialist with focused expertise in Amazon Cloud services and Oracle Cloud Infrastructure. He has worked in delivering database and infrastructure solutions in diverse industry and business domains including workforce management, finance, procurement , manufacturing , sales, and compensation. He is also a Certified Oracle Cloud Architect Professional and Amazon AWS Architect Associate. xi

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.