Ansible’s ad-hoc Reference Guide

Yes, I know this is like, the first thing that the Ansible Documentation site teaches you. But, again, it IS, like, the first thing this massive thing teaches you, and not in too much detail.

So, here’s a repeat, refresher, with screenshots!!

ansible ubuntu -a 'free -m'
Ansible Basic Command Module

This just runs ansible’s command module. As in it doesn’t support shell variables and things like piping. Thus, why the only flag given is the -a flag. If you wanted to change the module used, you’d include the -m flag before -a, as the -a flag tells ansible the text within the ` ` is the actual text for the module requested.

Next, we change the module to ping

ansible all -m ping

This doesn’t require the -a flag, unless there are other options you want to include with the ping module. Otherwise, this will run a simple ping on the hosts you requested.

Ansible Ping Module

Pass a List

I’ve been wanting to figure this one out for forever!

Basically, how to pass multiple items into a command option when using ansible’s ad-hoc mode on the command line.

ansible ipsec --become -m apt -a 'name={{ list }}' -e '{"list": [strongswan,strongswan-plugin-eap-mschapv2,moreutils,iptables-persistent]}'