logo资料库

Mastering Ansible - Second Edition.pdf

第1页 / 共303页
第2页 / 共303页
第3页 / 共303页
第4页 / 共303页
第5页 / 共303页
第6页 / 共303页
第7页 / 共303页
第8页 / 共303页
资料共303页,剩余部分请下载后查看
Cover
Copyright
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Table of Contents
Preface
Chapter 1: System Architecture and Design of Ansible
Ansible version and configuration
Inventory parsing and data sources
Static inventory
Inventory variable data
Dynamic inventories
Runtime inventory additions
Inventory limiting
Playbook parsing
Order of operations
Relative path assumptions
Play behavior directives
Execution strategies
Host selection for plays and tasks
Play and task names
Module transport and execution
Module reference
Module arguments
Module transport and execution
Task performance
Variable types and location
Variable types
Accessing external data
Variable precedence
Precedence order
Merging hashes
Summary
Chapter 2: Protecting Your Secrets with Ansible
Encrypting data at rest
Things Vault can encrypt
Creating new encrypted files
Password prompt
Password file
Password script
Encrypting existing files
Editing encrypted files
Password rotation on encrypted files
Decrypting encrypted files
Executing Ansible-playbook with encrypted files
Protecting secrets while operating
Secrets transmitted to remote hosts
Secrets logged to remote or local files
Summary
Chapter 3: Unlocking the Power of Jinja2 Templates
Control structures
Conditionals
Inline conditionals
Loops
Filtering loop items
Loop indexing
Macros
Macro variables
name
arguments
defaults
catch_kwargs
catch_varargs
caller
Data manipulation
Syntax
Useful built-in filters
default
count
random
round
Useful Ansible provided custom filters
Filters related to task status
shuffle
Filters dealing with path names
basename
dirname
expanduser
Base64 encoding
Searching for content
Omitting undefined arguments
Python object methods
String methods
List methods
int and float methods
Comparing values
Comparisons
Logic
Tests
Summary
Chapter 4: Controlling Task Conditions
Defining a failure
Ignoring errors
Defining an error condition
Defining a change
Special handling of the command family
Suppressing a change
Error recovery
Rescue
Always
Summary
Chapter 5: Composing Reusable Ansible Content with Roles
Task, handler, variable, and playbook include concepts
Including tasks
Passing variable values to included tasks
Passing complex data to included tasks
Conditional task includes
Tagging included tasks
Task includes with loops
Including handlers
Including variables
vars_files
Dynamic vars_files inclusion
include_vars
extra-vars
Including playbooks
Roles
Role structure
Tasks
Handlers
Variables
Modules and plugins
Dependencies
Files and templates
Putting it all together
Role dependencies
Role dependency variables
Tags
Role dependency conditionals
Role application
Mixing roles and tasks
Role includes
Role sharing
Ansible Galaxy
Summary
Chapter 6: Minimizing Downtime with Rolling Deployments
In-place upgrades
Expanding and contracting
Failing fast
The any_errors_fatal option
The max_fail_percentage option
Forcing handlers
Minimizing disruptions
Delaying a disruption
Running destructive tasks only once
Serializing single tasks
Summary
Chapter 7: Troubleshooting Ansible
Playbook logging and verbosity
Verbosity
Logging
Variable introspection
Variable sub elements
Subelement versus Python object method
Debugging code execution
Playbook debugging
Debugging local code
Debugging inventory code
Debugging playbook code
Debugging executor code
Debugging remote code
Debugging the action plugins
Summary
Chapter 8: Extending Ansible
Developing modules
The basic module construct
Custom modules
Simple module
Module documentation
Providing fact data
The check mode
Supporting the check mode
Handling check mode
Developing plugins
Connection type plugins
Shell plugins
Lookup plugins
Vars plugins
The fact caching plugins
Filter plugins
Callback plugins
Action plugins
Distributing plugins
Developing dynamic inventory plugins
Listing hosts
Listing host variables
Simple inventory plugin
Optimizing script performance
Contributing to the Ansible project
Contribution submissions
The ansible repository
Executing tests
Unit tests
Integration tests
Code style tests
Making a pull request
Summary
Chapter 9: Infrastructure Provisioning
Managing cloud infrastructure
Creating servers
Booting virtual servers
Adding to runtime inventory
Using OpenStack inventory source
Interacting with Docker containers
Building images
Building containers without a Dockerfile
Docker inventory
Previewing of Ansible container
Init
Build
Run
Summary
Index
Mastering Ansible Second Edition Master the ins and outs of advanced operations with Ansible Jesse Keating BIRMINGHAM - MUMBAI
Mastering Ansible Second Edition 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: November 2015 Second edition: March 2017 Production reference: 1270317 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78712-568-1 www.packtpub.com
Credits Author Jesse Keating Reviewer Sreenivas Makam Acquisition Editor Prachi Bisht Content Development Editor Trusha Shriyan Copy Editor Safis Editing Project Coordinator Kinjal Bari Proofreader Safis Editing Indexer Pratik Shirodkar Technical Editor Varsha Shivhare Production Coordinator Nilesh Mohite Graphics Kirk D'Penha
About the Author Jesse Keating is an accomplished Ansible user, contributor, and presenter. He has been an active member of the Linux and open source community for over fifteen years. He has first- hand experience with a variety of IT activities, software development, and large-scale system administration. He has presented at numerous conferences and meet-ups, and has written many articles on a variety of topics.
About the Reviewer Sreenivas Makam is a senior engineering manager at Cisco Systems, Bangalore. He has a master's in electrical engineering and has around 18 years’ experience in the networking industry. He has worked in both startups and big, established companies. His interests include Containers, SDN, network automation, devops, and cloud technologies, and he likes to try out and follow open source projects in these areas. His blog can be found at h t t p s ://s r e e n i n e t . w o r d p r e s s . c o m /, he has presentations at h t t p ://w w w . s l i d e s h a r e . n e t /S r e e n i v a s M a k a m , and his hacky code is at h t t p s ://g i t h u b . c o m /s m a k a m . Sreenivas is a Docker Captain, (h t t p s ://w w w . d o c k e r . c o m /c o m m u n i t y /d o c k e r - c a p t a i n s ) and his blog articles have been published in Docker weekly newsletters. He can be reached on Twitter at @srmakam. He has written Mastering CoreOS, also reviewed Mastering Ansible, CoreOS Cookbook, all by Packt Publishing. It was extra special that my second daughter, Masha, was born while reviewing this book. Thanks to my daughters, Sasha and Masha, for keeping me energetic.
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.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub.com 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 /1787282589. If you'd like to join our team of regular reviewers, you can e-mail us at customerreviews@packtpub.com. We award our regular reviewers with free eBooks and videos in exchange for their valuable feedback. Help us be relentless in improving our products!
分享到:
收藏