Example 1
hosts.ini
[centos]
provisioner ansible_connection=local
centos1 ansible_host=192.168.77.22
[ubuntu]
ubuntu1 ansible_host=192.168.77.23
Execute the whoami
command on all hosts.
ansible all -m command -a whoami
Tip
The default user used by the SSH client is the same as your current user on the provisioner.
Add the --become
or -b
flag to the previous command. Notice the differences in the command's outputs.
ansible all -m command -a whoami -b
The --become
directive instructs Ansible to take the identity of the superuser on the remote hosts. This feature requires on of the following options
- passwordless
sudo
access is enabled for the remote user - the name and password of the associated superuser are passed to Ansible