Book Image

Ansible Configuration Management - Second Edition

By : Daniel Hall
Book Image

Ansible Configuration Management - Second Edition

By: Daniel Hall

Overview of this book

<p>Ansible is an open source software platform for configuring and managing computers. It provides a clear and concise way to manage the configuration of your Linux infrastructure. This book is a step-by-step guide that provides you with the knowledge you require to effectively manage your systems in a simple, quick, and maintainable way, with real-world examples.</p> <p>You will begin by learning the basics of Ansible and then move on to exploring more advanced topics. You will then learn the basic and complex operations of playbooks and interact with modules to manage Windows machines and deploy them. You will also get acquainted with Ansible's more advanced features such as serially updating machines, delegating tasks to other machines, advanced uses of variables, looping and conditions, copying whole directories, and using filters to process variables. Towards the end of the book, you will learn how to increase the functionality of Ansible itself by writing your own modules and plugins.</p>
Table of Contents (12 chapters)

Chapter 5. Custom Modules

Until now we have been working solely with the tools provided to us by Ansible. This does afford us a lot of power, and make many things possible. However if you have something particularly complex or if you find yourself using the script module a lot, you will probably want to learn how to extend Ansible.

In this chapter, you will learn the following topics:

  • How to write modules in Bash scripting or Python

  • Using the custom modules that you have developed

  • Writing a script to use an external data source as an inventory

Often when you approach something complex in Ansible, you write a script module. The issue with script modules is that you can't process their output, or trigger handlers based on their output easily. So, although the script module works in some cases, using a module can be better.

Use a module instead of writing a script when:

  • You don't want to run the script every single time

  • You need to process the output

  • Your script needs to make facts

  • You need to send complex...