# I would like to convert my BASH scripts to Ansible User Modules

**URL:** <https://forum.ansible.com/t/i-would-like-to-convert-my-bash-scripts-to-ansible-user-modules/15255>\
**Category:** Ansible Developer\
**Tags:** aws\
**Created:** [May 16, 2014, 4:09pm UTC](https://forum.ansible.com/t/i-would-like-to-convert-my-bash-scripts-to-ansible-user-modules/15255 "2014-05-16T16:09:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JohnP](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@JohnP](https://forum.ansible.com/u/JohnP)\
**Post date:** [May 16, 2014, 4:09pm UTC](https://forum.ansible.com/t/i-would-like-to-convert-my-bash-scripts-to-ansible-user-modules/15255/1 "2014-05-16T16:09:27Z")

</div>

Hi All,

I have written some BASH ;( scripts that collects some information and shows them  
“very” human friendly and colourful format. Via Aws Cli, json processing etc.  
An obfuscated example as below for displaying the idea // result.

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [May 16, 2014, 7:08pm UTC](https://forum.ansible.com/t/i-would-like-to-convert-my-bash-scripts-to-ansible-user-modules/15255/2 "2014-05-16T19:08:27Z")

</div>

All output is handled via callbacks - the modules themselves do not output anything other than JSON. Theoretically you could create your own callback plugin to create output similar to yours above, however you would have to use it via the Ansible API. See the code in bin/ansible or bin/ansible-playbook to see how the callbacks are used there.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [May 16, 2014, 11:32pm UTC](https://forum.ansible.com/t/i-would-like-to-convert-my-bash-scripts-to-ansible-user-modules/15255/3 "2014-05-16T23:32:19Z")

</div>

If you have bash scripts that return that structured output, and want to wrap them with a module, you could.

Really the question is how to write a module in Bash – that’s easy.

The trick to writing a bash module in ansible is reading $1 (first argument) for the name of a file that returns key=value variables.

Then, either return JSON, or a series of results in key=value format, one per line (aka “baby JSON”)

ex:

[https://groups.google.com/forum/#!topic/ansible-project/RRWx1PQoQZU](https://groups.google.com/forum/#!topic/ansible-project/RRWx1PQoQZU)

But I probably wouldn’t try to parse your existing CLI, given the color codes and such.

---

<div class="post-metadata">

**Author:** ![JohnP](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@JohnP](https://forum.ansible.com/u/JohnP)\
**Post date:** [May 19, 2014, 2:45pm UTC](https://forum.ansible.com/t/i-would-like-to-convert-my-bash-scripts-to-ansible-user-modules/15255/4 "2014-05-19T14:45:11Z")

</div>

Hi, thanks to all whom kindly & promptly replied to my request.

> Brian Coca  
> James Cammarata  
> Michael DeHaan

After reading to posts, I am delighted to realise I can convert my scripts  
to Ansible & Python via “calbacks”.  
I really like Python (although sadly not an expert at the moment).

> …want to wrap them with a module, you could…

Since I have written them and know the algorithm, I would like to convert,  
instead of making yet more calls to AWS API (written in Python), external  
applications and process JSON in BASH inefficiently.  
It seems like Boto and Ansible are marriage made in heaven. I’ll definitely  
have go as a start.

Best Regards: JohnP

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [May 25, 2014, 9:20pm UTC](https://forum.ansible.com/t/i-would-like-to-convert-my-bash-scripts-to-ansible-user-modules/15255/5 "2014-05-25T21:20:10Z")

</div>

FYI - Ansible modules in bash and callbacks have nothing in common.

Callbacks in Ansible are a way of hooking output and sending them to different places.
