A Python library for code common to TripleO CLI and TripleO UI.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

229 lines
8.4KB

  1. - name: Quote the JSON queries to escape invalid characters
  2. set_fact:
  3. item_id: '"{{ item }}".id'
  4. item_group: '"{{ item }}".group'
  5. item_only: '"{{ item }}"'
  6. - name: Lookup deployment UUID
  7. set_fact:
  8. deployment_uuid: "{{ lookup('file', tripleo_role_name ~ '/' ~ ansible_hostname | lower ~ '/' ~ item) | from_yaml | json_query(item_id) }}"
  9. - name: Lookup deployment group
  10. set_fact:
  11. deployment_group: "{{ lookup('file', tripleo_role_name ~ '/' ~ ansible_hostname | lower ~ '/' ~ item) | from_yaml | json_query(item_group) }}"
  12. - name: Hiera check and diff mode
  13. block:
  14. - name: Create hiera check-mode directory
  15. file:
  16. path: /etc/puppet/check-mode/hieradata
  17. state: directory
  18. check_mode: no
  19. - name: Create deployed check-mode directory
  20. file:
  21. path: /var/lib/heat-config/check-mode
  22. state: directory
  23. check_mode: no
  24. - name: Create tripleo-config-download check-mode directory
  25. file:
  26. path: /var/lib/heat-config/tripleo-config-download/check-mode
  27. state: directory
  28. check_mode: no
  29. - name: "Template deployment file for {{ item }}"
  30. template:
  31. src: "{{ tripleo_role_name ~ '/' ~ ansible_hostname | lower ~ '/' ~ item }}"
  32. dest: "/var/lib/heat-config/check-mode/tripleo-config-download/{{ item ~ '-' ~ deployment_uuid }}.rendered"
  33. # variable_start/end are overridden since the Heat template must be
  34. # valid yaml, so the jinja expression must be wrapped in quotes in the
  35. # Heat templates. Now, the extra quotes must be removed so that they do
  36. # not end up in the final rendered value. Also, $$ is used as the delimiter
  37. # for the jinja expression since { and } are reserved in yaml.
  38. variable_start_string: "\"$$"
  39. variable_end_string: "$$\""
  40. - name: "Slurp remote deployment file for {{ item }}"
  41. slurp:
  42. src: "/var/lib/heat-config/check-mode/tripleo-config-download/{{ item ~ '-' ~ deployment_uuid }}.rendered"
  43. register: deployment_content
  44. - name: "Remote copy deployment file for {{ item }}"
  45. copy:
  46. content: "[ {{ deployment_content.content | b64decode | from_yaml | json_query(item_only) }} ]"
  47. dest: "/var/lib/heat-config/check-mode/tripleo-config-download/{{ item ~ '-' ~ deployment_uuid }}"
  48. - name: Run hiera deployment for check mode
  49. shell: |
  50. rm -f /var/lib/heat-config/check-mode/{{ deployment_uuid }}.json
  51. /usr/libexec/os-refresh-config/configure.d/55-heat-config
  52. exit $(jq .deploy_status_code /var/lib/heat-config/check-mode/{{ deployment_uuid }}.notify.json)
  53. args:
  54. warn: false
  55. become: true
  56. environment:
  57. HEAT_SHELL_CONFIG: /var/lib/heat-config/tripleo-config-download/check-mode/{{ item ~ '-' ~ deployment_uuid }}
  58. HEAT_PUPPET_HIERA_DATADIR: /etc/puppet/check-mode/hieradata
  59. HEAT_HIERA_CONFIG: /etc/puppet/check-mode/hiera.yaml
  60. HEAT_CONFIG_DEPLOYED: /var/lib/heat-config/check-mode
  61. check_mode: no
  62. ignore_errors: yes
  63. - name: List hieradata files for check mode
  64. find:
  65. path: /etc/puppet/check-mode/hieradata
  66. register: hieradata_files
  67. check_mode: no
  68. - name: diff hieradata changes for check mode
  69. command:
  70. diff -uN {{ hieradata_item.path | regex_replace('check-mode', '') }} {{ hieradata_item.path }}
  71. with_items: "{{ hieradata_files.files }}"
  72. check_mode: no
  73. register: diff_results
  74. changed_when: diff_results.rc == 1
  75. loop_control:
  76. loop_var: hieradata_item
  77. label: "{{ hieradata_item.path }}"
  78. failed_when: false
  79. when: ansible_diff_mode|bool
  80. - name: diff hieradata changes for check mode
  81. debug:
  82. var: item.stdout_lines
  83. with_items: "{{ diff_results.results }}"
  84. changed_when: item.rc == 1
  85. loop_control:
  86. label: "{{ item._ansible_item_label }}"
  87. when: ansible_diff_mode|bool
  88. - name: hiera.yaml changes for check mode
  89. command:
  90. diff -uN /etc/puppet/hiera.yaml /etc/puppet/check-mode/hiera.yaml
  91. check_mode: no
  92. register: diff_results
  93. changed_when: diff_results.rc == 1
  94. failed_when: false
  95. - name: diff hiera.yaml changes for check mode
  96. debug:
  97. var: diff_results.stdout_lines
  98. changed_when: diff_results.rc == 1
  99. when: ansible_diff_mode|bool
  100. ignore_errors: yes
  101. when:
  102. - deployment_group == 'hiera'
  103. - ansible_check_mode|bool
  104. - name: "Template deployment file for {{ item }}"
  105. template:
  106. src: "{{ tripleo_role_name ~ '/' ~ ansible_hostname | lower ~ '/' ~ item }}"
  107. dest: "/var/lib/heat-config/tripleo-config-download/{{ item ~ '-' ~ deployment_uuid }}.rendered"
  108. # variable_start/end are overridden since the Heat template must be
  109. # valid yaml, so the jinja expression must be wrapped in quotes in the
  110. # Heat templates. Now, the extra quotes must be removed so that they do
  111. # not end up in the final rendered value. Also, $$ is used as the delimiter
  112. # for the jinja expression since { and } are reserved in yaml.
  113. variable_start_string: "\"$$"
  114. variable_end_string: "$$\""
  115. - name: "Slurp remote deployment file for {{ item }}"
  116. slurp:
  117. src: "/var/lib/heat-config/tripleo-config-download/{{ item ~ '-' ~ deployment_uuid }}.rendered"
  118. register: deployment_content
  119. - name: "Remote copy deployment file for {{ item }}"
  120. copy:
  121. content: "[ {{ deployment_content.content | b64decode | from_yaml | json_query(item_only) }} ]"
  122. dest: "/var/lib/heat-config/tripleo-config-download/{{ item ~ '-' ~ deployment_uuid }}"
  123. - name: "Check if deployed file exists for {{ item }}"
  124. stat:
  125. path: /var/lib/heat-config/deployed/{{ deployment_uuid }}.json
  126. register: deployed_file_stat
  127. - name: "Check previous deployment rc for {{ item }}"
  128. shell: |
  129. exit $(jq .deploy_status_code /var/lib/heat-config/deployed/{{ deployment_uuid }}.notify.json)
  130. register: previous_deployment_result
  131. ignore_errors: true
  132. failed_when: false
  133. when: deployed_file_stat.stat.exists
  134. - name: "Remove deployed file for {{ item }} when previous deployment failed"
  135. file:
  136. path: /var/lib/heat-config/deployed/{{ deployment_uuid }}.json
  137. state: absent
  138. become: true
  139. when:
  140. - not ansible_check_mode|bool
  141. - deployed_file_stat.stat.exists
  142. - previous_deployment_result.rc != 0
  143. - name: "Force remove deployed file for {{ item }}"
  144. file:
  145. path: /var/lib/heat-config/deployed/{{ deployment_uuid }}.json
  146. state: absent
  147. become: true
  148. when: (force | bool)
  149. - name: Set fact for async_deployment
  150. set_fact:
  151. use_async_deployment: "{{ (async_deployment | default(False)) or (item == 'NetworkDeployment') }}"
  152. - name: "Run deployment {{ item }}"
  153. shell: |
  154. /usr/libexec/os-refresh-config/configure.d/55-heat-config
  155. exit $(jq .deploy_status_code /var/lib/heat-config/deployed/{{ deployment_uuid }}.notify.json)
  156. become: true
  157. environment:
  158. HEAT_SHELL_CONFIG: /var/lib/heat-config/tripleo-config-download/{{ item ~ '-' ~ deployment_uuid }}
  159. register: deployment_sync_result
  160. ignore_errors: yes
  161. when: not use_async_deployment|bool
  162. - name: "Run async deployment {{ item }}"
  163. shell: |
  164. /usr/libexec/os-refresh-config/configure.d/55-heat-config
  165. exit $(jq .deploy_status_code /var/lib/heat-config/deployed/{{ deployment_uuid }}.notify.json)
  166. become: true
  167. environment:
  168. HEAT_SHELL_CONFIG: /var/lib/heat-config/tripleo-config-download/{{ item ~ '-' ~ deployment_uuid }}
  169. register: deployment_async_result
  170. ignore_errors: yes
  171. when: use_async_deployment|bool
  172. async: "{{ async_timeout | default(300) }}"
  173. poll: "{{ async_poll | default(3) }}"
  174. - name: "Output for sync deployment {{ item }}"
  175. debug:
  176. msg:
  177. - stderr: "{{ deployment_sync_result.stderr.split('\n') }}"
  178. - status_code: "{{ deployment_sync_result.rc }}"
  179. tags:
  180. - output
  181. failed_when: deployment_sync_result.rc != 0
  182. when: not ansible_check_mode|bool and not use_async_deployment|bool
  183. - name: "Output for async deployment {{ item }}"
  184. debug:
  185. msg:
  186. - stderr: "{{ deployment_async_result.stderr.split('\n') }}"
  187. - status_code: "{{ deployment_async_result.rc }}"
  188. tags:
  189. - output
  190. failed_when: deployment_async_result.rc != 0
  191. when: not ansible_check_mode|bool and use_async_deployment|bool
  192. - name: "Check-mode for Run deployment {{ item }} (changed status indicates deployment would run)"
  193. stat:
  194. path: /var/lib/heat-config/deployed/{{ deployment_uuid }}.json
  195. become: true
  196. register: deploy_exists
  197. changed_when: not deploy_exists.stat.exists
  198. when: ansible_check_mode|bool
  199. ignore_errors: yes