Table of Contents

Ansible - Ad-hoc command

About

Adhoc command 1) are command executed as in the shell via ansible.

You can therefore execute command on a whole cluster of server.

This is because the default module of the ansible command line is command

Example

[dev]
ansibleHostName1  ansible_host=hostname1  ansible_ssh_private_key_file=./privateKey.pem ansible_user=user
ansibleHostName2  ansible_host=hostname2  ansible_ssh_private_key_file=./privateKey.pem ansible_user=user
ansible -i ansible/hosts-remote.ini --playbook-dir=ansible -a "echo nico" dev 
ansibleHostName1 | CHANGED | rc=0 >>
nico

ansibleHostName2 | CHANGED | rc=0 >>
nico