Ansible

This is growing into a minimal Ansible reference of sorts, since Ansible’s own docs have nothing like a reference.

Quickies:

To check the ubuntu version, ansible_distribution_version|float < 18 (ansible_distribution_version is e.g. “16.04”):

"ansible_distribution_release": "bionic"
"ansible_distribution_version": "18.04"

Better error formatting from https://www.jeffgeerling.com/blog/2018/use-ansibles-yaml-callback-plugin-better-cli-experience Put this in ansible.cfg:

[defaults]
# FROM https://www.jeffgeerling.com/blog/2018/use-ansibles-yaml-callback-plugin-better-cli-experience
# Use the YAML callback plugin.
stdout_callback = yaml
# Use the stdout_callback when running ad-hoc commands.
bin_ansible_callbacks = True

Just note that this can break output from ‘command’ or ‘ansible -m setup’, and you might need to disable it if you need that. Open issue: https://github.com/ansible/ansible/issues/39122

Misc. stuff I need to file somewhere:

Ad-hoc command

ansible Host Patterns -m <module> [options]

e.g.

$ ansible all -m ping –ask-pass

Shortcut to run a command:

$ ansible all -a “/bin/echo hello”

options: see output of “ansible –help” for now

See ansible ad-hoc commands doc for ad-hoc commands.