Browse Source

switch back to flat variable names

master
Nicolas Massé 9 years ago
parent
commit
c8dfd99dc9
  1. 10
      roles/3scale/tasks/apicast_cors.yml
  2. 39
      roles/3scale/tasks/main.yml
  3. 14
      roles/3scale/tasks/patch_apicast.yml
  4. 4
      roles/3scale/tasks/status.yml
  5. 6
      roles/3scale/tasks/wait_for.yml
  6. 17
      roles/3scale/vars/main.yml

10
roles/3scale/tasks/apicast_cors.yml

@ -1,19 +1,19 @@
--- ---
- name: Download 'apicast_cors.lua' - 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' - 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' - 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 register: oc
failed_when: oc.rc > 0 and 'Error from server (AlreadyExists):' not in oc.stderr failed_when: oc.rc > 0 and 'Error from server (AlreadyExists):' not in oc.stderr
changed_when: oc.rc == 0 changed_when: oc.rc == 0
- name: Create ConfigMap 'cors-conf' - 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 register: oc
failed_when: oc.rc > 0 and 'Error from server (AlreadyExists):' not in oc.stderr failed_when: oc.rc > 0 and 'Error from server (AlreadyExists):' not in oc.stderr
changed_when: oc.rc == 0 changed_when: oc.rc == 0

39
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 - name: Get a list of existing projects
command: oc get projects -o name command: oc get projects -o name
register: oc_get_projects register: oc_get_projects
changed_when: false changed_when: false
- name: Create a new project for 3scale - name: Create a new project for 3scale
command: oc new-project "{{ threescale_options.project }}" command: oc new-project "{{ threescale_project }}"
when: '"project/" ~ threescale_options.project not in oc_get_projects.stdout_lines' 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 - 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 register: oc
failed_when: oc.rc > 0 and 'Error from server (AlreadyExists):' not in oc.stderr failed_when: oc.rc > 0 and 'Error from server (AlreadyExists):' not in oc.stderr
changed_when: oc.rc == 0 changed_when: oc.rc == 0
@ -34,7 +23,7 @@
tags: status tags: status
- name: Deploy the storage tier (MySQL, Redis and Memcache) without any replicas - 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: with_items:
- backend-redis - backend-redis
- system-memcache - system-memcache
@ -44,7 +33,7 @@
tags: rollout tags: rollout
- name: Scale the storage tier (MySQL, Redis and Memcache) - 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: with_items:
- backend-redis - backend-redis
- system-memcache - system-memcache
@ -64,14 +53,14 @@
tags: status tags: status
- name: Deploy the backend-listener without any replicas - 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: with_items:
- backend-listener - backend-listener
when: item not in deployment_configs when: item not in deployment_configs
tags: rollout tags: rollout
- name: Scale backend-listener - 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: with_items:
- backend-listener - backend-listener
when: item not in replication_controllers when: item not in replication_controllers
@ -85,7 +74,7 @@
tags: status tags: status
- name: Deploy everything else without any replicas - 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: with_items:
- backend-listener - backend-listener
- backend-worker - backend-worker
@ -100,7 +89,7 @@
tags: rollout tags: rollout
- name: Scale system-app, system-resque and system-sidekiq - 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: with_items:
- system-app - system-app
- system-resque - system-resque
@ -118,7 +107,7 @@
tags: status tags: status
- name: Scale backend-cron, backend-worker and system-sphinx - 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: with_items:
- backend-worker - backend-worker
- backend-cron - backend-cron
@ -136,7 +125,7 @@
tags: status tags: status
- name: Deploy apicast-staging, apicast-production - 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: with_items:
- apicast-staging - apicast-staging
#- apicast-production #- apicast-production
@ -152,17 +141,17 @@
tags: status tags: status
- name: Get Admin Username - 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 register: username
changed_when: false changed_when: false
tags: status tags: status
- name: Get Admin Password - 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 register: password
changed_when: false changed_when: false
tags: status tags: status
- name: 3scale is ready ! - 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 tags: status

14
roles/3scale/tasks/patch_apicast.yml

@ -3,30 +3,30 @@
- debug: msg="Updating {{ item }}" - debug: msg="Updating {{ item }}"
- name: Check if APICast's DC has volumes - 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 register: volumes
changed_when: false changed_when: false
- name: Add volume 'apicast-cors' - 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" when: "'apicast-cors' not in volumes.stdout_lines"
- name: Add volume 'cors-conf' - 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" when: "'cors-conf' not in volumes.stdout_lines"
- name: Check if APICast's DC has already been patched - 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 register: patched
changed_when: false changed_when: false
- name: Patch volume 'apicast-cors' - 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" when: "'apicast-cors' not in patched.stdout_lines"
- name: Patch volume 'cors-conf' - 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" when: "'cors-conf' not in patched.stdout_lines"
- name: Add environment variable APICAST_MODULE to the APICast DeploymentConfig - 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 }}

4
roles/3scale/tasks/status.yml

@ -1,7 +1,7 @@
--- ---
- name: Retrieve current ReplicationController status - 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 register: rc_state
changed_when: false changed_when: false
@ -12,7 +12,7 @@
- name: Retrieve current DeploymentConfig status - 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 register: dc_state
changed_when: false changed_when: false

6
roles/3scale/tasks/wait_for.yml

@ -1,9 +1,9 @@
--- ---
- name: Wait for all pending deployments to become ready - 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 register: rc_state
changed_when: false changed_when: false
retries: "{{ threescale_options.retries }}" retries: "{{ threescale_retries }}"
delay: "{{ threescale_options.delay }}" 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' 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'

17
roles/3scale/vars/main.yml

@ -1,11 +1,10 @@
--- ---
threescale_default_options: threescale_template: https://raw.githubusercontent.com/nmasse-itix/OpenShift-Lab/master/roles/3scale/files/amp.json
template: https://raw.githubusercontent.com/nmasse-itix/OpenShift-Lab/master/roles/3scale/files/amp.json threescale_project: 3scale
project: 3scale threescale_tenant_name: 3scale
tenant_name: 3scale threescale_wildcard_domain: "{{ openshift_master_default_subdomain }}"
wildcard_domain: "{{ openshift_master_default_subdomain }}" threescale_delay: 5
delay: 5 threescale_retries: 30
retries: 30 threescale_apicast_cors_lua: https://raw.githubusercontent.com/3scale/apicast/cors-example/examples/cors/apicast_cors.lua
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
apicast_cors_conf: https://raw.githubusercontent.com/3scale/apicast/cors-example/examples/cors/cors.conf

Loading…
Cancel
Save