Wednesday, November 7, 2018

Ansible basic command structure

create a folder and cd to it
exercise1

in that create a text file to list all vms:inventory
---------
192.168.33.20
192.168.33.30


ansible all
ansible *

Above two will execute on all machines in the inventory.

ansible 192.168.33.20 -i inventory -u vagrant -m ping -k

-k will prompt for password interactively.

If you get any error as host key checking enabled.
then we need to create ssh fingerprint.

which can be created once you access with ssh directly and prompted during connection.
ssh vagrant@192.168.33.20

file is created on the machine, ~/.ssh/known_hosts

Then you can retry the ansible command.

-v for verbose mode.you can type at end.
-vv more detail, shows the remote module which is being compiled,etc.
-vvv even more detail, including the connection,compiling,etc

-m command -a <any command on remote system>
example, to update all machines.

ansible all -i inventory -u vagrant -m command -a "/usr/sbin/yum update -y"

THe command module, is the default, so we can directly call the above command just with -a

Like command, we have shell module.

Difference is shell module runs with linux shell environment and command module runs with python.
With shell module, we have access to shell variables.Like $home ,$path


Ansible basic command structure.:







No comments:

Post a Comment