# Writing custom modules for Ansible

DevFeed: [Writing custom modules for Ansible](<https://devfeed.tech/articles/writing-custom-modules-for-ansible-22362.md>)

Original publisher: [Read original article](<http://www.afronski.pl/2016/03/28/writing-custom-modules-for-ansible.html>)

Author: Wojtek Gawroński (afronski)

Published: 2016-03-28T19:00:00Z

Content type: tutorial

Language: en

Sources: [Wojtek Gawroński](<https://devfeed.tech/sources/wojtek-gawronski.md>)

Topics: [Ansible](<https://devfeed.tech/topics/ansible.md>), [modules](<https://devfeed.tech/topics/modules.md>), [Automation](<https://devfeed.tech/topics/automation.md>), [configuration-management](<https://devfeed.tech/topics/configuration-management.md>), [Erlang](<https://devfeed.tech/topics/erlang.md>), [JSON](<https://devfeed.tech/topics/json.md>), [YAML](<https://devfeed.tech/topics/yaml.md>), [Scripting](<https://devfeed.tech/topics/scripting.md>)

Tags: [ansible](<https://devfeed.tech/tags/ansible.md>), [automation](<https://devfeed.tech/tags/automation.md>), [c-sharp](<https://devfeed.tech/tags/c-sharp.md>), [canvas](<https://devfeed.tech/tags/canvas.md>), [clojure](<https://devfeed.tech/tags/clojure.md>), [code](<https://devfeed.tech/tags/code.md>), [commands](<https://devfeed.tech/tags/commands.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [configuration-management](<https://devfeed.tech/tags/configuration-management.md>), [css](<https://devfeed.tech/tags/css.md>), [css3](<https://devfeed.tech/tags/css3.md>), [erlang](<https://devfeed.tech/tags/erlang.md>), [html](<https://devfeed.tech/tags/html.md>), [html5](<https://devfeed.tech/tags/html5.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [json](<https://devfeed.tech/tags/json.md>), [modules](<https://devfeed.tech/tags/modules.md>), [mono](<https://devfeed.tech/tags/mono.md>), [net](<https://devfeed.tech/tags/net.md>), [node-js](<https://devfeed.tech/tags/node-js.md>), [programming](<https://devfeed.tech/tags/programming.md>), [scripting](<https://devfeed.tech/tags/scripting.md>), [sicp](<https://devfeed.tech/tags/sicp.md>), [vagrant](<https://devfeed.tech/tags/vagrant.md>), [webgl](<https://devfeed.tech/tags/webgl.md>)

## AI overview

This tutorial explains Ansible modules, including their role in remote infrastructure management, YAML-based declarative configuration, dependencies on the provisioned machine, and JSON input/output requirements. It then introduces a case study for implementing a custom module in Erlang to process XML status pages.

## Source excerpt

Writing custom modules for Ansible Introduction What is Ansible and what is a module? If you are a big fan of automation, if you are focused on spreading and building software in line with DevOps culture, tools related with automation / configuration management like Chef or Ansible are probably well known to you. From the other hand that what differentiates those tools is a topic for a next blog post. Without diving into those differences, let's briefly zoom into details for those people which do not know what Ansible and modules are. Ansible is a free-software platform for configuring and managing machines. It combines deployment, ad-hoc tasks execution and configuration management. This tool uses YAML and declarative way of defining steps, which are modifying state of your fleet. Module is a single piece of those steps, a well defined way of executing certain tasks on the remote infrastructure. It executes commands, and communicates by outputting JSON to standard output - it means that it can be written in any programming or scripting language. Development Before we'll start actual implementation we need to know how it works underneath. Requirements If you want to write a custom module, we stated above that you have to be aware of two things. Your module code will be executed on the provisioned machine, so all dependencies which your module requires, have to be there. Second, your module communicates over specific input and output protocols. It uses certain syntax for sending input parameters (either sent as a stdin or a file) and JSON protocol which will be consumed as an output of the module. And nothing more - any other, non-JSON compliant output will be treated as an error, and would not be consumed by Ansible properly. Case Study We would like to consume XMLified status pages and do certain actions based on checked and exposed facts, scraped from aforementioned place. Because I like Erlang, I will use that language to implement that module. We will do it usin