Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gustavomcarmo/e1966a5560dcd4eaf8aaf3165c262536 to your computer and use it in GitHub Desktop.
Save gustavomcarmo/e1966a5560dcd4eaf8aaf3165c262536 to your computer and use it in GitHub Desktop.
Just an example of Ansible playbook that runs docker-compose and then waits the MySQL container until it becomes ready. Tested on Ubuntu 18.04 LTS (Bionic Beaver).
---
- hosts: moodle
gather_facts: no
become: yes
tasks:
- name: Install required packages
apt:
name: "{{item}}"
update_cache: yes
loop:
- mysql-client
- python3-pip
- name: Update docker python package
pip:
name: docker
state: latest
- name: Install docker-compose python package
pip:
name: docker-compose
- name: Set up the Docker services
docker_service:
project_name: moodle
project_src: .
- name: Get MySQL container IP address
shell: docker inspect -f {% raw %}'{{ .NetworkSettings.Networks.moodle_default.IPAddress }}'{% endraw %} mysql
register: mysql_ip
- name: Wait until MySQL container is ready
shell: mysql -u root -pmoodle -h {{mysql_ip.stdout}} -e 'show databases;'
register: mysql_databases
until: mysql_databases.stdout.find('moodle') != -1
retries: 10
delay: 2
ignore_errors: yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment