upgrade.yml 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. ---
  2. ###############################################################################
  3. # Evaluate host groups and gather facts
  4. ###############################################################################
  5. - name: Evaluate host groups
  6. include: ../../evaluate_groups.yml
  7. - name: Load openshift_facts
  8. hosts: oo_masters_to_config:oo_nodes_to_config:oo_etcd_to_config:oo_lb_to_config
  9. roles:
  10. - openshift_facts
  11. - name: Evaluate additional groups for upgrade
  12. hosts: localhost
  13. connection: local
  14. become: no
  15. tasks:
  16. - name: Evaluate etcd_hosts_to_backup
  17. add_host:
  18. name: "{{ item }}"
  19. groups: etcd_hosts_to_backup
  20. with_items: groups.oo_etcd_to_config if groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config | length > 0 else groups.oo_first_master
  21. ###############################################################################
  22. # Pre-upgrade checks
  23. ###############################################################################
  24. - name: Verify upgrade can proceed
  25. hosts: oo_first_master
  26. vars:
  27. openshift_master_ha: "{{ groups.oo_masters_to_config | length > 1 }}"
  28. target_version: "{{ '1.1' if deployment_type == 'origin' else '3.1' }}"
  29. gather_facts: no
  30. tasks:
  31. # Pacemaker is currently the only supported upgrade path for multiple masters
  32. - fail:
  33. msg: "openshift_master_cluster_method must be set to 'pacemaker'"
  34. when: openshift_master_ha | bool and ((openshift_master_cluster_method is not defined) or (openshift_master_cluster_method is defined and openshift_master_cluster_method != "pacemaker"))
  35. - fail:
  36. msg: >
  37. This upgrade is only supported for origin, openshift-enterprise, and online
  38. deployment types
  39. when: deployment_type not in ['origin','openshift-enterprise', 'online']
  40. - fail:
  41. msg: >
  42. openshift_pkg_version is {{ openshift_pkg_version }} which is not a
  43. valid version for a {{ target_version }} upgrade
  44. when: openshift_pkg_version is defined and openshift_pkg_version.split('-',1).1 | version_compare(target_version ,'<')
  45. # If this script errors out ansible will show the default stdout/stderr
  46. # which contains details for the user:
  47. - script: ../files/pre-upgrade-check
  48. - name: Verify upgrade can proceed
  49. hosts: oo_masters_to_config:oo_nodes_to_config
  50. vars:
  51. target_version: "{{ '1.1' if deployment_type == 'origin' else '3.1' }}"
  52. tasks:
  53. - name: Clean package cache
  54. command: "{{ ansible_pkg_mgr }} clean all"
  55. - set_fact:
  56. g_new_service_name: "{{ 'origin' if deployment_type =='origin' else 'atomic-openshift' }}"
  57. - name: Determine available versions
  58. script: ../files/rpm_versions.sh {{ g_new_service_name }} openshift
  59. register: g_versions_result
  60. - set_fact:
  61. g_aos_versions: "{{ g_versions_result.stdout | from_yaml }}"
  62. - set_fact:
  63. g_new_version: "{{ g_aos_versions.curr_version.split('-', 1).0 if g_aos_versions.avail_version is none else g_aos_versions.avail_version.split('-', 1).0 }}"
  64. when: openshift_pkg_version is not defined
  65. - set_fact:
  66. g_new_version: "{{ openshift_pkg_version | replace('-','') }}"
  67. when: openshift_pkg_version is defined
  68. - fail:
  69. msg: This playbook requires Origin 1.0.6 or later
  70. when: deployment_type == 'origin' and g_aos_versions.curr_version | version_compare('1.0.6','<')
  71. - fail:
  72. msg: Upgrade packages not found
  73. when: (g_aos_versions.avail_version | default(g_aos_versions.curr_version, true) | version_compare(target_version, '<'))
  74. - set_fact:
  75. pre_upgrade_complete: True
  76. ##############################################################################
  77. # Gate on pre-upgrade checks
  78. ##############################################################################
  79. - name: Gate on pre-upgrade checks
  80. hosts: localhost
  81. connection: local
  82. become: no
  83. vars:
  84. pre_upgrade_hosts: "{{ groups.oo_masters_to_config | union(groups.oo_nodes_to_config) }}"
  85. tasks:
  86. - set_fact:
  87. pre_upgrade_completed: "{{ hostvars
  88. | oo_select_keys(pre_upgrade_hosts)
  89. | oo_collect('inventory_hostname', {'pre_upgrade_complete': true}) }}"
  90. - set_fact:
  91. pre_upgrade_failed: "{{ pre_upgrade_hosts | difference(pre_upgrade_completed) }}"
  92. - fail:
  93. msg: "Upgrade cannot continue. The following hosts did not complete pre-upgrade checks: {{ pre_upgrade_failed | join(',') }}"
  94. when: pre_upgrade_failed | length > 0
  95. ###############################################################################
  96. # Backup etcd
  97. ###############################################################################
  98. - name: Backup etcd
  99. hosts: etcd_hosts_to_backup
  100. vars:
  101. embedded_etcd: "{{ openshift.master.embedded_etcd }}"
  102. timestamp: "{{ lookup('pipe', 'date +%Y%m%d%H%M%S') }}"
  103. roles:
  104. - openshift_facts
  105. tasks:
  106. # Ensure we persist the etcd role for this host in openshift_facts
  107. - openshift_facts:
  108. role: etcd
  109. local_facts: {}
  110. when: "'etcd' not in openshift"
  111. - stat: path=/var/lib/openshift
  112. register: var_lib_openshift
  113. - stat: path=/var/lib/origin
  114. register: var_lib_origin
  115. - name: Create origin symlink if necessary
  116. file: src=/var/lib/openshift/ dest=/var/lib/origin state=link
  117. when: var_lib_openshift.stat.exists == True and var_lib_origin.stat.exists == False
  118. # TODO: replace shell module with command and update later checks
  119. # We assume to be using the data dir for all backups.
  120. - name: Check available disk space for etcd backup
  121. shell: df --output=avail -k {{ openshift.common.data_dir }} | tail -n 1
  122. register: avail_disk
  123. # TODO: replace shell module with command and update later checks
  124. - name: Check current embedded etcd disk usage
  125. shell: du -k {{ openshift.etcd.etcd_data_dir }} | tail -n 1 | cut -f1
  126. register: etcd_disk_usage
  127. when: embedded_etcd | bool
  128. - name: Abort if insufficient disk space for etcd backup
  129. fail:
  130. msg: >
  131. {{ etcd_disk_usage.stdout }} Kb disk space required for etcd backup,
  132. {{ avail_disk.stdout }} Kb available.
  133. when: (embedded_etcd | bool) and (etcd_disk_usage.stdout|int > avail_disk.stdout|int)
  134. - name: Install etcd (for etcdctl)
  135. action: "{{ ansible_pkg_mgr }} name=etcd state=latest"
  136. - name: Generate etcd backup
  137. command: >
  138. etcdctl backup --data-dir={{ openshift.etcd.etcd_data_dir }}
  139. --backup-dir={{ openshift.common.data_dir }}/etcd-backup-{{ timestamp }}
  140. - set_fact:
  141. etcd_backup_complete: True
  142. - name: Display location of etcd backup
  143. debug:
  144. msg: "Etcd backup created in {{ openshift.common.data_dir }}/etcd-backup-{{ timestamp }}"
  145. ##############################################################################
  146. # Gate on etcd backup
  147. ##############################################################################
  148. - name: Gate on etcd backup
  149. hosts: localhost
  150. connection: local
  151. become: no
  152. tasks:
  153. - set_fact:
  154. etcd_backup_completed: "{{ hostvars
  155. | oo_select_keys(groups.etcd_hosts_to_backup)
  156. | oo_collect('inventory_hostname', {'etcd_backup_complete': true}) }}"
  157. - set_fact:
  158. etcd_backup_failed: "{{ groups.etcd_hosts_to_backup | difference(etcd_backup_completed) }}"
  159. - fail:
  160. msg: "Upgrade cannot continue. The following hosts did not complete etcd backup: {{ etcd_backup_failed | join(',') }}"
  161. when: etcd_backup_failed | length > 0
  162. ###############################################################################
  163. # Upgrade Masters
  164. ###############################################################################
  165. - name: Create temp directory for syncing certs
  166. hosts: localhost
  167. connection: local
  168. become: no
  169. gather_facts: no
  170. tasks:
  171. - name: Create local temp directory for syncing certs
  172. local_action: command mktemp -d /tmp/openshift-ansible-XXXXXXX
  173. register: g_master_mktemp
  174. changed_when: False
  175. - name: Update deployment type
  176. hosts: oo_masters_to_config:oo_nodes_to_config:oo_etcd_to_config
  177. vars:
  178. openshift_deployment_type: "{{ deployment_type }}"
  179. roles:
  180. - openshift_facts
  181. - name: Update master facts
  182. hosts: oo_masters_to_config
  183. roles:
  184. - openshift_facts
  185. post_tasks:
  186. - openshift_facts:
  187. role: master
  188. local_facts:
  189. cluster_method: "{{ openshift_master_cluster_method | default(None) }}"
  190. - name: Upgrade master packages and configuration
  191. hosts: oo_masters_to_config
  192. vars:
  193. openshift_version: "{{ openshift_pkg_version | default('') }}"
  194. roles:
  195. - openshift_facts
  196. tasks:
  197. - name: Upgrade to latest available kernel
  198. action: "{{ ansible_pkg_mgr}} name=kernel state=latest"
  199. - name: Upgrade master packages
  200. command: "{{ ansible_pkg_mgr}} update -y {{ openshift.common.service_type }}-master{{ openshift_version }}"
  201. when: openshift_pkg_version is not defined
  202. - name: Upgrade packages
  203. command: "{{ ansible_pkg_mgr}} install -y {{ openshift.common.installed_variant_rpms | oo_31_rpm_rename_conversion(openshift_version) | join (' ')}}"
  204. when: openshift_pkg_version is defined and deployment_type == 'openshift-enterprise'
  205. - name: Ensure python-yaml present for config upgrade
  206. action: "{{ ansible_pkg_mgr }} name=PyYAML state=present"
  207. when: not openshift.common.is_atomic | bool
  208. - name: Upgrade master configuration
  209. openshift_upgrade_config:
  210. from_version: '3.0'
  211. to_version: '3.1'
  212. role: master
  213. config_base: "{{ hostvars[inventory_hostname].openshift.common.config_base }}"
  214. - set_fact:
  215. openshift_master_certs_no_etcd:
  216. - admin.crt
  217. - master.kubelet-client.crt
  218. - "{{ 'master.proxy-client.crt' if openshift.common.version_gte_3_1_or_1_1 else omit }}"
  219. - master.server.crt
  220. - openshift-master.crt
  221. - openshift-registry.crt
  222. - openshift-router.crt
  223. - etcd.server.crt
  224. openshift_master_certs_etcd:
  225. - master.etcd-client.crt
  226. - set_fact:
  227. openshift_master_certs: "{{ (openshift_master_certs_no_etcd | union(openshift_master_certs_etcd)) if (groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config) else openshift_master_certs_no_etcd }}"
  228. - name: Check status of master certificates
  229. stat:
  230. path: "{{ openshift.common.config_base }}/master/{{ item }}"
  231. with_items: openshift_master_certs
  232. register: g_master_cert_stat_result
  233. - set_fact:
  234. master_certs_missing: "{{ False in (g_master_cert_stat_result.results
  235. | oo_collect(attribute='stat.exists')
  236. | list ) }}"
  237. master_cert_subdir: master-{{ openshift.common.hostname }}
  238. master_cert_config_dir: "{{ openshift.common.config_base }}/master"
  239. - name: Generate missing master certificates
  240. hosts: oo_first_master
  241. vars:
  242. master_hostnames: "{{ hostvars
  243. | oo_select_keys(groups.oo_masters_to_config)
  244. | oo_collect('openshift.common.all_hostnames')
  245. | oo_flatten | unique }}"
  246. master_generated_certs_dir: "{{ openshift.common.config_base }}/generated-configs"
  247. masters_needing_certs: "{{ hostvars
  248. | oo_select_keys(groups['oo_masters_to_config'] | difference(groups['oo_first_master']))
  249. | oo_filter_list(filter_attr='master_certs_missing') }}"
  250. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  251. openshift_deployment_type: "{{ deployment_type }}"
  252. roles:
  253. - openshift_master_certificates
  254. post_tasks:
  255. - name: Remove generated etcd client certs when using external etcd
  256. file:
  257. path: "{{ master_generated_certs_dir }}/{{ item.0.master_cert_subdir }}/{{ item.1 }}"
  258. state: absent
  259. when: groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config
  260. with_nested:
  261. - masters_needing_certs
  262. - - master.etcd-client.crt
  263. - master.etcd-client.key
  264. - name: Create a tarball of the master certs
  265. command: >
  266. tar -czvf {{ master_generated_certs_dir }}/{{ item.master_cert_subdir }}.tgz
  267. -C {{ master_generated_certs_dir }}/{{ item.master_cert_subdir }} .
  268. with_items: masters_needing_certs
  269. - name: Retrieve the master cert tarball from the master
  270. fetch:
  271. src: "{{ master_generated_certs_dir }}/{{ item.master_cert_subdir }}.tgz"
  272. dest: "{{ sync_tmpdir }}/"
  273. flat: yes
  274. fail_on_missing: yes
  275. validate_checksum: yes
  276. with_items: masters_needing_certs
  277. - name: Sync generated certs, update service config and restart master services
  278. hosts: oo_masters_to_config
  279. vars:
  280. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  281. openshift_master_ha: "{{ groups.oo_masters_to_config | length > 1 }}"
  282. openshift_deployment_type: "{{ deployment_type }}"
  283. tasks:
  284. - name: Unarchive the tarball on the master
  285. unarchive:
  286. src: "{{ sync_tmpdir }}/{{ master_cert_subdir }}.tgz"
  287. dest: "{{ master_cert_config_dir }}"
  288. when: inventory_hostname != groups.oo_first_master.0
  289. - name: Restart master service
  290. service: name="{{ openshift.common.service_type}}-master" state=restarted
  291. when: not openshift_master_ha | bool
  292. - name: Ensure the master service is enabled
  293. service: name="{{ openshift.common.service_type}}-master" state=started enabled=yes
  294. when: not openshift_master_ha | bool
  295. - name: Check for configured cluster
  296. stat:
  297. path: /etc/corosync/corosync.conf
  298. register: corosync_conf
  299. when: openshift_master_ha | bool
  300. - name: Destroy cluster
  301. command: pcs cluster destroy --all
  302. when: openshift_master_ha | bool and corosync_conf.stat.exists == true
  303. run_once: true
  304. - name: Start pcsd
  305. service: name=pcsd enabled=yes state=started
  306. when: openshift_master_ha | bool
  307. - name: Re-create cluster
  308. hosts: oo_first_master
  309. vars:
  310. openshift_master_ha: "{{ groups.oo_masters_to_config | length > 1 }}"
  311. openshift_deployment_type: "{{ deployment_type }}"
  312. omc_cluster_hosts: "{{ groups.oo_masters_to_config | join(' ') }}"
  313. roles:
  314. - role: openshift_master_cluster
  315. when: openshift_master_ha | bool
  316. - name: Delete temporary directory on localhost
  317. hosts: localhost
  318. connection: local
  319. become: no
  320. gather_facts: no
  321. tasks:
  322. - file: name={{ g_master_mktemp.stdout }} state=absent
  323. changed_when: False
  324. - name: Set master update status to complete
  325. hosts: oo_masters_to_config
  326. tasks:
  327. - set_fact:
  328. master_update_complete: True
  329. ##############################################################################
  330. # Gate on master update complete
  331. ##############################################################################
  332. - name: Gate on master update
  333. hosts: localhost
  334. connection: local
  335. become: no
  336. tasks:
  337. - set_fact:
  338. master_update_completed: "{{ hostvars
  339. | oo_select_keys(groups.oo_masters_to_config)
  340. | oo_collect('inventory_hostname', {'master_update_complete': true}) }}"
  341. - set_fact:
  342. master_update_failed: "{{ groups.oo_masters_to_config | difference(master_update_completed) }}"
  343. - fail:
  344. msg: "Upgrade cannot continue. The following masters did not finish updating: {{ master_update_failed | join(',') }}"
  345. when: master_update_failed | length > 0
  346. ###############################################################################
  347. # Upgrade Nodes
  348. ###############################################################################
  349. - name: Upgrade nodes
  350. hosts: oo_nodes_to_config
  351. vars:
  352. openshift_version: "{{ openshift_pkg_version | default('') }}"
  353. roles:
  354. - openshift_facts
  355. tasks:
  356. - name: Upgrade node packages
  357. command: "{{ ansible_pkg_mgr }} update -y {{ openshift.common.service_type }}-node{{ openshift_version }}"
  358. when: openshift_pkg_version is not defined
  359. - name: Upgrade packages
  360. command: "{{ ansible_pkg_mgr}} install -y {{ openshift.common.installed_variant_rpms | oo_31_rpm_rename_conversion(openshift_version) | join (' ')}}"
  361. when: openshift_pkg_version is defined and deployment_type == 'openshift-enterprise'
  362. - name: Restart node service
  363. service: name="{{ openshift.common.service_type }}-node" state=restarted
  364. - name: Ensure node service enabled
  365. service: name="{{ openshift.common.service_type }}-node" state=started enabled=yes
  366. - name: Install Ceph storage plugin dependencies
  367. action: "{{ ansible_pkg_mgr }} name=ceph-common state=present"
  368. - name: Install GlusterFS storage plugin dependencies
  369. action: "{{ ansible_pkg_mgr }} name=glusterfs-fuse state=present"
  370. - name: Set sebooleans to allow gluster storage plugin access from containers
  371. seboolean:
  372. name: "{{ item }}"
  373. state: yes
  374. persistent: yes
  375. when: ansible_selinux and ansible_selinux.status == "enabled"
  376. with_items:
  377. - virt_use_fusefs
  378. - virt_sandbox_use_fusefs
  379. register: sebool_result
  380. failed_when: "'state' not in sebool_result and 'msg' in sebool_result and 'SELinux boolean {{ item }} does not exist' not in sebool_result.msg"
  381. - set_fact:
  382. node_update_complete: True
  383. ##############################################################################
  384. # Gate on nodes update
  385. ##############################################################################
  386. - name: Gate on nodes update
  387. hosts: localhost
  388. connection: local
  389. become: no
  390. tasks:
  391. - set_fact:
  392. node_update_completed: "{{ hostvars
  393. | oo_select_keys(groups.oo_nodes_to_config)
  394. | oo_collect('inventory_hostname', {'node_update_complete': true}) }}"
  395. - set_fact:
  396. node_update_failed: "{{ groups.oo_nodes_to_config | difference(node_update_completed) }}"
  397. - fail:
  398. msg: "Upgrade cannot continue. The following nodes did not finish updating: {{ node_update_failed | join(',') }}"
  399. when: node_update_failed | length > 0
  400. ###############################################################################
  401. # Post upgrade - Reconcile Cluster Roles and Cluster Role Bindings
  402. ###############################################################################
  403. - name: Reconcile Cluster Roles and Cluster Role Bindings
  404. hosts: oo_masters_to_config
  405. vars:
  406. origin_reconcile_bindings: "{{ deployment_type == 'origin' and g_new_version | version_compare('1.0.6', '>') }}"
  407. ent_reconcile_bindings: true
  408. openshift_master_ha: "{{ groups.oo_masters_to_config | length > 1 }}"
  409. tasks:
  410. - name: Reconcile Cluster Roles
  411. command: >
  412. {{ openshift.common.admin_binary}} --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  413. policy reconcile-cluster-roles --confirm
  414. run_once: true
  415. - name: Reconcile Cluster Role Bindings
  416. command: >
  417. {{ openshift.common.admin_binary}} --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  418. policy reconcile-cluster-role-bindings
  419. --exclude-groups=system:authenticated
  420. --exclude-groups=system:authenticated:oauth
  421. --exclude-groups=system:unauthenticated
  422. --exclude-users=system:anonymous
  423. --additive-only=true --confirm
  424. when: origin_reconcile_bindings | bool or ent_reconcile_bindings | bool
  425. run_once: true
  426. - name: Restart master services
  427. service: name="{{ openshift.common.service_type}}-master" state=restarted
  428. when: not openshift_master_ha | bool
  429. - name: Restart master cluster
  430. command: pcs resource restart master
  431. when: openshift_master_ha | bool
  432. run_once: true
  433. - name: Wait for the clustered master service to be available
  434. wait_for:
  435. host: "{{ openshift_master_cluster_vip }}"
  436. port: 8443
  437. state: started
  438. timeout: 180
  439. delay: 90
  440. when: openshift_master_ha | bool
  441. run_once: true
  442. - set_fact:
  443. reconcile_complete: True
  444. ##############################################################################
  445. # Gate on reconcile
  446. ##############################################################################
  447. - name: Gate on reconcile
  448. hosts: localhost
  449. connection: local
  450. become: no
  451. tasks:
  452. - set_fact:
  453. reconcile_completed: "{{ hostvars
  454. | oo_select_keys(groups.oo_masters_to_config)
  455. | oo_collect('inventory_hostname', {'reconcile_complete': true}) }}"
  456. - set_fact:
  457. reconcile_failed: "{{ groups.oo_masters_to_config | difference(reconcile_completed) }}"
  458. - fail:
  459. msg: "Upgrade cannot continue. The following masters did not finish reconciling: {{ reconcile_failed | join(',') }}"
  460. when: reconcile_failed | length > 0
  461. ###############################################################################
  462. # Post upgrade - Upgrade default router, default registry and examples
  463. ###############################################################################
  464. - name: Upgrade default router and default registry
  465. hosts: oo_first_master
  466. vars:
  467. openshift_deployment_type: "{{ deployment_type }}"
  468. registry_image: "{{ openshift.master.registry_url | replace( '${component}', 'docker-registry' ) | replace ( '${version}', 'v' + g_new_version ) }}"
  469. router_image: "{{ openshift.master.registry_url | replace( '${component}', 'haproxy-router' ) | replace ( '${version}', 'v' + g_new_version ) }}"
  470. oc_cmd: "{{ openshift.common.client_binary }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig"
  471. roles:
  472. # Create the new templates shipped in 3.1, existing templates are left
  473. # unmodified. This prevents the subsequent role definition for
  474. # openshift_examples from failing when trying to replace templates that do
  475. # not already exist. We could have potentially done a replace --force to
  476. # create and update in one step.
  477. - openshift_examples
  478. # Update the existing templates
  479. - role: openshift_examples
  480. openshift_examples_import_command: replace
  481. pre_tasks:
  482. - name: Collect all routers
  483. command: >
  484. {{ oc_cmd }} get pods --all-namespaces -l 'router' -o json
  485. register: all_routers
  486. failed_when: false
  487. changed_when: false
  488. - set_fact: haproxy_routers="{{ (all_routers.stdout | from_json)['items'] | oo_pods_match_component(openshift_deployment_type, 'haproxy-router') | oo_select_keys_from_list(['metadata']) }}"
  489. when: all_routers.rc == 0
  490. - set_fact: haproxy_routers=[]
  491. when: all_routers.rc != 0
  492. - name: Check for allowHostNetwork and allowHostPorts
  493. when: all_routers.rc == 0
  494. shell: >
  495. {{ oc_cmd }} get -o yaml scc/privileged | /usr/bin/grep -e allowHostPorts -e allowHostNetwork
  496. register: _scc
  497. - name: Grant allowHostNetwork and allowHostPorts
  498. when:
  499. - all_routers.rc == 0
  500. - "'false' in _scc.stdout"
  501. command: >
  502. {{ oc_cmd }} patch scc/privileged -p
  503. '{"allowHostPorts":true,"allowHostNetwork":true}' --api-version=v1
  504. - name: Update deployment config to 1.0.4/3.0.1 spec
  505. when: all_routers.rc == 0
  506. command: >
  507. {{ oc_cmd }} patch dc/{{ item['labels']['deploymentconfig'] }} -p
  508. '{"spec":{"strategy":{"rollingParams":{"updatePercent":-10},"spec":{"serviceAccount":"router","serviceAccountName":"router"}}}}'
  509. --api-version=v1
  510. with_items: haproxy_routers
  511. - name: Switch to hostNetwork=true
  512. when: all_routers.rc == 0
  513. command: >
  514. {{ oc_cmd }} patch dc/{{ item['labels']['deploymentconfig'] }} -p '{"spec":{"template":{"spec":{"hostNetwork":true}}}}'
  515. --api-version=v1
  516. with_items: haproxy_routers
  517. - name: Update router image to current version
  518. when: all_routers.rc == 0
  519. command: >
  520. {{ oc_cmd }} patch dc/{{ item['labels']['deploymentconfig'] }} -p
  521. '{"spec":{"template":{"spec":{"containers":[{"name":"router","image":"{{ router_image }}"}]}}}}'
  522. --api-version=v1
  523. with_items: haproxy_routers
  524. when: not openshift.common.version_gte_3_1_1_or_1_1_1
  525. - name: Update router image to current version
  526. when: all_routers.rc == 0
  527. command: >
  528. {{ oc_cmd }} patch dc/{{ item['labels']['deploymentconfig'] }} -p
  529. '{"spec":{"template":{"spec":{"containers":[{"name":"router","image":"{{ router_image }}","livenessProbe":{"tcpSocket":null,"httpGet":{"path": "/healthz", "port": 1936, "host": "localhost", "scheme": "HTTP"},"initialDelaySeconds":10,"timeoutSeconds":1}}]}}}}'
  530. --api-version=v1
  531. with_items: haproxy_routers
  532. when: openshift.common.version_gte_3_1_1_or_1_1_1
  533. - name: Check for default registry
  534. command: >
  535. {{ oc_cmd }} get -n default dc/docker-registry
  536. register: _default_registry
  537. failed_when: false
  538. changed_when: false
  539. - name: Update registry image to current version
  540. when: _default_registry.rc == 0
  541. command: >
  542. {{ oc_cmd }} patch dc/docker-registry -p
  543. '{"spec":{"template":{"spec":{"containers":[{"name":"registry","image":"{{ registry_image }}"}]}}}}'
  544. --api-version=v1