Mastering Ansible - Second Edition

Book description

Master the ins and outs of advanced operations with Ansible

About This Book

  • Learn how to extend Ansible with custom modules, plugins, and inventory sources

  • Utilize advanced Ansible features to orchestrate rolling updates with little to no service disruptions

  • An up-to-date book that brings to light the newly added features in Ansible 2.x

  • Who This Book Is For

    This book is for Ansible developers and operators who have an understanding of the core elements and applications but are now looking to enhance their skills in applying automation using Ansible.

    What You Will Learn

  • Gain an in-depth understanding of how Ansible works under the covers

  • Fully automate the Ansible playbook executions with encrypted data

  • Access and manipulate variable data within playbooks

  • Use Blocks to construct failure recovery or cleanup

  • Explore the Playbook debugger and Ansible Console

  • Troubleshoot unexpected behavior effectively

  • Work with cloud infrastructure providers and container systems

  • Develop custom modules, plugins, and dynamic inventory sources

  • In Detail

    This book provides you with the knowledge you need to understand how Ansible 2.1 works at a fundamental level and leverage its advanced capabilities. You'll learn how to encrypt Ansible content at rest and decrypt data at runtime. You will master the advanced features and capabilities required to tackle the complex automation challenges of today and beyond.

    You will gain detailed knowledge of Ansible workflows, explore use cases for advanced features, craft well thought out orchestrations, troubleshoot unexpected behaviour, and extend Ansible through customizations. Finally, you will discover the methods used to examine and debug Ansible operations, helping you to understand and resolve issues.

    By the end of the book, the readers will be able to unlock the true power of the Ansible automation engine and will tackle complex real world actions with ease.

    Style and approach

    This clear, practical guide illustrates the advanced functionalities of Ansible, its system architecture, and design aspects that will help you to master Ansible with ease.

    Table of contents

    1. Mastering Ansible - Second Edition
      1. Mastering Ansible - Second Edition
      2. Credits
      3. About the Author
      4. About the Reviewer
      5. www.PacktPub.com
        1. Why subscribe?
      6. Customer Feedback
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Downloading the color images of this book
          3. Errata
          4. Piracy
          5. Questions
      8. 1. System Architecture and Design of Ansible
        1. Ansible version and configuration
        2. Inventory parsing and data sources
          1. Static inventory
          2. Inventory variable data
          3. Dynamic inventories
          4. Runtime inventory additions
          5. Inventory limiting
        3. Playbook parsing
          1. Order of operations
          2. Relative path assumptions
          3. Play behavior directives
          4. Execution strategies
          5. Host selection for plays and tasks
          6. Play and task names
        4. Module transport and execution
          1. Module reference
          2. Module arguments
          3. Module transport and execution
            1. Task performance
        5. Variable types and location
          1. Variable types
        6. Accessing external data
        7. Variable precedence
          1. Precedence order
          2. Merging hashes
        8. Summary
      9. 2. Protecting Your Secrets with Ansible
        1. Encrypting data at rest
          1. Things Vault can encrypt
          2. Creating new encrypted files
            1. Password prompt
            2. Password file
            3. Password script
          3. Encrypting existing files
          4. Editing encrypted files
          5. Password rotation on encrypted files
          6. Decrypting encrypted files
          7. Executing Ansible-playbook with encrypted files
        2. Protecting secrets while operating
          1. Secrets transmitted to remote hosts
          2. Secrets logged to remote or local files
        3. Summary
      10. 3. Unlocking the Power of Jinja2 Templates
        1. Control structures
          1. Conditionals
            1. Inline conditionals
          2. Loops
            1. Filtering loop items
            2. Loop indexing
          3. Macros
            1. Macro variables
              1. name
              2. arguments
              3. defaults
              4. catch_kwargs
              5. catch_varargs
              6. caller
        2. Data manipulation
          1. Syntax
          2. Useful built-in filters
            1. default
            2. count
            3. random
            4. round
          3. Useful Ansible provided custom filters
            1. Filters related to task status
            2. shuffle
            3. Filters dealing with path names
              1. basename
              2. dirname
              3. expanduser
            4. Base64 encoding
            5. Searching for content
          4. Omitting undefined arguments
          5. Python object methods
            1. String methods
            2. List methods
            3. int and float methods
        3. Comparing values
          1. Comparisons
          2. Logic
          3. Tests
        4. Summary
      11. 4. Controlling Task Conditions
        1. Defining a failure
          1. Ignoring errors
          2. Defining an error condition
        2. Defining a change
          1. Special handling of the command family
          2. Suppressing a change
        3. Error recovery
          1. Rescue
          2. Always
        4. Summary
      12. 5. Composing Reusable Ansible Content with Roles
        1. Task, handler, variable, and playbook include concepts
          1. Including tasks
            1. Passing variable values to included tasks
            2. Passing complex data to included tasks
            3. Conditional task includes
            4. Tagging included tasks
          2. Task includes with loops
          3. Including handlers
          4. Including variables
            1. vars_files
            2. Dynamic vars_files inclusion
            3. include_vars
            4. extra-vars
          5. Including playbooks
        2. Roles
          1. Role structure
            1. Tasks
            2. Handlers
            3. Variables
            4. Modules and plugins
            5. Dependencies
            6. Files and templates
            7. Putting it all together
          2. Role dependencies
            1. Role dependency variables
            2. Tags
            3. Role dependency conditionals
          3. Role application
            1. Mixing roles and tasks
            2. Role includes
          4. Role sharing
            1. Ansible Galaxy
        3. Summary
      13. 6. Minimizing Downtime with Rolling Deployments
        1. In-place upgrades
        2. Expanding and contracting
        3. Failing fast
          1. The any_errors_fatal option
          2. The max_fail_percentage option
          3. Forcing handlers
        4. Minimizing disruptions
          1. Delaying a disruption
          2. Running destructive tasks only once
        5. Serializing single tasks
        6. Summary
      14. 7. Troubleshooting Ansible
        1. Playbook logging and verbosity
          1. Verbosity
          2. Logging
        2. Variable introspection
          1. Variable sub elements
            1. Subelement versus Python object method
        3. Debugging code execution
          1. Playbook debugging
          2. Debugging local code
            1. Debugging inventory code
            2. Debugging playbook code
            3. Debugging executor code
            4. Debugging remote code
            5. Debugging the action plugins
        4. Summary
      15. 8. Extending Ansible
        1. Developing modules
          1. The basic module construct
          2. Custom modules
          3. Simple module
            1. Module documentation
            2. Providing fact data
            3. The check mode
              1. Supporting the check mode
              2. Handling check mode
        2. Developing plugins
          1. Connection type plugins
          2. Shell plugins
          3. Lookup plugins
          4. Vars plugins
          5. The fact caching plugins
          6. Filter plugins
          7. Callback plugins
          8. Action plugins
          9. Distributing plugins
        3. Developing dynamic inventory plugins
          1. Listing hosts
          2. Listing host variables
          3. Simple inventory plugin
            1. Optimizing script performance
        4. Contributing to the Ansible project
          1. Contribution submissions
            1. The ansible repository
            2. Executing tests
              1. Unit tests
              2. Integration tests
              3. Code style tests
            3. Making a pull request
        5. Summary
      16. 9. Infrastructure Provisioning
        1. Managing cloud infrastructure
          1. Creating servers
            1. Booting virtual servers
            2. Adding to runtime inventory
          2. Using OpenStack inventory source
        2. Interacting with Docker containers
          1. Building images
          2. Building containers without a Dockerfile
          3. Docker inventory
        3. Previewing of Ansible container
          1. Init
          2. Build
          3. Run
        4. Summary

    Product information

    • Title: Mastering Ansible - Second Edition
    • Author(s): Jesse Keating
    • Release date: March 2017
    • Publisher(s): Packt Publishing
    • ISBN: 9781787125681