redhat-cop / openshift-applier

Used to apply OpenShift objects to an OpenShift Cluster
Apache License 2.0
101 stars 61 forks source link

Make "oc apply" invocation returning "ok" status when there is no change performed on the server #44

Open matihost opened 6 years ago

matihost commented 6 years ago

https://github.com/redhat-cop/openshift-applier/blob/master/roles/openshift-applier/tasks/process-template.yml#L43 always shows as "changed" in Ansible output

Since oc 3.9 the "oc apply" returns information whether is perfoma any change the server or not. So "changed_when" option can be used by comparing oc_apply stdout.

Actually oc command works via computing patch so it know whether it performs a change on the server - since oc 3.11 (or later) oc apply will be actually happening on the server completely.

References: https://docs.ansible.com/ansible/2.6/user_guide/playbooks_error_handling.html#overriding-the-changed-result https://ansibledaily.com/idempotent-shell-command-in-ansible/

oybed commented 6 years ago

Hi @matihost thanks for submitting this request (and info). With issue https://github.com/redhat-cop/openshift-applier/issues/39, we are looking to move to k8s_raw (instead of using the oc command), so I'd like to link this change to that one to ensure the request/needs are met as part of that work.