summaryrefslogtreecommitdiffstats
path: root/roles/openshift_hosted/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'roles/openshift_hosted/tasks')
-rw-r--r--roles/openshift_hosted/tasks/main.yml21
-rw-r--r--roles/openshift_hosted/tasks/registry/registry.yml40
-rw-r--r--roles/openshift_hosted/tasks/registry/storage/object_storage.yml114
-rw-r--r--roles/openshift_hosted/tasks/registry/storage/persistent_volume.yml18
-rw-r--r--roles/openshift_hosted/tasks/registry/storage/s3.yml12
-rw-r--r--roles/openshift_hosted/tasks/router.yml65
-rw-r--r--roles/openshift_hosted/tasks/router/router.yml70
7 files changed, 274 insertions, 66 deletions
diff --git a/roles/openshift_hosted/tasks/main.yml b/roles/openshift_hosted/tasks/main.yml
index d42a4e365..c801a0e67 100644
--- a/roles/openshift_hosted/tasks/main.yml
+++ b/roles/openshift_hosted/tasks/main.yml
@@ -1,3 +1,22 @@
---
+- name: Create temp directory for kubeconfig
+ command: mktemp -d /tmp/openshift-ansible-XXXXXX
+ register: mktemp
+ changed_when: False
-- include: router.yml
+- set_fact:
+ openshift_hosted_kubeconfig: "{{ mktemp.stdout }}/admin.kubeconfig"
+
+- name: Copy the admin client config(s)
+ command: >
+ cp {{ openshift_master_config_dir }}/admin.kubeconfig {{ openshift_hosted_kubeconfig }}
+ changed_when: False
+
+- include: router/router.yml
+- include: registry/registry.yml
+
+- name: Delete temp directory
+ file:
+ name: "{{ mktemp.stdout }}"
+ state: absent
+ changed_when: False
diff --git a/roles/openshift_hosted/tasks/registry/registry.yml b/roles/openshift_hosted/tasks/registry/registry.yml
new file mode 100644
index 000000000..a242ce30f
--- /dev/null
+++ b/roles/openshift_hosted/tasks/registry/registry.yml
@@ -0,0 +1,40 @@
+---
+- name: Retrieve list of openshift nodes matching registry selector
+ command: >
+ {{ openshift.common.client_binary }} --api-version='v1' -o json
+ get nodes -n default --config={{ openshift_hosted_kubeconfig }}
+ --selector={{ openshift.hosted.registry.selector | default('') }}
+ register: openshift_hosted_registry_nodes_json
+ changed_when: false
+ when: openshift.hosted.registry.replicas | default(none) is none
+
+- set_fact:
+ replicas: "{{ openshift.hosted.registry.replicas | default(((openshift_hosted_registry_nodes_json.stdout | from_json)['items'] | length) if openshift.hosted.registry.storage.kind | default(none) is not none else 1) }}"
+
+- name: Create OpenShift registry
+ command: >
+ {{ openshift.common.admin_binary }} registry --create
+ --config={{ openshift_hosted_kubeconfig }}
+ {% if replicas > 1 -%}
+ --replicas={{ replicas }}
+ {% endif -%}
+ --namespace={{ openshift.hosted.registry.namespace | default('default') }}
+ --service-account=registry
+ {% if openshift.hosted.registry.selector | default(none) is not none -%}
+ --selector='{{ openshift.hosted.registry.selector }}'
+ {% endif -%}
+ {% if not openshift.common.version_gte_3_2_or_1_2 | bool -%}
+ --credentials={{ openshift_master_config_dir }}/openshift-registry.kubeconfig
+ {% endif -%}
+ {% if openshift.hosted.registry.registryurl | default(none) is not none -%}
+ --images='{{ openshift.hosted.registry.registryurl }}'
+ {% endif -%}
+ register: openshift_hosted_registry_results
+ changed_when: "'service exists' not in openshift_hosted_registry_results.stdout"
+ failed_when: "openshift_hosted_registry_results.rc != 0 and 'service exists' not in openshift_hosted_registry_results.stdout and 'deployment_config' not in openshift_hosted_registry_results.stderr and 'service' not in openshift_hosted_registry_results.stderr"
+
+- include: storage/object_storage.yml
+ when: openshift.hosted.registry.storage.kind | default(none) == 'object'
+
+- include: storage/persistent_volume.yml
+ when: openshift.hosted.registry.storage.kind | default(none) in ['nfs', 'openstack']
diff --git a/roles/openshift_hosted/tasks/registry/storage/object_storage.yml b/roles/openshift_hosted/tasks/registry/storage/object_storage.yml
new file mode 100644
index 000000000..9db67ecc6
--- /dev/null
+++ b/roles/openshift_hosted/tasks/registry/storage/object_storage.yml
@@ -0,0 +1,114 @@
+- fail:
+ msg: >
+ Object Storage Provider: {{ openshift.hosted.registry.storage.provider }}
+ is not currently supported
+ when: openshift.hosted.registry.storage.provider not in ['azure_blob', 's3', 'swift']
+
+- fail:
+ msg: >
+ Support for provider: "{{ openshift.hosted.registry.storage.provider }}"
+ not implemented yet
+ when: openshift.hosted.registry.storage.provider in ['azure_blob', 'swift']
+
+- include: s3.yml
+ when: openshift.hosted.registry.storage.provider == 's3'
+
+- name: Test if docker registry config secret exists
+ command: >
+ {{ openshift.common.client_binary }}
+ --config={{ openshift_hosted_kubeconfig }}
+ --namespace={{ openshift.hosted.registry.namespace | default('default') }}
+ get secrets {{ registry_config_secret_name }} -o json
+ register: secrets
+ changed_when: false
+ failed_when: false
+
+- set_fact:
+ registry_config: "{{ lookup('template', '../templates/registry_config.j2') | b64encode }}"
+
+- set_fact:
+ registry_config_secret: "{{ lookup('template', '../templates/registry_config_secret.j2') | from_yaml }}"
+
+- set_fact:
+ same_storage_provider: "{{ (secrets.stdout|from_json)['metadata']['annotations']['provider'] | default(none) == openshift.hosted.registry.storage.provider }}"
+ when: secrets.rc == 0
+
+- name: Update registry config secret
+ command: >
+ {{ openshift.common.client_binary }}
+ --config={{ openshift_hosted_kubeconfig }}
+ --namespace={{ openshift.hosted.registry.namespace | default('default') }}
+ patch secret/{{ registry_config_secret_name }}
+ -p '{"data": {"config.yml": "{{ registry_config }}"}}'
+ register: update_config_secret
+ when: secrets.rc == 0 and (secrets.stdout|from_json)['data']['config.yml'] != registry_config and same_storage_provider | bool
+
+- name: Create registry config secret
+ shell: >
+ echo '{{ registry_config_secret |to_json }}' |
+ {{ openshift.common.client_binary }}
+ --config={{ openshift_hosted_kubeconfig }}
+ --namespace={{ openshift.hosted.registry.namespace | default('default') }}
+ create -f -
+ when: secrets.rc == 1
+
+- name: Determine if service account contains secrets
+ command: >
+ {{ openshift.common.client_binary }}
+ --config={{ openshift_hosted_kubeconfig }}
+ --namespace={{ openshift.hosted.registry.namespace | default('default') }}
+ get serviceaccounts registry
+ -o jsonpath='{.secrets[?(@.name=="{{ registry_config_secret_name }}")].name}'
+ register: serviceaccount
+ changed_when: false
+
+- name: Add secrets to registry service account
+ command: >
+ {{ openshift.common.client_binary }}
+ --config={{ openshift_hosted_kubeconfig }}
+ --namespace={{ openshift.hosted.registry.namespace | default('default') }}
+ secrets add serviceaccount/registry secrets/{{ registry_config_secret_name }}
+ when: serviceaccount.stdout == ''
+
+- name: Determine if deployment config contains secrets
+ command: >
+ {{ openshift.common.client_binary }}
+ --config={{ openshift_hosted_kubeconfig }}
+ --namespace={{ openshift.hosted.registry.namespace | default('default') }}
+ set volumes dc/docker-registry --list
+ register: volume
+ changed_when: false
+
+- name: Add secrets to registry deployment config
+ command: >
+ {{ openshift.common.client_binary }}
+ --config={{ openshift_hosted_kubeconfig }}
+ --namespace={{ openshift.hosted.registry.namespace | default('default') }}
+ set volumes dc/docker-registry --add --name=docker-config -m /etc/registry
+ --type=secret --secret-name={{ registry_config_secret_name }}
+ when: registry_config_secret_name not in volume.stdout
+
+- name: Determine if registry environment variable needs to be created
+ command: >
+ {{ openshift.common.client_binary }}
+ --config={{ openshift_hosted_kubeconfig }}
+ --namespace={{ openshift.hosted.registry.namespace | default('default') }}
+ set env --list dc/docker-registry
+ register: oc_env
+ changed_when: false
+
+- name: Add registry environment variable
+ command: >
+ {{ openshift.common.client_binary }}
+ --config={{ openshift_hosted_kubeconfig }}
+ --namespace={{ openshift.hosted.registry.namespace | default('default') }}
+ set env dc/docker-registry REGISTRY_CONFIGURATION_PATH=/etc/registry/config.yml
+ when: "'REGISTRY_CONFIGURATION_PATH' not in oc_env.stdout"
+
+- name: Redeploy registry
+ command: >
+ {{ openshift.common.client_binary }}
+ --config={{ openshift_hosted_kubeconfig }}
+ --namespace={{ openshift.hosted.registry.namespace | default('default') }}
+ deploy dc/docker-registry --latest
+ when: secrets.rc == 0 and update_config_secret.rc == 0 and same_storage_provider | bool
diff --git a/roles/openshift_hosted/tasks/registry/storage/persistent_volume.yml b/roles/openshift_hosted/tasks/registry/storage/persistent_volume.yml
new file mode 100644
index 000000000..6bf859e82
--- /dev/null
+++ b/roles/openshift_hosted/tasks/registry/storage/persistent_volume.yml
@@ -0,0 +1,18 @@
+---
+- set_fact:
+ registry_volume_claim: "{{ openshift.hosted.registry.storage.volume.name }}-claim"
+
+- name: Determine if volume is already attached to dc/docker-registry
+ command: "{{ openshift.common.client_binary }} get -o template dc/docker-registry --template=\\{\\{.spec.template.spec.volumes\\}\\} --output-version=v1"
+ changed_when: false
+ register: registry_volumes_output
+
+- set_fact:
+ volume_attached: "{{ registry_volume_claim in registry_volumes_output.stdout }}"
+
+- name: Add volume to dc/docker-registry
+ command: >
+ {{ openshift.common.client_binary }} volume dc/docker-registry
+ --add --overwrite -t persistentVolumeClaim --claim-name={{ registry_volume_claim }}
+ --name=registry-storage
+ when: not volume_attached | bool
diff --git a/roles/openshift_hosted/tasks/registry/storage/s3.yml b/roles/openshift_hosted/tasks/registry/storage/s3.yml
new file mode 100644
index 000000000..707be9c00
--- /dev/null
+++ b/roles/openshift_hosted/tasks/registry/storage/s3.yml
@@ -0,0 +1,12 @@
+---
+- fail:
+ msg: >
+ openshift_hosted_registry_storage_s3_accesskey and
+ openshift_hosted_registry_storage_s3_secretkey are required
+ when: openshift.hosted.registry.storage.s3.accesskey | default(none) is none or openshift.hosted.registry.storage.s3.secretkey | default(none) is none
+
+- fail:
+ msg: >
+ openshift_hosted_registry_storage_s3_bucket and
+ openshift_hosted_registry_storage_s3_region are required
+ when: openshift.hosted.registry.storage.s3.bucket | default(none) is none or openshift.hosted.registry.storage.s3.region | default(none) is none
diff --git a/roles/openshift_hosted/tasks/router.yml b/roles/openshift_hosted/tasks/router.yml
deleted file mode 100644
index 4ccbf4430..000000000
--- a/roles/openshift_hosted/tasks/router.yml
+++ /dev/null
@@ -1,65 +0,0 @@
----
-- fail:
- msg: "Both 'certfile' and 'keyfile' keys must be specified when supplying the openshift_hosted_router_certificate variable."
- when: openshift_hosted_router_certificate is defined and ('certfile' not in openshift_hosted_router_certificate or 'keyfile' not in openshift_hosted_router_certificate)
-
-- name: Read router certificate and key
- slurp:
- src: "{{ item }}"
- register: openshift_router_certificate_output
- with_items:
- - "{{ openshift_hosted_router_certificate.certfile }}"
- - "{{ openshift_hosted_router_certificate.keyfile }}"
- delegate_to: localhost
- when: openshift_hosted_router_certificate is defined
-
-- name: Persist certificate contents
- openshift_facts:
- role: hosted
- openshift_env:
- openshift_hosted_router_certificate_contents: "{% for certificate in openshift_router_certificate_output.results -%}{{ certificate.content | b64decode }}{% endfor -%}"
- when: openshift_hosted_router_certificate is defined
-
-- name: Create PEM certificate
- copy:
- content: "{{ openshift.hosted.router.certificate.contents }}"
- dest: "{{ openshift_master_config_dir }}/openshift-router.pem"
- mode: 0600
- when: openshift.hosted.router.certificate | default(None) != None
-
-- name: Retrieve list of openshift nodes
- command: >
- {{ openshift.common.client_binary }} --api-version='v1' -o json
- get nodes -n default --config={{ openshift.common.config_base }}/master/admin.kubeconfig
- register: openshift_hosted_router_nodes_json
- changed_when: false
- when: openshift.hosted.router.replicas | default(None) == None
-
-- name: Collect nodes matching router selector
- set_fact:
- openshift_hosted_router_nodes: >
- {{ (openshift_hosted_router_nodes_json.stdout|from_json)['items']
- | oo_oc_nodes_matching_selector(openshift.hosted.router.selector) }}
- when: openshift.hosted.router.replicas | default(None) == None
-
-- name: Create OpenShift router
- command: >
- {{ openshift.common.admin_binary }} router --create
- {% if openshift.hosted.router.replicas | default(None) != None -%}
- --replicas={{ openshift.hosted.router.replicas }}
- {% else -%}
- --replicas={{ openshift_hosted_router_nodes | length }}
- {% endif %}
- {% if openshift.hosted.router.certificate | default(None) != None -%}
- --default-cert={{ openshift_master_config_dir }}/openshift-router.pem
- {% endif -%}
- --namespace=default
- --service-account=router
- --selector='{{ openshift.hosted.router.selector }}'
- --credentials={{ openshift_master_config_dir }}/openshift-router.kubeconfig
- {% if openshift.hosted.router.registryurl | default(None)!= None -%}
- --images='{{ openshift.hosted.router.registryurl }}'
- {% endif -%}
- register: openshift_hosted_router_results
- changed_when: "'service exists' not in openshift_hosted_router_results.stdout"
- when: openshift.hosted.router.replicas | default(None) != None or (openshift_hosted_router_nodes is defined and openshift_hosted_router_nodes | length > 0)
diff --git a/roles/openshift_hosted/tasks/router/router.yml b/roles/openshift_hosted/tasks/router/router.yml
new file mode 100644
index 000000000..c011db762
--- /dev/null
+++ b/roles/openshift_hosted/tasks/router/router.yml
@@ -0,0 +1,70 @@
+---
+- fail:
+ msg: "'certfile', 'keyfile' and 'cafile' keys must be specified when supplying the openshift_hosted_router_certificate variable."
+ when: openshift_hosted_router_certificate is defined and ('certfile' not in openshift_hosted_router_certificate or 'keyfile' not in openshift_hosted_router_certificate or 'cafile' not in openshift_hosted_router_certificate)
+
+- name: Read router certificate and key
+ become: no
+ local_action:
+ module: slurp
+ src: "{{ item }}"
+ register: openshift_router_certificate_output
+ with_items:
+ - "{{ openshift_hosted_router_certificate.certfile }}"
+ - "{{ openshift_hosted_router_certificate.keyfile }}"
+ - "{{ openshift_hosted_router_certificate.cafile }}"
+ when: openshift_hosted_router_certificate is defined
+
+- name: Persist certificate contents
+ openshift_facts:
+ role: hosted
+ openshift_env:
+ openshift_hosted_router_certificate_contents: "{% for certificate in openshift_router_certificate_output.results -%}{{ certificate.content | b64decode }}{% endfor -%}"
+ when: openshift_hosted_router_certificate is defined
+
+- name: Create PEM certificate
+ copy:
+ content: "{{ openshift.hosted.router.certificate.contents }}"
+ dest: "{{ openshift_master_config_dir }}/openshift-router.pem"
+ mode: 0600
+ when: openshift.hosted.router.certificate | default(none) is not none
+
+- name: Retrieve list of openshift nodes matching router selector
+ command: >
+ {{ openshift.common.client_binary }} --api-version='v1' -o json
+ get nodes -n default --config={{ openshift_hosted_kubeconfig }}
+ --selector={{ openshift.hosted.router.selector | default('') }}
+ register: openshift_hosted_router_nodes_json
+ changed_when: false
+ when: openshift.hosted.router.replicas | default(none) is none
+
+- set_fact:
+ replicas: "{{ openshift.hosted.router.replicas | default((openshift_hosted_router_nodes_json.stdout | from_json)['items'] | length) }}"
+
+- name: Create OpenShift router
+ command: >
+ {{ openshift.common.admin_binary }} router --create
+ --config={{ openshift_hosted_kubeconfig }}
+ {% if replicas > 1 -%}
+ --replicas={{ replicas }}
+ {% endif -%}
+ {% if openshift.hosted.router.certificate | default(none) is not none -%}
+ --default-cert={{ openshift_master_config_dir }}/openshift-router.pem
+ {% endif -%}
+ --namespace={{ openshift.hosted.router.namespace | default('default') }}
+ {% if openshift.hosted.router.force_subdomain | default(none) is not none %}
+ --force-subdomain={{ openshift.hosted.router.force_subdomain }}
+ {% endif %}
+ --service-account=router
+ {% if openshift.hosted.router.selector | default(none) is not none -%}
+ --selector='{{ openshift.hosted.router.selector }}'
+ {% endif -%}
+ {% if not openshift.common.version_gte_3_2_or_1_2 | bool -%}
+ --credentials={{ openshift_master_config_dir }}/openshift-router.kubeconfig
+ {% endif -%}
+ {% if openshift.hosted.router.registryurl | default(none) is not none -%}
+ --images='{{ openshift.hosted.router.registryurl }}'
+ {% endif -%}
+ register: openshift_hosted_router_results
+ changed_when: "'service exists' not in openshift_hosted_router_results.stdout"
+ failed_when: "openshift_hosted_router_results.rc != 0 and 'service exists' not in openshift_hosted_router_results.stdout and 'deployment_config' not in openshift_hosted_router_results.stderr and 'service' not in openshift_hosted_router_results.stderr"