Javad Zahrabi

Ansible

Agentless config management & orchestration over SSH.

Official docs

Ad-hoc commands

  • ansible all -m ping

    Cheapest health check across the inventory — confirms SSH + python.

  • ansible all -m setup

    Dump every fact (gathered variable) for every host.

  • ansible web -m shell -a 'uptime'

    Run an arbitrary shell command on a host group.

  • ansible web -m apt -a 'name=nginx state=present' -b

    Install a package — -b becomes root.

  • ansible all -m copy -a 'src=./hosts dest=/etc/hosts' -b

    Push a file to every host.

Inventory

  • ansible-inventory --list

    Print the inventory as JSON. Useful for dynamic inventory debugging.

  • ansible-inventory --graph

    Tree view of groups + hosts.

  • ansible all --list-hosts

    Just the host names matching a pattern.

  • ansible -i hosts.ini web --list-hosts

    Use a non-default inventory file.

Playbooks

  • ansible-playbook site.yml

    Run a playbook against the inventory.

  • ansible-playbook site.yml --check

    Dry-run: report what would change without applying.

  • ansible-playbook site.yml --diff

    Show before/after diffs for files Ansible modifies.

  • ansible-playbook site.yml --tags 'nginx,tls'

    Only tasks tagged matching.

  • ansible-playbook site.yml --limit web01

    Only run against one host (or pattern).

  • ansible-playbook site.yml -K

    Prompt for sudo (become) password.

Vault (secrets)

  • ansible-vault create secrets.yml

    Create a new encrypted file.

  • ansible-vault edit secrets.yml

    Decrypt → open in $EDITOR → re-encrypt on save.

  • ansible-vault view secrets.yml

    Print the decrypted contents to stdout.

  • ansible-vault encrypt_string 'shh' --name 'db_password'

    Encrypt a single value to paste into a YAML file.

  • ansible-playbook site.yml --ask-vault-pass

    Prompt for the vault password at runtime.

Roles & Galaxy

  • ansible-galaxy init my_role

    Scaffold a fresh role with the standard directory layout.

  • ansible-galaxy install -r requirements.yml

    Pull external roles/collections from Galaxy or git.

  • ansible-galaxy collection install community.general

    Install a collection.

  • ansible-galaxy role list

    List installed roles + their versions.