ansible

Table of Contents

1. Inspect

1.1. inventory

ansible-inventory -i <inventory_file> --graph
ansible-inventory -i <inventory_file> --list
ansible-inventory -i <inventory_file> --host <hostname> # see info about host
ansible <pattern> --list-hosts

1.2. configuration

ansible-config list # list all available options, good for reference
ansible-config dump # list effective options w source
ansible-config view # view ansible.cfg as is

2. Documentation & Help

ansible-doc <fqcn.plugin_name> # show doc of certain plugin
ansible-doc -l <namespace.collection> # list shit form the collection
ansible-doc -l -t <plugin_type> # list shit from all collection of that plugin type
ansible-doc -l <namespace.collection> -t <plugin_type> # list shit from certain collection of that plugin type

3. Playbook

3.1. Run a playbook

ansible-playbook playbook.yaml

3.2. Verify/check

ansible-playbook --check playbook.yaml # dry run, register variables skipped
ansible-playbook --diff playbook.yaml # show diff for files/templates
ansible-playbook --list-tasks playbook.yaml # list tasks to be executed
ansible-playbook --list-hosts playbook.yaml # list matching host
ansible-playbook --syntax-check playbook.yaml
ansible-lint playbook.yaml

3.3. Other notes on playbooks

  • Use lowercase for task names
  • Use - separated names for handler names, no spaces
  • Sometimes dpkg lock gets in the way.

4. Role

ansible-galaxy init <role_name> # create an base role directory

Created: 2024-07-16 Tue 16:44

Validate