Running arbitrary commands

The Ansible command can also be used to run arbitrary commands on remote servers. In the following example, we will run the df command only on all hosts matching 54.175.86.* for their public IP address (you will need to adapt this command to match your instance public IP as returned in the ping command from the previous example):

$ ansible --private-key ~/.ssh/EffectiveDevOpsAWS.pem '54.175.86.*' 
-a 'df -h' 54.175.86.38 | success | rc=0 >> Filesystem Size Used Avail Use% Mounted on /dev/xvda1 7.8G 1.3G 6.5G 16% /
devtmpfs        490M   56K  490M   1% /dev
tmpfs           498M     0  498M   0% /dev/shm  

Now that we have a basic understanding of how Ansible works, we can start combining calls to different Ansible modules to put in place our automation. This is called creating a playbook.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset