oc_apply.yaml 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. ---
  2. - name: Checking generation of {{file_content.kind}} {{file_content.metadata.name}}
  3. command: >
  4. {{ openshift_client_binary }} --config={{ kubeconfig }}
  5. get {{file_content.kind}} {{file_content.metadata.name}}
  6. -o jsonpath='{.metadata.resourceVersion}'
  7. -n {{namespace}}
  8. register: generation_init
  9. failed_when: "'not found' not in generation_init.stderr and generation_init.stdout == ''"
  10. changed_when: no
  11. - name: Applying {{file_name}}
  12. command: >
  13. {{ openshift_client_binary }} --config={{ kubeconfig }}
  14. apply -f {{ file_name }}
  15. -n {{ namespace }}
  16. register: generation_apply
  17. failed_when:
  18. - "'error' in generation_apply.stderr"
  19. - "generation_apply.rc != 0"
  20. changed_when: no
  21. - name: Determine change status of {{file_content.kind}} {{file_content.metadata.name}}
  22. command: >
  23. {{ openshift_client_binary }} --config={{ kubeconfig }}
  24. get {{file_content.kind}} {{file_content.metadata.name}}
  25. -o jsonpath='{.metadata.resourceVersion}'
  26. -n {{namespace}}
  27. register: generation_changed
  28. failed_when: "'not found' not in generation_changed.stderr and generation_changed.stdout == ''"
  29. changed_when: generation_changed.stdout | default (0) | int > generation_init.stdout | default(0) | int
  30. when:
  31. - "'field is immutable' not in generation_apply.stderr"
  32. - name: Removing previous {{file_name}}
  33. command: >
  34. {{ openshift_client_binary }} --config={{ kubeconfig }}
  35. delete -f {{ file_name }}
  36. -n {{ namespace }}
  37. register: generation_delete
  38. failed_when:
  39. - "'error' in generation_delete.stderr"
  40. - "generation_delete.rc != 0"
  41. changed_when: generation_delete.rc == 0
  42. when: generation_apply.rc != 0
  43. - name: Recreating {{file_name}}
  44. command: >
  45. {{ openshift_client_binary }} --config={{ kubeconfig }}
  46. apply -f {{ file_name }}
  47. -n {{ namespace }}
  48. register: generation_apply
  49. failed_when:
  50. - "'error' in generation_apply.stderr"
  51. - "generation_apply.rc != 0"
  52. changed_when: generation_apply.rc == 0
  53. when: generation_apply.rc != 0