summaryrefslogtreecommitdiffstats
path: root/roles/openshift_resource/tasks/resource.yml
blob: 03420a92de98fc4beca50c5f237ab348a3d343bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
---
- block:
  - name: Find out which resources we are going to configure
    set_fact: rkind="{{ tmpl.kind }}" rname="{{ tmpl.metadata.name }}"

  - name: "Lookup the specified resource {{rkind}}/{{rname}} in {{project}}"
    command: "oc get -n {{project}} {{rkind}}/{{rname}}"
    register: find_result
    changed_when: false
    failed_when: false

  - name: "Detroy existing resources {{rkind}}/{{rname}} in {{project}}"
    command: "oc delete -n {{project}} {{rkind}}/{{rname}}"
    register: rm_result
    failed_when: false
    changed_when: rm_result is succeeded
    when: (recreate|default(false)) 

  - name: "Populate resources defined in {{ template }} to {{project}} ({{ replace | default(false) | ternary('replace', 'create')  }})"
    command: "oc {{ replace | default(false) | ternary((find_result.rc == 0) | ternary('replace', 'create'), 'create') }} -n {{project}} -f '{{ template_path }}/{{ template }}' {{ create_args | default('') }}"
    when: (recreate|default(false)) or (replace | default(false)) or (find_result.rc != 0)
  run_once: true