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
- We define the servers in a ini inventory file. Two servers in a group called dev with a ssh connection via private key
[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
- Example:
ansible -i ansible/hosts-remote.ini --playbook-dir=ansible -a "echo nico" dev
ansibleHostName1 | CHANGED | rc=0 >>
nico
ansibleHostName2 | CHANGED | rc=0 >>
nico