From 4738c47878fc9a6236780ac8040ffe262239ecac Mon Sep 17 00:00:00 2001 From: David Zager Date: Wed, 23 May 2018 10:30:34 -0400 Subject: [PATCH] Include vars for ansible version >= 2.6 (#33) * Include vars for ansible version >= 2.6 * Improve version test, fix templates * Remove latest origin/k8s tests * Remove apiVersions that don't change --- .travis.yml | 4 ++-- tasks/main.yml | 4 ++++ templates/deployment.yaml | 9 +++++---- templates/route.yaml | 2 +- templates/service.yaml | 2 +- vars/ansible_26.yml | 5 +++++ vars/main.yml | 5 +++++ 7 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 vars/ansible_26.yml diff --git a/.travis.yml b/.travis.yml index 1acdafa..ec1430b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,9 +7,9 @@ python: env: - OPENSHIFT_VERSION=v3.9 - - OPENSHIFT_VERSION=v3.10 + #- OPENSHIFT_VERSION=v3.10 - KUBERNETES_VERSION=v1.9.0 - - KUBERNETES_VERSION=v1.10.0 + #- KUBERNETES_VERSION=v1.10.0 # Allow failures on oc latest # TODO: re-enable latest when it isn't busted matrix: diff --git a/tasks/main.yml b/tasks/main.yml index 3eae831..846d109 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -14,6 +14,10 @@ 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', '>=') + - name: Validate Admin User and Password fail: msg: "Mediawiki Admin User and Password cannot be the same value!" diff --git a/templates/deployment.yaml b/templates/deployment.yaml index a2f2f59..ab09326 100644 --- a/templates/deployment.yaml +++ b/templates/deployment.yaml @@ -1,9 +1,10 @@ --- -apiVersion: v1 {% if cluster == 'kubernetes' %} +apiVersion: {{ deployment_api_version }} kind: Deployment {% else %} +apiVersion: {{ deploymentconfig_api_version }} kind: DeploymentConfig {% endif %} metadata: @@ -51,12 +52,12 @@ spec: fieldRef: fieldPath: status.podIP ports: - - container_port: 8080 + - containerPort: 8080 protocol: TCP volumeMounts: - name: mediawiki mountPath: /persistent volumes: - name: mediawiki - persistent_volume_claim: - claim_name: {{ app_name }} + persistentVolumeClaim: + claimName: {{ app_name }} diff --git a/templates/route.yaml b/templates/route.yaml index b09a4db..7d5b6ad 100644 --- a/templates/route.yaml +++ b/templates/route.yaml @@ -1,6 +1,6 @@ --- -apiVersion: v1 +apiVersion: {{ route_api_version }} kind: Route metadata: name: {{ app_name }} diff --git a/templates/service.yaml b/templates/service.yaml index 3ccf9a8..1286f7d 100644 --- a/templates/service.yaml +++ b/templates/service.yaml @@ -12,7 +12,7 @@ spec: ports: - name: web port: 8080 - target_port: 8080 + targetPort: 8080 selector: app: {{ app_name }} service: {{ app_name }} diff --git a/vars/ansible_26.yml b/vars/ansible_26.yml new file mode 100644 index 0000000..4662515 --- /dev/null +++ b/vars/ansible_26.yml @@ -0,0 +1,5 @@ +--- + +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 158c3a5..aa9567b 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -10,3 +10,8 @@ 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