Created
July 6, 2018 14:01
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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