patch_configmap_file.yaml 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. ---
  2. ## The purpose of this task file is to get a patch that is based on the diff
  3. ## between configmap_current_file and configmap_new_file. The module
  4. ## logging_patch takes the paths of two files to compare and also a list of
  5. ## variables whose line we exclude from the diffs.
  6. ## We then patch the new configmap file so that we can build a configmap
  7. ## using that file later. We then use oc apply to idempotenly modify any
  8. ## existing configmap.
  9. ## The following variables are expected to be provided when including this task:
  10. # __configmap_output -- This is provided to us from patch_configmap_files.yaml
  11. # it is a dict of the configmap where configmap_current_file exists
  12. # configmap_current_file -- The name of the data file in the __configmap_output
  13. # configmap_new_file -- The path to the file that we intend to oc apply later
  14. # we apply our generated patch to this file.
  15. # configmap_protected_lines -- The list of variables to exclude from the diff
  16. - when:
  17. - configmap_current_file in __configmap_output.results.results[0]['data']
  18. block:
  19. - copy:
  20. content: "{{ __configmap_output.results.results[0]['data'][configmap_current_file] }}"
  21. dest: "{{ tempdir }}/current.yml"
  22. - logging_patch:
  23. original_file: "{{ tempdir }}/current.yml"
  24. new_file: "{{ configmap_new_file }}"
  25. whitelist: "{{ configmap_protected_lines | default([]) }}"
  26. register: patch_output
  27. - when:
  28. - patch_output.raw_patch is defined
  29. - patch_output.raw_patch | length > 0
  30. block:
  31. - slurp:
  32. src: "{{ configmap_new_file }}"
  33. register: new_file_slurp
  34. - local_action: copy content="{{ patch_output.raw_patch }}\n" dest={{ local_tmp.stdout }}/patch.patch
  35. become: false
  36. - local_action: copy content={{ new_file_slurp['content'] | b64decode }} dest={{ local_tmp.stdout }}/configmap_new_file
  37. become: false
  38. - local_action: command patch --force --quiet -u {{ local_tmp.stdout }}/configmap_new_file {{ local_tmp.stdout }}/patch.patch
  39. become: false
  40. - copy:
  41. src: "{{ local_tmp.stdout }}/configmap_new_file"
  42. dest: "{{ configmap_new_file }}"