Show Menu
Cheatography

Ansible commands Cheat Sheet (DRAFT) by

Quick and fast reminder for Ansible command line

This is a draft cheat sheet. It is a work in progress and is not finished yet.

ansibl­e-p­laybook

<YA­ML>
Run on all hosts defined
<YA­ML> -f 10
Run 10 hosts in parallel
<YA­ML> -v
Verbosity (-vv, -vvv)
<YA­ML> -C -D
-C: Dry run -D: Diff
<YA­ML> -l <ho­st>
Run the playbook against <ho­st>
<YA­ML> [--lis­t-hosts | --list­-tasks]
Show [hosts | tasks] triggered for each play
<YA­ML> --synt­ax-­check
Self explan­atory
<YA­ML> --star­t-a­t-task "my task"
Start PB at specific task
<YA­ML> --tags "­tag­1,t­ag2­"
Only run tasks with
tag1 and 2
<YA­ML> --tags [tag1,­tag2]
Only run tasks with
tag1 or 2
<YA­ML> --skip­-tags [tag1,­tag2]
Skip tasks with tag1 or 2
<YA­ML> -e "­APP­_US­ER=­joh­n"
Override variable in your playbook
--become --beco­me-­met­hod­=doas --beco­me-­use­r=w­ww-data --ask-­bec­ome­-pass
Run the playbook as www-data. Use method runas for windows hosts
... --ask-­vau­lt-pass
Ask for the vault pass at runtime
... --vaul­t-p­ass­wor­d-file <va­ult­_pa­ssw­ord­_fi­le>
If you vault pass is in a file
<YA­ML> [-C | --check]
Dry run
 

Ansibl­e-g­alaxy

[colle­ction | role] list
List installed collec­tions or roles
install <ga­lax­y.r­epo> -p ./roles
Install the role into ./role­s/g­ala­xy.repo folder

ansible

all -m ping
Check if hosts are reachable
<HO­ST> -m setup
Gather facts for <HO­ST>
<HO­ST> -m setup --tree /tmp/file
Save facts in </t­mp/­fil­e>
all -m setup -a 'filte­r=a­nsi­ble­_di­str­ibu­tion*'
Get only specific facts on all hosts
<GR­OUP> -a "ip a"
Exec arbitrary cmd on hosts

Ansibl­e-vault

create <fi­leN­ame>
edit <fi­leN­ame>
Will ask you for the password when editor open and encrypt the file back when you exit editor
decrypt <fi­leN­ame>
encrypt <fi­leN­ame>
view <fi­leN­ame>

ansibl­e-c­onfig

list
List all possible config­ura­tions
view
Show current config
dump
Display all current config value and where it is set
 

ansibl­e-i­nve­ntory [-i INVENTORY]

--graph
Show inventory graph
--list
Display hosts info
--host <HO­ST>
Display host info
-i [INVEN­TORY] -y
Display inventory with processed variables