Part 7 — CLI Deep Dive¶
Chapter status: outline
This chapter is scoped but not yet written in full prose. The sections below define what each part will cover.
Ansible ships more command-line tools than most beginners ever discover. This chapter is a reference-grade tour of each one, what it's for, and the options that actually matter day to day.
Why This Exists¶
- Most tutorials teach
ansible-playbookand stop. Real operators also reach foransible-docto check module arguments mid-task,ansible-consoleto poke at hosts interactively, andansible-vaultconstantly — this chapter gives each tool its due.
Problem Statement¶
- Without knowing this toolkit exists, engineers reinvent things it already does: grepping module source instead of
ansible-doc, hand-editing secrets instead ofansible-vault, or writing throwaway playbooks instead ofansible-console/ad hocansiblecommands.
Internal Architecture¶
- All CLI entry points are thin wrappers around the same core library (
ansible.cli.*) — they share config loading, inventory parsing, and connection plugin machinery, which is why flags like-i,-l,-e,-vvvbehave consistently across tools.
Step-by-Step Explanation (per tool)¶
ansible— ad hoc module execution (ansible all -m ping,-a,-m,-b,-K).ansible-playbook— running playbooks; key flags:--check,--diff,--limit,--tags,--skip-tags,--start-at-task,-e,--syntax-check,--list-tasks,--list-hosts.ansible-config—list,dump,viewsubcommands to introspect effective configuration.ansible-doc—-lto list modules,<module>to show full argspec/docs/examples,-sfor a snippet.ansible-console— REPL-style ad hoc execution against inventory, with tab completion andbecome.ansible-galaxy—install,init,collection install,role init,list.ansible-vault—create,edit,encrypt,decrypt,view,rekey, andencrypt_stringfor inline secrets.ansible-test— sanity/unit/integration test runner (previewed here, covered fully in Volume 5).ansible-lint— rule-based playbook/role linting (previewed here, covered fully in Volume 5).ansible-navigator— TUI for running/inspecting playbooks against Execution Environments (previewed here, covered fully in Volume 4).
Production Best Practices¶
- Using
--check --diffin CI/PR pipelines before any real apply. - Using
ansible-config dump --only-changedto document non-default settings for a project instead of assuming teammates know the defaults.
Common Mistakes¶
- Running
ansible-playbookwithout--checkon unfamiliar playbooks against production inventory. - Not knowing
ansible-doc <module>exists and guessing at module argument names instead.
Performance Considerations¶
-f/--forksand-vvv/-vvvvverbosity flags and their cost — previewed here, covered fully in Volume 6.
Security Considerations¶
ansible-vaultkey management: password files vs.--vault-id, avoiding vault passwords in shell history or CI logs.
Interview Questions¶
- "What's the difference between
ansibleandansible-playbook?" - "How would you look up a module's exact arguments without opening a browser?"
- "How does
ansible-vaultprotect secrets in a playbook repository?"
Hands-On Lab¶
- Use
ansible-doc -l | grep copyto find thecopymodule,ansible-doc copyto read its arguments, then run it ad hoc withansible all -m copy -a "..."against a local test host.
Summary¶
- The CLI surface is larger than
ansible-playbookalone —ansible-docandansible-vaultin particular are tools you should be reaching for constantly, not occasionally.
Next¶
Continue to Part 8 — Inventory.