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

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.

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.

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

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

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

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.