Cheat Sheet

Useful Ansible commands.

Hosts

Host from variable

Playbook file:

- name: Your playbook name
  hosts: "{{ variable_host | default('localhost') }}"
  become: yes

To run it:

ansible-playbook playbooks/your-playbook-name.yml \
  --extra-vars "variable_host=PUT-YOUR-HOST-HERE"

Ping

Ping all hosts

ansible all -m ping -u root

Ping localhost

ansible all -m shell -a "ping -c 3 localhost" -u root

Python virtualenv

Make sure python will load all modules installed in your virtualenv.

Set RSA key path

Install packages

Decrypt

Decrypt string

Make sure your string variable is in group_vars/all.yml.

For example:

Then run:

Last updated