You are previewing Extending Ansible.
O'Reilly logo
Extending Ansible

Book Description

Discover how to efficiently deploy and customize Ansible in the way your platform demands

About This Book

  • Get the first book on the market that maximizes the functionalities of Ansible

  • Master the skill of extending Ansible by deep diving into its modules and plugins

  • Work through this step-by-step guide to customizing Ansible according to your requirements

  • Who This Book Is For

    This book is perfect for developers and administrators who are familiar with Ansible and Python programming, but have no knowledge of how to customize Ansible.

    What You Will Learn

  • Get a thorough understanding of Ansible modules

  • Find out everything about plugins that fit in the Ansible architecture

  • Get to grips with designing modules and handling errors

  • Work with data structures

  • Distribute Ansible extensions using PyPi and Git submodules

  • Get to know the various distribution methods of modules and plugins

  • In Detail

    Ansible is an IT automation tool that lets you manage your Infrastructure as a Code. It helps you deploy your applications and manage configurations, thus making life easier. Ansible, in most ways, is self sufficient to address most of your requirements.

    Ideally, standard modules, libraries, or plugins are used to automate a given IT platform. Customizing Ansible can be done by custom module and plugin development.

    This book shows you how to automate most of the tasks in your IT environment, thus minimizing the need to manually perform scheduled tasks and extend your Ansible implementation by developing customized modules and plugins.

    You’ll begin by getting an understanding of the fundamental aspects of extending the Ansible framework, such as custom functions and reusable modules. You’ll then progress to building custom plugins and extensions using the fundamental building blocks explained earlier. We’ll also show you how to automate some tasks using scripts. Finally, we’ll demonstrate how these extensions can be seamlessly integrated into existing Ansible installations and explain how to conduct unit testing on these extensions to ensure they work as desired.

    Style and approach

    This book is a learning book on the fundamentals of Ansible framework and how it can be leveraged to extend it using the modules and plugins.

    Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

    Table of Contents

    1. Extending Ansible
      1. Table of Contents
      2. Extending Ansible
      3. Credits
      4. About the Author
      5. About the Reviewer
      6. www.PacktPub.com
        1. eBooks, discount offers, and more
          1. Why subscribe?
      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. Errata
          3. Piracy
          4. Questions
      8. 1. Getting Started with Ansible
        1. Why Ansible?
        2. Why extend Ansible?
          1. Need something new
          2. Company-wide abstraction
          3. Diving into Ansible
        3. Contributing to Ansible
        4. Ansible architecture
          1. Brief overview of Ansible components
          2. Ansible runner
            1. Connection plugins
            2. Playbook
            3. Roles
            4. Variables
            5. Facts
            6. Runner
        5. Playbook expressiveness
          1. Extending Ansible
            1. Custom fact scripts
            2. Modules
            3. Plugins
            4. Python API
        6. Summary
      9. 2. Getting to Know Ansible Modules
        1. Writing your first Ansible module
          1. Execution environment
          2. Step 1 – module placement
          3. Writing a basic Bash module
          4. Reading arguments
          5. Handling errors
        2. Creating Ansible modules in Python
          1. The AnsibleModule boilerplate
        3. Documenting modules
        4. Testing and debugging modules
        5. Quick local execution
        6. Best practices
        7. Summary
      10. 3. Digging Deeper into Ansible Modules
        1. Dry run (check mode)
        2. Loading modules
        3. Exploiting Ansible
          1. Diving deeper into the AnsibleModule boilerplate
        4. Complex arguments
          1. Reading complex arguments
        5. Summary
      11. 4. Exploring API
        1. Python API
          1. Runner
          2. Playbook
          3. Callbacks
        2. Ansible plugins
          1. PluginLoader
        3. Summary
      12. 5. An In-Depth Look at Ansible Plugins
        1. Lookup plugins
          1. Lookup pluginfile
          2. Lookup plugin – csvfile
          3. Lookup plugin – dig
          4. Lookup plugin – ini
        2. Loops – lookup plugins for iteration
          1. Standard loop – with_items
          2. Do until loop–until
          3. Create your own lookup plugin
        3. Callback plugins
        4. Var plugins
        5. Connection plugins
        6. Filter plugin
          1. Using filters with conditions
          2. Version comparison
          3. IP address filter
          4. Understanding the code
        7. Summary
      13. 6. Fitting It All Together – Integration
        1. Configuring Ansible
          1. Environment configuration
        2. Contributing to Ansible
        3. Galaxy–sharing roles
        4. Galaxy – best practices
        5. Sharing modules and plugins
          1. Getting a module into Ansible
        6. Getting plugins into Ansible
          1. Points to remember
        7. Best practices
        8. Summary
      14. 7. Becoming a Master – A Complete Configuration Guide
        1. One playbook, different applications, multiple targets
        2. Ansible roles – using tags
        3. Getting infrastructure information and hosting it centrally
        4. Creating a dynamic inventory of just launched instances
        5. Ansible through a bastion host
        6. Happy managers = happy you
        7. Summary
      15. Index