Implemented idempotent docker run and user creation for mariadb

This commit is contained in:
Evgeniy L 2015-04-22 16:59:24 +03:00
parent 55a5e8821f
commit 9a320cd300
4 changed files with 14 additions and 5 deletions

View File

@ -2,6 +2,10 @@
- hosts: [service/haproxy]
sudo: yes
tasks:
- shell: docker ps | grep -q {{name}}
ignore_errors: true
register: is_running
- file: state=directory path=/etc/solar/{{name}}
# TODO Remove hardcoded path
- template: src=/vagrant/examples/resources/templates/haproxy.cfg.j2 dest=/etc/solar/{{name}}/haproxy.cfg backup=yes
@ -10,3 +14,4 @@
--privileged \
-v /etc/solar/{{name}}/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro \
--name {{name}} {{image}}
when: is_running|failed

View File

@ -2,6 +2,9 @@
- hosts: [service/keystone]
sudo: yes
tasks:
- shell: docker ps | grep -q {{name}}
ignore_errors: true
register: is_running
# NOTE(eli): specify restart policy (--restart parameter) for
# keystone conatiner if there are more than 2 keystone containers
# to be deployed, they both will perform db migration and will fail,
@ -14,3 +17,4 @@
-e "MARIADB_SERVICE_HOST={{db_host}}" \
--restart="on-failure:10" \
--name {{name}} {{image}}
when: is_running|failed

View File

@ -2,6 +2,9 @@
- hosts: [service/mariadb]
sudo: yes
tasks:
- shell: docker ps | grep -q {{name}}
ignore_errors: true
register: is_running
- shell: docker run \
-d \
--net="host" \
@ -10,3 +13,4 @@
-e "MARIADB_ROOT_PASSWORD={{root_password}}" \
-e "BIND_ADDRESS={{bind_ip}}" \
{{image}}
when: is_running|failed

View File

@ -2,11 +2,7 @@
- hosts: [service/mariadb]
sudo: yes
tasks:
- command: docker exec -t {{name}} \
mysql -uroot -p{{root_password}} \
-e "CREATE USER '{{item.name}}'@'%' IDENTIFIED BY '{{item.password}}'"
with_items: users
# NOTE(eli): it will automatically create user if it does not exist
- command: docker exec -t {{name}} \
mysql -uroot -p{{root_password}} -e "GRANT ALL PRIVILEGES ON *.* TO '{{item.name}}'@'%' WITH GRANT OPTION"
with_items: users