This inventory file defines two hosts, which means two droplets will be created. It also specifies the location of the private key that will be used to connect to the Droplets. Make sure you have generated a private key on your local machine before continuing.
Step 4: Create the Playbooks
Open the digitalocean.yml file and add the following YAML config:
You will need to replace the <your_token> value that is assigned to the digital_ocean_token variable with your DigitalOcean token.
There are three tasks in the playbook above. The first task will add the public key of your SSH key located in ~/.ssh to your DigitalOcean account. The ID of the key will be stored in sshkey_result and used in the next task to assign it to the created Droplet.
The last task will store the hostnames and IP addresses of the Droplets in your local hosts file. Note: in a production environment, you will likely want to replace this task for a task that adds the IP addresses to your DNS servers.
Open the nginx.yml file and add the following YAML config:
Once the playbook above has finished, the hosts should be created and the IP addresses saved in your local hosts file (/etc/hosts). Now we can run the nginx.yml playbook to install NGINX on the Droplets by running the command below:
Tony is the founder and editor of GraspingTech, a blog which provides tutorials for Cloud Architects, DevOps Engineers and System Administrators. He has written over one hundred tech tutorials which have been read by more than a million people.