Docker-Ansible-AWS

As I have been regularly using Docker 🐳, Ansible, and AWS, I wanted to use all 3 technologies together. Multiple Docker containers can be deployed using Docker compose. However, the Docker Ansible modules also let you deploy multiple containers using a playbook. I wanted to try it so I deployed Docker containers using Ansible on AWS. The example written below contains 2 Docker containers (drupal & postgres) deployed on an EC2 container which has Ansible running on it.

Ansible Playbook:

---

-  name: Using Ansible to deploy containers
   hosts: localhost
   gather_facts: no

   tasks:

   - name: Deploying Drupal container
     docker_container:
       name: drupal
       image: drupal
       ports:
         - "80:80"
       volumes:
         - drupal-modules:/var/www/html/modules
         - drupal-profiles:/var/www/html/profiles
         - drupal-themes:/var/www/html/themes
         - drupal-sites:/var/www/html/sites

   - name: Deploying postgres container
     docker_container:
       name: database
       image: postgres
       ports:
         - "5432:5432"
       env:
         POSTGRES_PASSWORD: secret

Just like it would with Docker compose, the drupal site was up and running but this time using Docker containers deployed using Ansible.

Issues faced: