Modules in languages other than Python?

This page: https://docs.ansible.com/ansible/2.3/dev_guide/developing_modules_general.html
states that modules can be in other languages. Are there any examples of this? I’m much more proficient in Perl than Python and would prefer to write in that language.

An additional thought… I’m not sure I need to write any modules, but I want to know how if I do.

TIA

Mike

All the native Windows modules is written in Powershell
https://github.com/ansible/ansible/tree/devel/lib/ansible/modules/windows

Other than that, I have not seen modules in other languages, but that doesn't mean they don't exist.

There’s no real examples that I know off, if you are not writing a module in Python (on Linux) or PowerShell (on Windows) it can still be done you just miss out on some of the helper functions that Ansible provides to parse the input requirements and output the end result back to the controller. Ultimately if you want to continue ahead with this you will need to;

  • Add a shebang to the start of the module, e.g. `#!/usr/bin/perl’
  • Add ‘# WANT_JSON’ in the module to get module args as JSON instead of key=value. Only the ‘WANT_JSON’ is important and ‘#’ is just to comment the line
  • Ansible executes the module and specifies the file where the module arguments are as the first argument, so you would need to read arg[1] in your script then read that file to get the input arguments
  • As stated above, by default these arguments are in a key=value form but adding ‘WANT_JSON’ ensures they are in json which is better for complex data- Do not print anything to the console except for the output json once the module is complete
  • The output json should at least return ‘{“changed”: false}’ (set to true if there was a change) but you can add whatever you want
  • If the module fails, add {“failed”: true} to the output json string alongside “msg” to indicate what went wrong
    There’s probably more to add but ultimately it is possible to write modules in another language it just means you have to do the low level work yourself.

Thanks

Jordan

We do have a few examples:

Go: https://github.com/ansible/ansible/blob/devel/test/integration/targets/binary_modules/library/helloworld.go
shell: https://github.com/ansible/ansible/blob/devel/test/integration/targets/old_style_modules_posix/library/helloworld.sh
WANT_JSON (although implemented in python): https://github.com/ansible/ansible/blob/devel/test/integration/targets/want_json_modules_posix/library/helloworld.py
Rust: https://github.com/ansible/ansible-examples/blob/master/rust-module-hello-world/module-src/src/main.rs

There is a Perl module for helping develop Ansible modules in Perl at https://metacpan.org/pod/AnsibleModule