From a4153da9b649c2eac8c970644a7fd906791921b7 Mon Sep 17 00:00:00 2001 From: Evgeniy L Date: Mon, 20 Apr 2015 17:37:09 +0300 Subject: [PATCH] Changed resources to use templating language and tags, without hardcoded values --- examples/check_deployment.sh | 1 + examples/resources/docker.yml | 2 +- examples/resources/docker2.yml | 4 +-- examples/resources/haproxy.yml | 31 ++++++++++++--------- examples/resources/keystone.yml | 5 +++- examples/resources/mariadb.yml | 6 +++- examples/resources/simple/haproxy/run.yml | 11 ++++---- examples/resources/simple/keystone/run.yml | 18 ++++++++---- examples/resources/simple/mariadb/run.yml | 10 ++++--- examples/resources/simple/mariadb/users.yml | 14 +++++----- examples/resources/simple/mariadb/wait.yml | 4 +-- examples/resources/templates/haproxy.cfg.j2 | 2 +- 12 files changed, 65 insertions(+), 43 deletions(-) diff --git a/examples/check_deployment.sh b/examples/check_deployment.sh index 9aadaee6..ece1a7e6 100755 --- a/examples/check_deployment.sh +++ b/examples/check_deployment.sh @@ -1,3 +1,4 @@ #!/bin/bash docker exec -it keystone-test keystone --debug --os-username admin --os-password password --os-tenant-name admin --os-auth-url http://10.0.0.3:8080/v2.0 role-list + diff --git a/examples/resources/docker.yml b/examples/resources/docker.yml index c52caecb..187bd8c2 100644 --- a/examples/resources/docker.yml +++ b/examples/resources/docker.yml @@ -1,4 +1,4 @@ -id: docker_1 +id: docker class: docker type: resource handler: ansible diff --git a/examples/resources/docker2.yml b/examples/resources/docker2.yml index 1f080b41..e985ef2a 100644 --- a/examples/resources/docker2.yml +++ b/examples/resources/docker2.yml @@ -11,6 +11,4 @@ input: node: link: node_2 tags: - - service/docker - - env/test_env - + - service/docker2 diff --git a/examples/resources/haproxy.yml b/examples/resources/haproxy.yml index 826d81fc..02f2b7cf 100644 --- a/examples/resources/haproxy.yml +++ b/examples/resources/haproxy.yml @@ -1,4 +1,5 @@ id: haproxy +class: haproxy type: resource handler: ansible version: v1 @@ -8,20 +9,24 @@ actions: remove: simple/haproxy/remove.yml input: - name: haproxy - image: haproxy:1.5 + name: haproxy-test + image: 'haproxy:1.5' + services: - # TODO Here we should be able to remove hardcoded data, - # we can have sveral keystone backaends, and other different - # services. Without hardcoding of specific node we should - # get the nodes with specific tag. - # * get all nodes which use all tags with 'service/keystone' - # * iterate over this list here - # * pass correct port and ip address - - service_name: keystone - bind: "*:8080" + - service_name: keystone-admin + bind: '*:8080' backends: - - remote_name: keystone-test - remote_addr: 10.0.0.3:35357 + 'with_items': '{{ with_tags("service/keystone") }}' + 'item': + 'remote_name': '{{ item.name }}' + 'remote_addr': '{{ item.node.ip }}:{{ item.admin_port }}' + + - service_name: keystone-pub + bind: '*:8081' + backends: + with_items: '{{ with_tags("service/keystone") }}' + item: + remote_name: '{{ item.name }}' + remote_addr: '{{ item.node.ip }}:{{ item.public_port }}' tags: [service/haproxy] diff --git a/examples/resources/keystone.yml b/examples/resources/keystone.yml index ea19c5b4..22dc625a 100644 --- a/examples/resources/keystone.yml +++ b/examples/resources/keystone.yml @@ -1,4 +1,5 @@ id: keystone +class: keystone type: resource handler: ansible version: v1 @@ -8,8 +9,10 @@ actions: remove: simple/keystone/remove.yml input: + db_root_password: '{{ first_with_tags("entrypoint/mariadb").root_password }}' + db_host: '{{ first_with_tags("entrypoint/mariadb").node.ip }}' admin_port: 35357 - public_port: 5000 + public_port: 5000 name: keystone-test image: kollaglue/centos-rdo-keystone diff --git a/examples/resources/mariadb.yml b/examples/resources/mariadb.yml index 5ccf8fe0..0826b278 100644 --- a/examples/resources/mariadb.yml +++ b/examples/resources/mariadb.yml @@ -1,4 +1,5 @@ id: mariadb +class: mariadb type: resource handler: ansible version: v1 @@ -10,10 +11,13 @@ actions: users: simple/mariadb/users.yml input: + bind_ip: "{{ this.node.ip }}" name: mariadb-test image: kollaglue/fedora-rdo-mariadb-app root_password: test1 users: - name: test1 password: test1 -tags: [service/mariadb] +tags: + - service/mariadb + - entrypoint/mariadb diff --git a/examples/resources/simple/haproxy/run.yml b/examples/resources/simple/haproxy/run.yml index f863f9d4..f9aff6b3 100644 --- a/examples/resources/simple/haproxy/run.yml +++ b/examples/resources/simple/haproxy/run.yml @@ -1,12 +1,13 @@ -- hosts: [haproxy] +- hosts: [service/haproxy] sudo: yes tasks: - - file: state=directory path=/etc/solar/{{haproxy.name}} + - file: state=directory path=/etc/solar/{{name}} # TODO Remove hardcoded path - - template: src=/vagrant/examples/resources/templates/haproxy.cfg.j2 dest=/etc/solar/{{haproxy.name}}/haproxy.cfg backup=yes + - template: src=/vagrant/examples/resources/templates/haproxy.cfg.j2 dest=/etc/solar/{{name}}/haproxy.cfg backup=yes + - shell: docker rm -f {{name}} || true - shell: docker run -d \ --net="host" \ --privileged \ - -v /etc/solar/{{haproxy.name}}/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro \ - --name {{haproxy.name}} {{haproxy.image}} + -v /etc/solar/{{name}}/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro \ + --name {{name}} {{image}} diff --git a/examples/resources/simple/keystone/run.yml b/examples/resources/simple/keystone/run.yml index db051e8c..4891a874 100644 --- a/examples/resources/simple/keystone/run.yml +++ b/examples/resources/simple/keystone/run.yml @@ -1,9 +1,17 @@ -- hosts: [keystone] +- hosts: [service/keystone] sudo: yes tasks: + - shell: docker rm -f {{name}} || true + # 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, + # the container which is first should create database, the rest of + # the containers should be just restarted - shell: docker run -d --net="host" --privileged \ - -e "DB_ROOT_PASSWORD={{mariadb.root_password}}" \ - -e "KEYSTONE_PUBLIC_SERVICE_PORT={{keystone.public_port}}" \ - -e "KEYSTONE_ADMIN_SERVICE_PORT={{keystone.admin_port}}" \ - --name {{keystone.name}} {{keystone.image}} + -e "DB_ROOT_PASSWORD={{db_root_password}}" \ + -e "KEYSTONE_PUBLIC_SERVICE_PORT={{public_port}}" \ + -e "KEYSTONE_ADMIN_SERVICE_PORT={{admin_port}}" \ + -e "MARIADB_SERVICE_HOST={{db_host}}" \ + --restart="on-failure:10" \ + --name {{name}} {{image}} diff --git a/examples/resources/simple/mariadb/run.yml b/examples/resources/simple/mariadb/run.yml index d5fac68e..839eaf36 100644 --- a/examples/resources/simple/mariadb/run.yml +++ b/examples/resources/simple/mariadb/run.yml @@ -1,11 +1,13 @@ -- hosts: [mariadb] +- hosts: [service/mariadb] sudo: yes tasks: + - shell: docker rm -f {{name}} || true - shell: docker run \ -d \ --net="host" \ --privileged \ - --name {{mariadb.name}} \ - -e "MARIADB_ROOT_PASSWORD={{mariadb.root_password}}" \ - {{mariadb.image}} + --name {{name}} \ + -e "MARIADB_ROOT_PASSWORD={{root_password}}" \ + -e "BIND_ADDRESS={{bind_ip}}" \ + {{image}} diff --git a/examples/resources/simple/mariadb/users.yml b/examples/resources/simple/mariadb/users.yml index ae591c6d..4d20ed83 100644 --- a/examples/resources/simple/mariadb/users.yml +++ b/examples/resources/simple/mariadb/users.yml @@ -1,12 +1,12 @@ -- hosts: [mariadb] +- hosts: [service/mariadb] sudo: yes tasks: - - command: docker exec -t {{mariadb.name}} \ - mysql -uroot -p{{mariadb.root_password}} \ + - command: docker exec -t {{name}} \ + mysql -uroot -p{{root_password}} \ -e "CREATE USER '{{item.name}}'@'%' IDENTIFIED BY '{{item.password}}'" - with_items: mariadb.users + with_items: users - - command: docker exec -t {{mariadb.name}} \ - mysql -uroot -p{{mariadb.root_password}} -e "GRANT ALL PRIVILEGES ON *.* TO '{{item.name}}'@'%' WITH GRANT OPTION" - with_items: mariadb.users + - command: docker exec -t {{name}} \ + mysql -uroot -p{{root_password}} -e "GRANT ALL PRIVILEGES ON *.* TO '{{item.name}}'@'%' WITH GRANT OPTION" + with_items: users diff --git a/examples/resources/simple/mariadb/wait.yml b/examples/resources/simple/mariadb/wait.yml index a29b8ad3..40a2ee45 100644 --- a/examples/resources/simple/mariadb/wait.yml +++ b/examples/resources/simple/mariadb/wait.yml @@ -1,8 +1,8 @@ -- hosts: [mariadb] +- hosts: [service/mariadb] sudo: yes tasks: - - shell: docker exec -t {{mariadb.name}} mysql -p{{mariadb.root_password}} -uroot -e "select 1" + - shell: docker exec -t {{name}} mysql -p{{root_password}} -uroot -e "select 1" register: result until: result.rc == 0 retries: 10 diff --git a/examples/resources/templates/haproxy.cfg.j2 b/examples/resources/templates/haproxy.cfg.j2 index fa1e3410..8bdb826b 100644 --- a/examples/resources/templates/haproxy.cfg.j2 +++ b/examples/resources/templates/haproxy.cfg.j2 @@ -17,7 +17,7 @@ listen stats :1936 stats uri / #stats auth Username:Password -{% for service in haproxy.services %} +{% for service in services %} listen {{ service.service_name }} bind {{service.bind}} {% for backend in service.backends %}