A question about some modules

So I was thinking about some of the modules implemented in ansible.

A few of them just proxy through to unix commands while others will use a Python API when it exists. Can someone explain the advantages and disadvantages for both?

I can only think of an API being more programmer friendly for getting back return codes, calling functions instead of commands etc …

Am I missing other points? I’m writing a few modules and don’t want to feel bad for writing a command proxy when I could spend time writing a python API for my needs.

Kind Regards,
-Mathew Davies.

A few of them just proxy through to unix commands while others will
use a Python API when it exists. Can someone explain the advantages
and disadvantages for both?

I don't have a general answer, but I can illustrate one such difference
by something I ran into months ago.

I had a list of Debian package names, and I wanted to figure out which
packages in that list were not already installed; or, alternatively, to
find out if they were all up-to-date or not. This turns out to be clumsy
and slow to do using apt-get on the command line.

In contrast, with just a few lines of Python, I could use an apt.Cache()
to check cache[name].is_installed and cache[name].installed.version for
all my packages in a loop. It worked great.

I'm writing a few modules and don't want to feel bad for writing a
command proxy when I could spend time writing a python API for my
needs.

My advice, for what it's worth, would be to do as much as you can by
running commands, and write more code only if a clear need presents
itself. (Oh, also: don't feel bad.)

-- ams

This is more of a topic for ansible-project.

In many cases Ansible doesn’t wish to add extra dependencies for remote modules and the CLI commands are sufficient.

In other cases, we want to do something a lot more involved (like work with OpenStack) where the library is the most logical and stable option.

It all depends basically.

In some cases, an underlying API may be very fragile by platform - basically rarely updated random packages on PyPi are not things we like to link against, nor do we like to use packages that are not available in EPEL.

We almost never try to parse output, but it’s fine to shell out to a Unix command and interrogate a return code, and keeps our dependencies down and in many cases the app is more reliable.

I mean ansible-devel here, not ansible-project.

Feel free to join the development list when you get a chance!