Heat templates for deploying OpenStack
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.

290 lines
12KB

  1. # Note the indentation here is required as it's joined
  2. # to create a playbook in deploy-steps.j2
  3. #####################################################
  4. # Per step puppet configuration of the baremetal host
  5. #####################################################
  6. - name: Write the config_step hieradata
  7. no_log: True
  8. copy:
  9. content: "{{ dict(step=step|int) | to_json }}"
  10. dest: /etc/puppet/{{ ansible_check_mode | bool | ternary('check-mode/', '') }}hieradata/config_step.json
  11. force: true
  12. mode: '0600'
  13. check_mode: no
  14. tags:
  15. - host_config
  16. - name: Run puppet host configuration for step {{ step }}
  17. async: 3600
  18. poll: 0
  19. when: enable_puppet|bool
  20. shell: >-
  21. set -o pipefail;
  22. puppet apply {{ host_puppet_config_debug | default('') }}
  23. --modulepath=/etc/puppet/modules:/opt/stack/puppet-modules:/usr/share/openstack-puppet/modules
  24. --detailed-exitcodes
  25. --summarize
  26. --color=false
  27. {{ ansible_check_mode | bool | ternary('--noop', '') }}
  28. {{ ansible_check_mode | bool | ternary('--hiera_config /etc/puppet/check-mode/hiera.yaml', '') }}
  29. /var/lib/tripleo-config/{{ ansible_check_mode | bool | ternary('check-mode/', '') }}puppet_step_config.pp
  30. 2>&1 | logger -s -t puppet-user
  31. register: puppet_host_async_result
  32. no_log: true
  33. tags:
  34. - host_config
  35. check_mode: no
  36. - name: Wait for puppet host configuration to finish
  37. async_status:
  38. jid: "{{ puppet_host_async_result.ansible_job_id }}"
  39. register: puppet_host_outputs
  40. until: puppet_host_outputs.finished
  41. retries: 1200
  42. delay: 3
  43. failed_when:
  44. - (not puppet_host_outputs.finished) or (puppet_host_outputs.rc is defined and puppet_host_outputs.rc not in [0, 2])
  45. tags:
  46. - host_config
  47. - name: "Debug output for task: Run puppet host configuration for step {{ step }}"
  48. debug:
  49. var: puppet_host_outputs.stdout_lines | default([]) | union(puppet_host_outputs.stderr_lines | default([]))
  50. when:
  51. - enable_puppet | bool
  52. - puppet_host_outputs.rc is defined
  53. changed_when: puppet_host_outputs.rc == 2
  54. failed_when: puppet_host_outputs.rc not in [0, 2]
  55. tags:
  56. - host_config
  57. ignore_errors: "{{ ansible_check_mode|bool }}"
  58. #########################################
  59. # Pre-cache facts for container-puppet.py
  60. #########################################
  61. # We don't want the pre-cache tasks to be skipped in dry-run so we force
  62. # check_mode to "no".
  63. # https://bugzilla.redhat.com/show_bug.cgi?id=1738529
  64. - name: Pre-cache facts for container-puppet.py
  65. include_role:
  66. name: tripleo-puppet-cache
  67. tags:
  68. - container_config
  69. - container_config_tasks
  70. ######################################
  71. # Generate config via container-puppet.py
  72. ######################################
  73. - name: Run container-puppet tasks (generate config) during step {{ step }}
  74. async: 3600
  75. poll: 0
  76. shell: "{{ python_cmd }} /var/lib/container-puppet/container-puppet.py"
  77. environment:
  78. NET_HOST: 'true'
  79. DEBUG: '{{ docker_puppet_debug | bool }}'
  80. PROCESS_COUNT: "{{ docker_puppet_process_count }}"
  81. CONTAINER_CLI: "{{ container_cli }}"
  82. CONFIG: '/var/lib/container-puppet/{{ ansible_check_mode | bool | ternary("check-mode/", "") }}container-puppet.json'
  83. CONFIG_VOLUME_PREFIX: '/var/lib/config-data{{ ansible_check_mode | bool | ternary("/check-mode", "") }}'
  84. CHECK_MODE: '{{ ansible_check_mode | bool | ternary(1, 0) }}'
  85. STARTUP_CONFIG_PATTERN: '/var/lib/tripleo-config/container-startup-config/*/{{ ansible_check_mode | bool | ternary("check-mode/", "") }}*.json'
  86. MOUNT_HOST_PUPPET: '{{docker_puppet_mount_host_puppet | default(true)}}'
  87. CONTAINER_LOG_STDOUT_PATH: "{{ container_log_stdout_path }}"
  88. CONTAINER_HEALTHCHECK_DISABLED: "{{ container_healthcheck_disabled }}"
  89. SHORT_HOSTNAME: "{{ ansible_hostname }}"
  90. when: step|int == 1
  91. check_mode: no
  92. register: generate_config_async_result
  93. tags:
  94. - container_config
  95. - name: Wait for container-puppet tasks (generate config) to finish
  96. async_status:
  97. jid: "{{ generate_config_async_result.ansible_job_id }}"
  98. register: generate_config_outputs
  99. until: generate_config_outputs.finished
  100. retries: 1200
  101. delay: 3
  102. when: step|int == 1
  103. tags:
  104. - container_config
  105. - name: "Debug output for task: Run container-puppet tasks (generate config) during step {{ step }}"
  106. debug:
  107. var: generate_config_outputs.stdout_lines | default([]) | union(generate_config_outputs.stderr_lines | default([]))
  108. when: generate_config_outputs.rc is defined
  109. failed_when: generate_config_outputs.rc != 0
  110. tags:
  111. - container_config
  112. ignore_errors: "{{ ansible_check_mode|bool }}"
  113. - name: Diff container-puppet.py puppet-generated changes for check mode
  114. shell: |
  115. diff -ruN --no-dereference -q /var/lib/config-data/puppet-generated /var/lib/config-data/check-mode/puppet-generated
  116. diff -ruN --no-dereference /var/lib/config-data/puppet-generated /var/lib/config-data/check-mode/puppet-generated
  117. register: diff_results
  118. tags:
  119. - container_config
  120. check_mode: no
  121. when:
  122. - step|int == 1
  123. - ansible_check_mode|bool
  124. - ansible_diff_mode
  125. failed_when: false
  126. changed_when: diff_results.rc == 1
  127. - name: Diff container-puppet.py puppet-generated changes for check mode
  128. debug:
  129. var: diff_results.stdout_lines
  130. changed_when: diff_results.rc == 1
  131. when:
  132. - step|int == 1
  133. - ansible_check_mode|bool
  134. - ansible_diff_mode
  135. tags:
  136. - container_config
  137. #####################################
  138. # Per step starting of the containers
  139. #####################################
  140. # Note container-puppet.py generates the hashed-*.json file, which is a copy of
  141. # the *step_n.json with a hash of the generated external config added
  142. # This acts as a salt to enable restarting the container if config changes
  143. - name: Per step starting of the containers using Paunch
  144. when: enable_paunch|default(true)
  145. block:
  146. - name: Start containers for step {{ step }} using paunch
  147. async: 3600
  148. poll: 0
  149. environment:
  150. TRIPLEO_MINOR_UPDATE: '{{ tripleo_minor_update | default(false) }}'
  151. paunch:
  152. config: "/var/lib/tripleo-config/container-startup-config/step_{{ step }}"
  153. config_id: "tripleo_step{{ step }}"
  154. action: apply
  155. container_cli: "{{ container_cli }}"
  156. container_log_stdout_path: "{{ container_log_stdout_path }}"
  157. healthcheck_disabled: "{{ container_healthcheck_disabled | bool }}"
  158. managed_by: "tripleo-{{ tripleo_role_name }}"
  159. debug: "{{ enable_debug | bool }}"
  160. register: start_containers_async_result
  161. tags:
  162. - container_startup_configs
  163. - name: Wait for containers to start for step {{ step }} using paunch
  164. async_status:
  165. jid: "{{ start_containers_async_result.ansible_job_id }}"
  166. register: start_containers_outputs
  167. until: start_containers_outputs.finished
  168. retries: 1200
  169. delay: 3
  170. tags:
  171. - container_startup_configs
  172. - name: "Debug output for task: Start containers for step {{ step }}"
  173. debug:
  174. var: start_containers_outputs.stdout_lines | default([]) | union(start_containers_outputs.stderr_lines | default([]))
  175. when: start_containers_outputs.rc is defined
  176. failed_when: start_containers_outputs.rc != 0
  177. tags:
  178. - container_startup_configs
  179. # This is experimental, do not use for production now
  180. - name: Per step starting of the containers using tripleo-ansible
  181. when: not enable_paunch|default(true)
  182. environment:
  183. TRIPLEO_MINOR_UPDATE: '{{ tripleo_minor_update | default(false) }}'
  184. block:
  185. - name: "Manage containers for step {{ step }} with tripleo-ansible"
  186. include_role:
  187. name: tripleo-container-manage
  188. vars:
  189. tripleo_container_manage_concurrency: 2
  190. tripleo_container_manage_systemd_order: true
  191. tripleo_container_manage_cli: "{{ container_cli }}"
  192. tripleo_container_manage_config: "/var/lib/tripleo-config/container-startup-config/step_{{ step }}"
  193. tripleo_container_manage_config_id: "tripleo_step{{ step }}"
  194. tripleo_container_manage_debug: "{{ enable_debug | bool }}"
  195. tripleo_container_manage_healthcheck_disabled: "{{ container_healthcheck_disabled | bool }}"
  196. tripleo_container_manage_log_path: "{{ container_log_stdout_path }}"
  197. tags:
  198. - container_startup_configs
  199. ########################################################
  200. # Bootstrap tasks - run any tasks that have been defined
  201. ########################################################
  202. - name: "Clean container_puppet_tasks for {{ansible_hostname}} step {{step}}"
  203. file:
  204. path: /var/lib/container-puppet/container-puppet-tasks{{step}}.json
  205. state: absent
  206. tags:
  207. - container_config_tasks
  208. - name: Calculate container_puppet_tasks for {{ansible_hostname}} step {{step}}
  209. set_fact:
  210. host_container_puppet_tasks: "{{host_container_puppet_tasks|default([]) + [item]}}"
  211. loop: "{{container_puppet_tasks.get('step_' + step, [])}}"
  212. when: (groups[item.service_name] | default ([]) | map('extract', hostvars, 'inventory_hostname') | sort | first) == ansible_hostname
  213. vars:
  214. container_puppet_tasks: "{{ lookup('file', tripleo_role_name + '/container_puppet_tasks.yaml', errors='ignore') | default({}, True) | from_yaml }}"
  215. tags:
  216. - container_config_tasks
  217. - name: Write container-puppet-tasks json file for {{ansible_hostname}} step {{step}}
  218. no_log: True
  219. copy:
  220. content: "{{host_container_puppet_tasks|to_nice_json}}"
  221. dest: "/var/lib/container-puppet/container-puppet-tasks{{step}}.json"
  222. force: yes
  223. mode: '0600'
  224. tags:
  225. - container_config_tasks
  226. when: host_container_puppet_tasks is defined
  227. - name: Run container-puppet tasks (bootstrap tasks) for step {{ step }}
  228. async: 3600
  229. poll: 0
  230. shell: "{{ python_cmd }} /var/lib/container-puppet/container-puppet.py"
  231. environment:
  232. CONFIG: /var/lib/container-puppet/{{ ansible_check_mode | bool | ternary('check-mode/', '') }}container-puppet-tasks{{ step }}.json
  233. CONFIG_VOLUME_PREFIX: '/var/lib/config-data{{ ansible_check_mode | bool | ternary("/check-mode", "") }}'
  234. NET_HOST: "true"
  235. NO_ARCHIVE: "true"
  236. STEP: "{{ step }}"
  237. CONTAINER_CLI: "{{ container_cli }}"
  238. DEBUG: "{{ docker_puppet_debug }}"
  239. MOUNT_HOST_PUPPET: '{{docker_puppet_mount_host_puppet}}'
  240. SHORT_HOSTNAME: "{{ ansible_hostname }}"
  241. PROCESS_COUNT: "{{ docker_puppet_process_count }}"
  242. when: host_container_puppet_tasks is defined
  243. register: bootstrap_tasks_async_result
  244. no_log: true
  245. tags:
  246. - container_config_tasks
  247. - name: Wait for container-puppet tasks (bootstrap tasks) for step {{ step }} to finish
  248. async_status:
  249. jid: "{{ bootstrap_tasks_async_result.ansible_job_id }}"
  250. register: bootstrap_tasks_outputs
  251. until: bootstrap_tasks_outputs.finished
  252. retries: 1200
  253. delay: 3
  254. when: host_container_puppet_tasks is defined
  255. tags:
  256. - container_config_tasks
  257. - name: "Debug output for task: Run container-puppet tasks (bootstrap tasks) for step {{ step }}"
  258. debug:
  259. var: bootstrap_tasks_outputs.stdout_lines | default([]) | union(bootstrap_tasks_outputs.stderr_lines | default([]))
  260. when:
  261. - host_container_puppet_tasks is defined
  262. - bootstrap_tasks_outputs.rc is defined
  263. failed_when: bootstrap_tasks_outputs.rc != 0
  264. tags:
  265. - container_config_tasks