diff options
author | Suren A. Chilingaryan <csa@suren.me> | 2017-04-01 04:53:28 +0200 |
---|---|---|
committer | Suren A. Chilingaryan <csa@suren.me> | 2017-04-01 04:53:28 +0200 |
commit | e7ed329bd81c2273c03e94c93c9ce9c1d01cdc86 (patch) | |
tree | 444778102e4f73b83ef9462235b7f614b004b264 /roles/openshift_resource | |
download | ands-e7ed329bd81c2273c03e94c93c9ce9c1d01cdc86.tar.gz ands-e7ed329bd81c2273c03e94c93c9ce9c1d01cdc86.tar.bz2 ands-e7ed329bd81c2273c03e94c93c9ce9c1d01cdc86.tar.xz ands-e7ed329bd81c2273c03e94c93c9ce9c1d01cdc86.zip |
Initial import
Diffstat (limited to 'roles/openshift_resource')
-rw-r--r-- | roles/openshift_resource/defaults/main.yml | 1 | ||||
-rw-r--r-- | roles/openshift_resource/tasks/command.yml | 17 | ||||
-rw-r--r-- | roles/openshift_resource/tasks/lookup.yml | 6 | ||||
-rw-r--r-- | roles/openshift_resource/tasks/main.yml | 22 | ||||
-rw-r--r-- | roles/openshift_resource/tasks/resource.yml | 20 | ||||
-rw-r--r-- | roles/openshift_resource/tasks/template.yml | 25 |
6 files changed, 91 insertions, 0 deletions
diff --git a/roles/openshift_resource/defaults/main.yml b/roles/openshift_resource/defaults/main.yml new file mode 100644 index 0000000..ec44c4f --- /dev/null +++ b/roles/openshift_resource/defaults/main.yml @@ -0,0 +1 @@ +template_path: "/mnt/provision/templates" diff --git a/roles/openshift_resource/tasks/command.yml b/roles/openshift_resource/tasks/command.yml new file mode 100644 index 0000000..c8e8d04 --- /dev/null +++ b/roles/openshift_resource/tasks/command.yml @@ -0,0 +1,17 @@ +- block: + + - name: Lookup the specified resource + command: "oc get -n {{project}} {{resource}}" + register: result + failed_when: false + changed_when: (result | failed) + + - name: Detroy existing resources + command: "oc delete -n {{project}} {{resource}}" + failed_when: false + when: (recreate|default(false)) + + - name: Executing command + command: "oc -n {{ project }} {{ command }}" + when: (recreate|default(false)) or (result | changed) + run_once: true diff --git a/roles/openshift_resource/tasks/lookup.yml b/roles/openshift_resource/tasks/lookup.yml new file mode 100644 index 0000000..07beb81 --- /dev/null +++ b/roles/openshift_resource/tasks/lookup.yml @@ -0,0 +1,6 @@ +--- +- name: Lookup the specified resource + command: "oc get -n {{project}} {{rkind}}/{{rname}}" + register: result + failed_when: false + changed_when: (result | failed) diff --git a/roles/openshift_resource/tasks/main.yml b/roles/openshift_resource/tasks/main.yml new file mode 100644 index 0000000..698efea --- /dev/null +++ b/roles/openshift_resource/tasks/main.yml @@ -0,0 +1,22 @@ +--- +- block: + - name: "Read template {{ template }}" + command: cat '{{template_path}}/{{template}}' + changed_when: false + register: results + + - name: Parse JSON templates + set_fact: tmpl="{{ results.stdout | from_json }}" + when: template.find(".json") != -1 + + - name: Parse YaML templates + set_fact: tmpl="{{ results.stdout | from_yaml }}" + when: template.find(".json") == -1 + + - include: template.yml + when: tmpl.kind == "Template" + + - include: resource.yml + when: tmpl.kind != "Template" + + run_once: true diff --git a/roles/openshift_resource/tasks/resource.yml b/roles/openshift_resource/tasks/resource.yml new file mode 100644 index 0000000..326abbb --- /dev/null +++ b/roles/openshift_resource/tasks/resource.yml @@ -0,0 +1,20 @@ +--- +- 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 + command: "oc get -n {{project}} {{rkind}}/{{rname}}" + register: result + failed_when: false + changed_when: (result | failed) + + - name: Detroy existing resources + command: "oc delete -n {{project}} {{rkind}}/{{rname}}" + failed_when: false + when: (recreate|default(false)) + + - name: Create resources defined in template + command: "oc create -n {{project}} -f '{{ template_path }}/{{ template }}' {{ create_args | default('') }}" + when: (recreate|default(false)) or (result | changed) + run_once: true diff --git a/roles/openshift_resource/tasks/template.yml b/roles/openshift_resource/tasks/template.yml new file mode 100644 index 0000000..c93dec5 --- /dev/null +++ b/roles/openshift_resource/tasks/template.yml @@ -0,0 +1,25 @@ +--- +- block: + - name: Find out which resources we are going to configure + set_fact: resources="{{ tmpl | json_query(query) }}" + vars: + query: "objects[*].{kind: kind, name: metadata.name}" + + - name: Lookup the specified resource + command: "oc get -n {{project}} {{item.kind}}/{{item.name}}" + register: results + failed_when: false + changed_when: (results | failed) + with_items: "{{ resources | default([]) }}" +# when: not (recreate|default(false)) + + - name: Detroy existing resources + command: "oc delete -n {{project}} {{resources[item|int].kind}}/{{resources[item|int].name}}" + failed_when: false + with_sequence: start=0 count="{{resources | default([]) | length}}" + when: ((recreate|default(false)) or (results | changed)) and (results.results[item|int].rc == 0) + + - name: Create resources defined in template + shell: "oc process -f '{{ template_path }}/{{template}}' {{ template_args | default('') }} | oc create -n {{project}} -f - {{ create_args | default('') }}" + when: (recreate|default(false)) or (results | changed) + run_once: true |