From c8dfd99dc982367e933a1ba9ff3192f1dbbf4d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Mass=C3=A9?= Date: Mon, 26 Jun 2017 19:51:55 +0200 Subject: [PATCH] switch back to flat variable names --- roles/3scale/tasks/apicast_cors.yml | 10 +++---- roles/3scale/tasks/main.yml | 39 ++++++++++------------------ roles/3scale/tasks/patch_apicast.yml | 14 +++++----- roles/3scale/tasks/status.yml | 4 +-- roles/3scale/tasks/wait_for.yml | 6 ++--- roles/3scale/vars/main.yml | 17 ++++++------ 6 files changed, 39 insertions(+), 51 deletions(-) diff --git a/roles/3scale/tasks/apicast_cors.yml b/roles/3scale/tasks/apicast_cors.yml index 7033f38..3fb2039 100644 --- a/roles/3scale/tasks/apicast_cors.yml +++ b/roles/3scale/tasks/apicast_cors.yml @@ -1,19 +1,19 @@ --- - + - name: Download 'apicast_cors.lua' - get_url: dest=apicast_cors.lua url={{ threescale_options.apicast_cors_lua }} + get_url: dest=apicast_cors.lua url={{ threescale_apicast_cors_lua }} - name: Download 'cors.conf' - get_url: dest=cors.conf url={{ threescale_options.apicast_cors_conf }} + get_url: dest=cors.conf url={{ threescale_apicast_cors_conf }} - name: Create ConfigMap 'apicast-cors' - command: oc create configmap apicast-cors --from-file=apicast_cors.lua -n "{{ threescale_options.project }}" + command: oc create configmap apicast-cors --from-file=apicast_cors.lua -n "{{ threescale_project }}" register: oc failed_when: oc.rc > 0 and 'Error from server (AlreadyExists):' not in oc.stderr changed_when: oc.rc == 0 - name: Create ConfigMap 'cors-conf' - command: oc create configmap cors-conf --from-file=cors.conf -n "{{ threescale_options.project }}" + command: oc create configmap cors-conf --from-file=cors.conf -n "{{ threescale_project }}" register: oc failed_when: oc.rc > 0 and 'Error from server (AlreadyExists):' not in oc.stderr changed_when: oc.rc == 0 diff --git a/roles/3scale/tasks/main.yml b/roles/3scale/tasks/main.yml index 2df2a7d..e069a00 100644 --- a/roles/3scale/tasks/main.yml +++ b/roles/3scale/tasks/main.yml @@ -1,27 +1,16 @@ --- - - name: Create an empty threescale_options variable if it does not exist - set_fact: - threescale_options: {} - when: threescale_options is not defined - tags: vars - - - name: Provision default values for the 3scale_options - set_fact: - threescale_options: "{{ threescale_default_options|combine(threescale_options) }}" - tags: vars - - name: Get a list of existing projects command: oc get projects -o name register: oc_get_projects changed_when: false - name: Create a new project for 3scale - command: oc new-project "{{ threescale_options.project }}" - when: '"project/" ~ threescale_options.project not in oc_get_projects.stdout_lines' + command: oc new-project "{{ threescale_project }}" + when: '"project/" ~ threescale_project not in oc_get_projects.stdout_lines' - name: Process the OpenShift Template and create the OpenShift objects for the 3scale API Management Platform - shell: oc process -f "{{ threescale_options.template }}" -p "TENANT_NAME={{ threescale_options.tenant_name }}" -p "WILDCARD_DOMAIN={{ threescale_options.wildcard_domain }}" -n "{{ threescale_options.project }}" | oc create -f - -n "{{ threescale_options.project }}" + shell: oc process -f "{{ threescale_template }}" -p "TENANT_NAME={{ threescale_tenant_name }}" -p "WILDCARD_DOMAIN={{ threescale_wildcard_domain }}" -n "{{ threescale_project }}" | oc create -f - -n "{{ threescale_project }}" register: oc failed_when: oc.rc > 0 and 'Error from server (AlreadyExists):' not in oc.stderr changed_when: oc.rc == 0 @@ -34,7 +23,7 @@ tags: status - name: Deploy the storage tier (MySQL, Redis and Memcache) without any replicas - command: oc rollout latest "{{ item }}" -n "{{ threescale_options.project }}" + command: oc rollout latest "{{ item }}" -n "{{ threescale_project }}" with_items: - backend-redis - system-memcache @@ -44,7 +33,7 @@ tags: rollout - name: Scale the storage tier (MySQL, Redis and Memcache) - command: oc scale dc "{{ item }}" --replicas=1 -n "{{ threescale_options.project }}" + command: oc scale dc "{{ item }}" --replicas=1 -n "{{ threescale_project }}" with_items: - backend-redis - system-memcache @@ -64,14 +53,14 @@ tags: status - name: Deploy the backend-listener without any replicas - command: oc rollout latest "{{ item }}" -n "{{ threescale_options.project }}" + command: oc rollout latest "{{ item }}" -n "{{ threescale_project }}" with_items: - backend-listener when: item not in deployment_configs tags: rollout - name: Scale backend-listener - command: oc scale dc "{{ item }}" --replicas=1 -n "{{ threescale_options.project }}" + command: oc scale dc "{{ item }}" --replicas=1 -n "{{ threescale_project }}" with_items: - backend-listener when: item not in replication_controllers @@ -85,7 +74,7 @@ tags: status - name: Deploy everything else without any replicas - command: oc rollout latest "{{ item }}" -n "{{ threescale_options.project }}" + command: oc rollout latest "{{ item }}" -n "{{ threescale_project }}" with_items: - backend-listener - backend-worker @@ -100,7 +89,7 @@ tags: rollout - name: Scale system-app, system-resque and system-sidekiq - command: oc scale dc "{{ item }}" --replicas=1 -n "{{ threescale_options.project }}" + command: oc scale dc "{{ item }}" --replicas=1 -n "{{ threescale_project }}" with_items: - system-app - system-resque @@ -118,7 +107,7 @@ tags: status - name: Scale backend-cron, backend-worker and system-sphinx - command: oc scale dc "{{ item }}" --replicas=1 -n "{{ threescale_options.project }}" + command: oc scale dc "{{ item }}" --replicas=1 -n "{{ threescale_project }}" with_items: - backend-worker - backend-cron @@ -136,7 +125,7 @@ tags: status - name: Deploy apicast-staging, apicast-production - command: oc scale dc "{{ item }}" --replicas=1 -n "{{ threescale_options.project }}" + command: oc scale dc "{{ item }}" --replicas=1 -n "{{ threescale_project }}" with_items: - apicast-staging #- apicast-production @@ -152,17 +141,17 @@ tags: status - name: Get Admin Username - command: oc get dc system-app -n "{{ threescale_options.project }}" -o 'jsonpath={.spec.template.spec.containers[0].env[?(@.name=="USER_LOGIN")].value}' + command: oc get dc system-app -n "{{ threescale_project }}" -o 'jsonpath={.spec.template.spec.containers[0].env[?(@.name=="USER_LOGIN")].value}' register: username changed_when: false tags: status - name: Get Admin Password - command: oc get dc system-app -n "{{ threescale_options.project }}" -o 'jsonpath={.spec.template.spec.containers[0].env[?(@.name=="USER_PASSWORD")].value}' + command: oc get dc system-app -n "{{ threescale_project }}" -o 'jsonpath={.spec.template.spec.containers[0].env[?(@.name=="USER_PASSWORD")].value}' register: password changed_when: false tags: status - name: 3scale is ready ! - debug: msg="Login on https://{{ threescale_options.tenant_name }}-admin.{{ threescale_options.wildcard_domain }} with username = '{{ username.stdout }}' and password = '{{ password.stdout }}'" + debug: msg="Login on https://{{ threescale_tenant_name }}-admin.{{ threescale_wildcard_domain }} with username = '{{ username.stdout }}' and password = '{{ password.stdout }}'" tags: status diff --git a/roles/3scale/tasks/patch_apicast.yml b/roles/3scale/tasks/patch_apicast.yml index 57bbeb0..ecd0c28 100644 --- a/roles/3scale/tasks/patch_apicast.yml +++ b/roles/3scale/tasks/patch_apicast.yml @@ -3,30 +3,30 @@ - debug: msg="Updating {{ item }}" - name: Check if APICast's DC has volumes - command: oc get dc {{ item }} -o jsonpath='{range .spec.template.spec.volumes[*]}{.name}{"\n"}{end}' -n "{{ threescale_options.project }}" + command: oc get dc {{ item }} -o jsonpath='{range .spec.template.spec.volumes[*]}{.name}{"\n"}{end}' -n "{{ threescale_project }}" register: volumes changed_when: false - name: Add volume 'apicast-cors' - command: 'oc set volume dc/{{ item }} -n {{ threescale_options.project }} --add --name=apicast-cors --mount-path /opt/app-root/src/src/apicast_cors.lua --source=''{"configMap":{"name":"apicast-cors","items":[{"key":"apicast_cors.lua","path":"apicast_cors.lua"}]}}'' ' + command: 'oc set volume dc/{{ item }} -n {{ threescale_project }} --add --name=apicast-cors --mount-path /opt/app-root/src/src/apicast_cors.lua --source=''{"configMap":{"name":"apicast-cors","items":[{"key":"apicast_cors.lua","path":"apicast_cors.lua"}]}}'' ' when: "'apicast-cors' not in volumes.stdout_lines" - name: Add volume 'cors-conf' - command: 'oc set volume dc/{{ item }} -n {{ threescale_options.project }} --add --name=cors-conf --mount-path /opt/app-root/src/apicast.d/cors.conf --source=''{"configMap":{"name":"cors-conf","items":[{"key":"cors.conf","path":"cors.conf"}]}}'' ' + command: 'oc set volume dc/{{ item }} -n {{ threescale_project }} --add --name=cors-conf --mount-path /opt/app-root/src/apicast.d/cors.conf --source=''{"configMap":{"name":"cors-conf","items":[{"key":"cors.conf","path":"cors.conf"}]}}'' ' when: "'cors-conf' not in volumes.stdout_lines" - name: Check if APICast's DC has already been patched - command: oc get dc {{ item }} -o jsonpath='{range .spec.template.spec.containers[*].volumeMounts[?(@.subPath)]}{.name}{"\n"}{end}' -n "{{ threescale_options.project }}" + command: oc get dc {{ item }} -o jsonpath='{range .spec.template.spec.containers[*].volumeMounts[?(@.subPath)]}{.name}{"\n"}{end}' -n "{{ threescale_project }}" register: patched changed_when: false - name: Patch volume 'apicast-cors' - command: 'oc patch dc/{{ item }} -n {{ threescale_options.project }} --type=json -p ''[ {"op": "add", "path": "/spec/template/spec/containers/0/volumeMounts/0/subPath", "value":"apicast_cors.lua"} ]'' ' + command: 'oc patch dc/{{ item }} -n {{ threescale_project }} --type=json -p ''[ {"op": "add", "path": "/spec/template/spec/containers/0/volumeMounts/0/subPath", "value":"apicast_cors.lua"} ]'' ' when: "'apicast-cors' not in patched.stdout_lines" - name: Patch volume 'cors-conf' - command: 'oc patch dc/{{ item }} -n {{ threescale_options.project }} --type=json -p ''[ {"op": "add", "path": "/spec/template/spec/containers/0/volumeMounts/1/subPath", "value":"cors.conf"} ]'' ' + command: 'oc patch dc/{{ item }} -n {{ threescale_project }} --type=json -p ''[ {"op": "add", "path": "/spec/template/spec/containers/0/volumeMounts/1/subPath", "value":"cors.conf"} ]'' ' when: "'cors-conf' not in patched.stdout_lines" - name: Add environment variable APICAST_MODULE to the APICast DeploymentConfig - command: oc env dc/{{ item }} APICAST_MODULE=apicast_cors -n {{ threescale_options.project }} + command: oc env dc/{{ item }} APICAST_MODULE=apicast_cors -n {{ threescale_project }} diff --git a/roles/3scale/tasks/status.yml b/roles/3scale/tasks/status.yml index 18b7cfe..1a68db8 100644 --- a/roles/3scale/tasks/status.yml +++ b/roles/3scale/tasks/status.yml @@ -1,7 +1,7 @@ --- - name: Retrieve current ReplicationController status - command: 'oc get rc -o json -n "{{ threescale_options.project }}"' + command: 'oc get rc -o json -n "{{ threescale_project }}"' register: rc_state changed_when: false @@ -12,7 +12,7 @@ - name: Retrieve current DeploymentConfig status - command: 'oc get dc -o json -n "{{ threescale_options.project }}"' + command: 'oc get dc -o json -n "{{ threescale_project }}"' register: dc_state changed_when: false diff --git a/roles/3scale/tasks/wait_for.yml b/roles/3scale/tasks/wait_for.yml index 3c8f2b6..dafb56b 100644 --- a/roles/3scale/tasks/wait_for.yml +++ b/roles/3scale/tasks/wait_for.yml @@ -1,9 +1,9 @@ --- - name: Wait for all pending deployments to become ready - command: 'oc get rc -o json -n "{{ threescale_options.project }}"' + command: 'oc get rc -o json -n "{{ threescale_project }}"' register: rc_state changed_when: false - retries: "{{ threescale_options.retries }}" - delay: "{{ threescale_options.delay }}" + retries: "{{ threescale_retries }}" + delay: "{{ threescale_delay }}" until: 'rc_state.stdout |from_json |json_query(''items[? status.replicas != `0` && (status.readyReplicas == ""|| status.readyReplicas == `0`) ].metadata.annotations."openshift.io/deployment-config.name"'') |intersect(pod_to_wait) |length == 0' diff --git a/roles/3scale/vars/main.yml b/roles/3scale/vars/main.yml index 7ae8e7f..f5ae33d 100644 --- a/roles/3scale/vars/main.yml +++ b/roles/3scale/vars/main.yml @@ -1,11 +1,10 @@ --- - threescale_default_options: - template: https://raw.githubusercontent.com/nmasse-itix/OpenShift-Lab/master/roles/3scale/files/amp.json - project: 3scale - tenant_name: 3scale - wildcard_domain: "{{ openshift_master_default_subdomain }}" - delay: 5 - retries: 30 - apicast_cors_lua: https://raw.githubusercontent.com/3scale/apicast/cors-example/examples/cors/apicast_cors.lua - apicast_cors_conf: https://raw.githubusercontent.com/3scale/apicast/cors-example/examples/cors/cors.conf + threescale_template: https://raw.githubusercontent.com/nmasse-itix/OpenShift-Lab/master/roles/3scale/files/amp.json + threescale_project: 3scale + threescale_tenant_name: 3scale + threescale_wildcard_domain: "{{ openshift_master_default_subdomain }}" + threescale_delay: 5 + threescale_retries: 30 + threescale_apicast_cors_lua: https://raw.githubusercontent.com/3scale/apicast/cors-example/examples/cors/apicast_cors.lua + threescale_apicast_cors_conf: https://raw.githubusercontent.com/3scale/apicast/cors-example/examples/cors/cors.conf