--- - name: Lookup the specified resource command: "oc get -n '{{project}}' '{{resource}}' -o json" register: orig_result changed_when: 0 - name: Lookup API version of the specified resource 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 {{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 | succeeded) when: dummy_result.stdout != patch_result.stdout