← retour aux snippets

ansible: ad-hoc ping et commandes

Tester la connectivité et lancer une commande sur un groupe via l'inventaire.

bash config #ansible#ping#ad-hoc

objectif

Valider rapidement l’accès et exécuter une commande unique.

code minimal

ansible -i inventory all -m ping
ansible -i inventory web -m command -a 'uname -a'

utilisation

# become
ansible -i inventory db -b -m command -a 'id'

variante(s) utile(s)

# variable inline
ansible -i inventory web -m shell -a 'echo $HOSTNAME'

notes

  • préférez des modules idempotents (apt, file, template) plutôt que shell.
  • configurez SSH et become dans ansible.cfg.