From 9590e5a878f7cc3c81b5f8b66c7f9fef4ccb8fdf Mon Sep 17 00:00:00 2001 From: David Zager Date: Tue, 17 Jul 2018 16:17:29 -0400 Subject: [PATCH] Update APB for ansible 26 (#38) --- tasks/main.yml | 38 ++++++------------- .../{deployment.yaml => deployment.yaml.j2} | 6 +-- templates/{pvc.yaml => pvc.yaml.j2} | 0 templates/{route.yaml => route.yaml.j2} | 2 +- templates/{service.yaml => service.yaml.j2} | 0 vars/ansible_26.yml | 5 --- vars/main.yml | 5 --- 7 files changed, 15 insertions(+), 41 deletions(-) rename templates/{deployment.yaml => deployment.yaml.j2} (93%) rename templates/{pvc.yaml => pvc.yaml.j2} (100%) rename templates/{route.yaml => route.yaml.j2} (86%) rename templates/{service.yaml => service.yaml.j2} (100%) delete mode 100644 vars/ansible_26.yml diff --git a/tasks/main.yml b/tasks/main.yml index a9b8f24..72455b2 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -5,18 +5,9 @@ description: "0%: Starting" when: in_cluster -- name: 'Determine cluster type' - command: oc version - register: oc_version - ignore_errors: yes - - name: 'Set facts' set_fact: - cluster: "{{ 'openshift' if 'openshift' in oc_version.stdout else 'kubernetes' }}" - -- name: 'Include variables based on ansible version' - include_vars: ansible_26.yml - when: ansible_version.full is version('2.6', '>=') + cluster: '{{ "openshift" if "openshift" in lookup("k8s", cluster_info="version") else "kubernetes" }}' - name: Validate Admin User and Password fail: @@ -26,23 +17,16 @@ - apb_action == "provision" - name: "Set mediawiki objects state={{ state }}" - k8s_raw: - state: '{{ state }}' - definition: "{{ lookup('template', item) | from_yaml }}" - with_items: - - service.yaml - - pvc.yaml - -- name: "Set mediawiki route state={{ state }}" - openshift_raw: - state: '{{ state }}' - definition: "{{ lookup('template', 'route.yaml') | from_yaml }}" - when: cluster == 'openshift' - -- name: "Set mediawiki deployment state={{ state }}" - openshift_raw: - state: '{{ state }}' - definition: "{{ lookup('template', 'deployment.yaml') | from_yaml }}" + k8s: + state: "{{ state }}" + definition: "{{ lookup('template', item.name) | from_yaml }}" + when: item.apply | default(True) + loop: + - name: service.yaml.j2 + - name: pvc.yaml.j2 + - name: route.yaml.j2 + apply: "{{ True if cluster == 'openshift' else False }}" + - name: deployment.yaml.j2 - name: "Update last operation" asb_last_operation: diff --git a/templates/deployment.yaml b/templates/deployment.yaml.j2 similarity index 93% rename from templates/deployment.yaml rename to templates/deployment.yaml.j2 index a76257a..98dd6da 100644 --- a/templates/deployment.yaml +++ b/templates/deployment.yaml.j2 @@ -1,10 +1,10 @@ --- {% if cluster == 'kubernetes' %} -apiVersion: {{ deployment_api_version }} +apiVersion: apps/v1 kind: Deployment {% else %} -apiVersion: {{ deploymentconfig_api_version }} +apiVersion: apps.openshift.io/v1 kind: DeploymentConfig {% endif %} metadata: @@ -57,7 +57,7 @@ spec: value: {{ lookup( 'openshift', - api_version=route_api_version, + api_version='route.openshift.io/v1', kind='Route', namespace=namespace, resource_name=app_name diff --git a/templates/pvc.yaml b/templates/pvc.yaml.j2 similarity index 100% rename from templates/pvc.yaml rename to templates/pvc.yaml.j2 diff --git a/templates/route.yaml b/templates/route.yaml.j2 similarity index 86% rename from templates/route.yaml rename to templates/route.yaml.j2 index 7d5b6ad..f582ec8 100644 --- a/templates/route.yaml +++ b/templates/route.yaml.j2 @@ -1,6 +1,6 @@ --- -apiVersion: {{ route_api_version }} +apiVersion: route.openshift.io/v1 kind: Route metadata: name: {{ app_name }} diff --git a/templates/service.yaml b/templates/service.yaml.j2 similarity index 100% rename from templates/service.yaml rename to templates/service.yaml.j2 diff --git a/vars/ansible_26.yml b/vars/ansible_26.yml deleted file mode 100644 index 4662515..0000000 --- a/vars/ansible_26.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- - -deployment_api_version: apps/v1 -deploymentconfig_api_version: apps.openshift.io/v1 -route_api_version: route.openshift.io/v1 diff --git a/vars/main.yml b/vars/main.yml index aa9567b..158c3a5 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -10,8 +10,3 @@ state: "{{ state_map[apb_action] }}" pod_name: "{{ lookup('env', 'POD_NAME') }}" pod_namespace: "{{ lookup('env', 'POD_NAMESPACE') }}" in_cluster: "{{ True if (pod_name and pod_namespace) else False }}" - -# Ansible 2.5 api versions -deployment_api_version: v1 -deploymentconfig_api_version: v1 -route_api_version: v1