This tutorial will help you understand how Ansible orchestrates Docker containers at least for a dev environment.

We’ll use Vagrant as a local server where containers with microservices are deployed.

Microservices work Flow

Conf file for dev environment:

export MYSQL_ROOT_PASSWORD=mysql-root-password
export MYSQL_USER=mysql-user
export MYSQL_PASSWORD=mysql-password
export MYSQL_DATABASE=mysql-database
export NEWUSER=newuser
export SSH_KEY=~/.ssh/id_rsa.pub

vagrant/Vagrantfile

Vagrant.configure(2) do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.network "forwarded_port", guest: 80, host: 8888
  config.vm.network "forwarded_port", guest: 443, host: 8443
  config.vm.synced_folder "./vmwordpress", "/var/www/html"
  config.vm.provision "ansible" do |ansible|
    ansible.playbook = "../ansible/server_setup.yml"
    ansible.sudo = true
    ansible.extra_vars = { ansible_ssh_user: 'vagrant' }
    ansible.host_key_checking = false
  end
end
We’ll use Ubuntu 14 for the Vagrant OS, and we’ll use port forwarding (8888(local)-80(Vagrant)).

Also, we will use /var/www/html of Vagrant to store ./vmwordpress.

vagrant/development_build.sh:

#!/bin/bash
source ../.env
rm -rf ./vmwordpress/*
vagrant up
export ANSIBLE_HOST_KEY_CHECKING=False
ansible-playbook --user=vagrant --inventory-file=./.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory ../ansible/new_wordpress_setup.yml --extra-vars "site_name=$1 wordpress_version=$2 edit=True"
sudo ssh -p 2222 -gNfL 80:localhost:80 vagrant@localhost -i .vagrant/machines/default/virtualbox/private_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no

The core of this tutorial is the line of “ansible-playbook”:

  1. The user is vagrant.
  2. The inventory file will be created after the vagrant box is created.
  3. Then, we’ll run ansible/new_wordpress_setup.yml.
  4. We’re going to pass in two variables via command line: FQDN and WP version (4.5.3).

#microservices #ansible #cloud #docker #developer

How to Deploy MicroServices via Ansible in Cloud Platform
1.95 GEEK