Executing modules

The ansible command is the main command that drives the execution of the different modules on the remote hosts.

Modules are libraries that can be executed directly on remote hosts. Ansible comes with a number of modules as listed at http://bit.ly/24rU0yk. In addition to the standard modules, you can also create your own modules using Python. There are modules for most common use cases and technologies. The first module we will see is a simple module called ping that tries to connect to a host and returns pong if the host is usable.

Module documentation can also be accessed using the ansible-doc command, that is,
$ ansible-doc ping.

In the Creating our Ansible playground section, we created a new EC2 instance using CloudFormation. So far, we haven't looked up its IP address. Using Ansible and the ping command can discover that information. As mentioned before, we need to be in the ansible folder to run the ansible command. The command is:

$ ansible--private-key ~/.ssh/EffectiveDevOpsAWS.pem ec2 -m ping
54.175.86.38 | success >> {
    "changed": false,
    "ping": "pong"
}  

As we can see, Ansible was able to find our EC2 instance querying the AWS EC2 API and the instance is ready to be used.

Configuring SSH
As Ansible relies heavily on SSH, it is worth spending a bit of time on configuring SSH via the $HOME/.ssh/config file. For instance, you can use the following options to avoid having to specify --private-key and -u in the preceding example:
IdentityFile ~/.ssh/EffectiveDevOpsAWS.pem
User ec2-user
StrictHostKeyChecking no
PasswordAuthentication no
ForwardAgent yes
Once configured, you won't need to provide the --private-key option to Ansible.

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

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