If I'm going to write an Ansible module, that targets Linux systems,
what language, other than Python, would/could I use to write that
module?
@Trevor -
I would highly encourage Python, as that would be the "Native" and standard choice for Ansible since most Ansible modules are already built using Python and there is an AnsibleModule utility class. Additionally, you could use an existing Ansible module as a template for a module in your new collection.
It is possible to use other things like BASH, GO, Rust, C, or other languages, but each one would have some challenges such as possibly needing to compile and have binaries or tools to be available and installed.
The important things or requirements for an Ansible Module is that it must have both Input and Output for the typical Ansible module protocol. This output is expected to be JSON - just like custom inventory plugins or inventory scripts, so again, some languages are better suited to make dealiing with JSON easier.
And this response is the very reason I bring this type of query
to the RHLC!
Many thanks Travis!!!
@Trevor Agree with Travis on this, python is the best bcz it is easiest and integrates well with Ansible libraries.
Since the Ansible module contract relies on a straightforward JSONin/JSON out communication model, you have the flexibility to write modules in virtually any programming language. The only real requirements are that the language must be executable on the managed host and capable of reading input that is either via standard input or a temporary file and returning avalid JSON.
This approach has led to a wide variety of community driven examples. For instance, you will find everything from lightweight Bash scripts that handle simple tasks to compiled binaries written in Go or Rust for more performance-critical work. Even interpreted languages like Perl and Ruby work perfectly fine, provided they include the correct shebang. Ultimately, as long as the code can be executed on the target and emit the expected JSON structure, Ansible can manage it.
https://forum.ansible.com/t/modules-in-languages-other-than-python/30997
https://docs.ansible.com/projects/ansible/latest/dev_guide/developing_modules_general.html
Pure gold!
Many thanks Chetan!!!
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.