By default, Ansible expects to find the custom libraries in the /usr/share/ansible folder. As previously when we looked at the inventory script in Chapter 3, Treating Your Infrastructure As Code, we can change this default behavior by editing the ansible.cfg file. We will make the necessary changes so that the library is being downloaded onto the host with the rest of the Ansible files. The simplest way to accomplish that is to create a new directory at the root of our ansible repository and put the library in it.
On your computer, open a Terminal and go to your ansible directory:
In the root directory of our ansible repository where the ansible.cfg lives, we are going to add the new directory library to store the AWS CodeDeploy ansible library:
$ mkdir library
Once the folder is created, we can download the ansible library in it:
$ curl -L http://bit.ly/2cRAtYo > library/aws_codedeploy
Lastly, we are going to edit the ansible.cfg file present in the root directory of the ansible repository to specify the location of that library folder as follows:
# update ansible.cfg [defaults] inventory = ./ec2.py remote_user = ec2-user become = True become_method = sudo become_user = root nocows = 1 library = library
We are now ready to start using the library. CodeDeploy is a service that we are likely to reuse over time as new services get added to our system. In order to keep our ansible repository code DRY, we are going to create an Ansible role dedicated to CodeDeploy.