patch_configmap_file.yaml 1.6 KB

1234567891011121314151617181920212223242526272829303132333435
  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. - copy:
  17. content: "{{ __configmap_output.results.results[0]['data'][configmap_current_file] }}"
  18. dest: "{{ tempdir }}/current.yml"
  19. - logging_patch:
  20. original_file: "{{ tempdir }}/current.yml"
  21. new_file: "{{ configmap_new_file }}"
  22. whitelist: "{{ configmap_protected_lines | default([]) }}"
  23. register: patch_output
  24. - copy:
  25. content: "{{ patch_output.raw_patch }}\n"
  26. dest: "{{ tempdir }}/patch.patch"
  27. when: patch_output.raw_patch | length > 0
  28. - command: >
  29. patch --force --quiet -u "{{ configmap_new_file }}" "{{ tempdir }}/patch.patch"
  30. when: patch_output.raw_patch | length > 0