Browse Source

3scale rollout playbook

master
Nicolas Massé 9 years ago
parent
commit
ea333c4052
  1. 126
      roles/3scale/tasks/main.yml
  2. 22
      roles/3scale/tasks/status.yml
  3. 9
      roles/3scale/tasks/wait_for.yml
  4. 2
      roles/3scale/vars/main.yml

126
roles/3scale/tasks/main.yml

@ -23,15 +23,139 @@
- 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 }}" | oc create -f - -n "{{ threescale_options.project }}" shell: oc process -f "{{ threescale_options.template }}" -p "TENANT_NAME={{ threescale_options.tenant_name }}" -p "WILDCARD_DOMAIN={{ threescale_options.wildcard_domain }}" | oc create -f - -n "{{ threescale_options.project }}"
# TODO - include: status.yml
tags: status
- name: Deploy the storage tier (MySQL, Redis and Memcache) without any replicas
command: oc rollout latest "{{ item }}" -n "{{ threescale_options.project }}"
with_items:
- backend-redis
- system-memcache
- system-mysql
- system-redis
when: item not in deployment_configs
tags: rollout
- name: Scale the storage tier (MySQL, Redis and Memcache)
command: oc scale dc "{{ item }}" --replicas=1 -n "{{ threescale_options.project }}"
with_items:
- backend-redis
- system-memcache
- system-mysql
- system-redis
when: item not in replication_controllers
tags: rollout
- include: wait_for.yml
static: no
vars:
pod_to_wait:
- backend-redis
- system-memcache
- system-mysql
- system-redis
tags: status
- name: Deploy the backend-listener without any replicas
command: oc rollout latest "{{ item }}" -n "{{ threescale_options.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 }}"
with_items:
- backend-listener
when: item not in replication_controllers
tags: rollout
- include: wait_for.yml
static: no
vars:
pod_to_wait:
- backend-listener
tags: status
- name: Deploy everything else without any replicas
command: oc rollout latest "{{ item }}" -n "{{ threescale_options.project }}"
with_items:
- backend-listener
- backend-worker
- system-app
- system-resque
- system-sidekiq
- backend-cron
- system-sphinx
- apicast-staging
- apicast-production
when: item not in deployment_configs
tags: rollout
- name: Scale system-app, system-resque and system-sidekiq
command: oc scale dc "{{ item }}" --replicas=1 -n "{{ threescale_options.project }}"
with_items:
- system-app
- system-resque
- system-sidekiq
when: item not in replication_controllers
tags: rollout
- include: wait_for.yml
static: no
vars:
pod_to_wait:
- system-app
- system-resque
- system-sidekiq
tags: status
- name: Scale backend-cron, backend-worker and system-sphinx
command: oc scale dc "{{ item }}" --replicas=1 -n "{{ threescale_options.project }}"
with_items:
- backend-worker
- backend-cron
- system-sphinx
when: item not in replication_controllers
tags: rollout
- include: wait_for.yml
static: no
vars:
pod_to_wait:
- backend-worker
- backend-cron
- system-sphinx
tags: status
- name: Deploy apicast-staging, apicast-production
command: oc scale dc "{{ item }}" --replicas=1 -n "{{ threescale_options.project }}"
with_items:
- apicast-staging
#- apicast-production
when: item not in replication_controllers
tags: rollout
- include: wait_for.yml
static: no
vars:
pod_to_wait:
- apicast-staging
#- apicast-production
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_options.project }}" -o 'jsonpath={.spec.template.spec.containers[0].env[?(@.name=="USER_LOGIN")].value}'
register: username register: username
changed_when: false
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_options.project }}" -o 'jsonpath={.spec.template.spec.containers[0].env[?(@.name=="USER_PASSWORD")].value}'
register: password register: password
changed_when: false
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_options.tenant_name }}-admin.{{ threescale_options.wildcard_domain }} with username = '{{ username.stdout }}' and password = '{{ password.stdout }}'"
tags: status

22
roles/3scale/tasks/status.yml

@ -0,0 +1,22 @@
---
- name: Retrieve current ReplicationController status
command: 'oc get rc -o json -n "{{ threescale_options.project }}"'
register: rc_state
changed_when: false
- name: Parse the list of deployed ReplicationController
set_fact:
replication_controllers: '{{ rc_state.stdout |from_json |json_query(''items[? @.status.replicas && @.status.replicas != `0`].metadata.annotations."openshift.io/deployment-config.name"'') }}'
replication_controllers_status: '{{ rc_state.stdout |from_json |json_query(''items[? @.status.replicas && @.status.replicas != `0`].{"name": metadata.annotations."openshift.io/deployment-config.name", "status": status.readyReplicas}'') }}'
- name: Retrieve current DeploymentConfig status
command: 'oc get dc -o json -n "{{ threescale_options.project }}"'
register: dc_state
changed_when: false
- name: Parse the list of DeploymentConfig
set_fact:
deployment_configs: '{{ dc_state.stdout |from_json |json_query(''items[? metadata.generation > `1`].metadata.name'') }}'
deployment_configs_status: '{{ dc_state.stdout |from_json |json_query(''items[? metadata.generation > `1` ].{"name": metadata.name, "status": status.replicas}'') }}'

9
roles/3scale/tasks/wait_for.yml

@ -0,0 +1,9 @@
---
- name: Wait for all pending deployments to become ready
command: 'oc get rc -o json -n "{{ threescale_options.project }}"'
register: rc_state
changed_when: false
retries: "{{ threescale_options.retries }}"
delay: "{{ threescale_options.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'

2
roles/3scale/vars/main.yml

@ -5,3 +5,5 @@
project: 3scale project: 3scale
tenant_name: 3scale tenant_name: 3scale
wildcard_domain: "{{ openshift_master_default_subdomain }}" wildcard_domain: "{{ openshift_master_default_subdomain }}"
delay: 5
retries: 30

Loading…
Cancel
Save