blob: 76d010e17de29a7fc4020733c069083e059fb7a4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
---
- name: "Lookup {{resource}} in {{project}}"
command: "oc get -n '{{project}}' '{{resource}}' -o json"
register: orig_result
changed_when: 0
- name: "Lookup API version of {{resource}} in {{project}}"
command: "oc get -n '{{project}}' '{{resource}}' --template {{'{{' + '.apiVersion' + '}}'}}"
register: api_version
changed_when: 0
# Fucking ansible is making mess of escaping. Main problem it parses to objects strings starting with '{ ... }', but not with ' { ... }'
- name: Escaping patch
set_fact: xpatch='{{patch | to_json | regex_replace(" ","") | regex_replace("^", " ")}}'
- name: "Generate dummy patch for {{resource}} in {{project}}"
command: "oc patch -n '{{project}}' --patch ' {\"apiVersion\": \"{{api_version.stdout}}\"}' --local=true -f - -o json"
args:
stdin: " {{ orig_result.stdout_lines | join('') }}"
register: dummy_result
changed_when: 0
- name: "Generate test patch {{resource}} in {{project}}"
command: "oc patch -n '{{project}}' --patch '{{xpatch}}' --local=true -f - -o json"
args:
stdin: " {{ orig_result.stdout_lines | join('') }}"
register: patch_result
changed_when: 0
#- debug: msg="{{ dummy_result.stdout }}"
# when: dummy_result.stdout != patch_result.stdout
#- debug: msg="{{ patch_result.stdout }}"
# when: dummy_result.stdout != patch_result.stdout
- name: "Patch {{resource}} in {{project}}"
command: "oc patch -n '{{project}}' '{{resource}}' --patch '{{xpatch}}'"
register: result
changed_when: result is succeeded
when: dummy_result.stdout != patch_result.stdout
|