main.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. ---
  2. # TODO: add validation for openshift_master_identity_providers
  3. # TODO: add ability to configure certificates given either a local file to
  4. # point to or certificate contents, set in default cert locations.
  5. - assert:
  6. that:
  7. - openshift_master_oauth_grant_method in openshift_master_valid_grant_methods
  8. when: openshift_master_oauth_grant_method is defined
  9. #- fail:
  10. # msg: "openshift_master_cluster_password must be set for multi-master installations"
  11. # when: openshift_master_ha | bool and not openshift.master.cluster_defer_ha | bool and openshift_master_cluster_password is not defined
  12. - name: Set master facts
  13. openshift_facts:
  14. role: master
  15. local_facts:
  16. cluster_hostname: "{{ openshift_master_cluster_hostname | default(None) }}"
  17. cluster_public_hostname: "{{ openshift_master_cluster_public_hostname | default(None) }}"
  18. cluster_defer_ha: "{{ openshift_master_cluster_defer_ha | default(None) }}"
  19. debug_level: "{{ openshift_master_debug_level | default(openshift.common.debug_level) }}"
  20. api_port: "{{ openshift_master_api_port | default(None) }}"
  21. api_url: "{{ openshift_master_api_url | default(None) }}"
  22. api_use_ssl: "{{ openshift_master_api_use_ssl | default(None) }}"
  23. public_api_url: "{{ openshift_master_public_api_url | default(None) }}"
  24. console_path: "{{ openshift_master_console_path | default(None) }}"
  25. console_port: "{{ openshift_master_console_port | default(None) }}"
  26. console_url: "{{ openshift_master_console_url | default(None) }}"
  27. console_use_ssl: "{{ openshift_master_console_use_ssl | default(None) }}"
  28. public_console_url: "{{ openshift_master_public_console_url | default(None) }}"
  29. etcd_hosts: "{{ openshift_master_etcd_hosts | default(None)}}"
  30. etcd_port: "{{ openshift_master_etcd_port | default(None) }}"
  31. etcd_use_ssl: "{{ openshift_master_etcd_use_ssl | default(None) }}"
  32. etcd_urls: "{{ openshift_master_etcd_urls | default(None) }}"
  33. embedded_etcd: "{{ openshift_master_embedded_etcd | default(None) }}"
  34. embedded_kube: "{{ openshift_master_embedded_kube | default(None) }}"
  35. embedded_dns: "{{ openshift_master_embedded_dns | default(None) }}"
  36. dns_port: "{{ openshift_master_dns_port | default(None) }}"
  37. bind_addr: "{{ openshift_master_bind_addr | default(None) }}"
  38. portal_net: "{{ openshift_master_portal_net | default(None) }}"
  39. session_max_seconds: "{{ openshift_master_session_max_seconds | default(None) }}"
  40. session_name: "{{ openshift_master_session_name | default(None) }}"
  41. session_secrets_file: "{{ openshift_master_session_secrets_file | default(None) }}"
  42. access_token_max_seconds: "{{ openshift_master_access_token_max_seconds | default(None) }}"
  43. auth_token_max_seconds: "{{ openshift_master_auth_token_max_seconds | default(None) }}"
  44. identity_providers: "{{ openshift_master_identity_providers | default(None) }}"
  45. registry_url: "{{ oreg_url | default(None) }}"
  46. oauth_grant_method: "{{ openshift_master_oauth_grant_method | default(None) }}"
  47. sdn_cluster_network_cidr: "{{ osm_cluster_network_cidr | default(None) }}"
  48. sdn_host_subnet_length: "{{ osm_host_subnet_length | default(None) }}"
  49. default_subdomain: "{{ osm_default_subdomain | default(None) }}"
  50. custom_cors_origins: "{{ osm_custom_cors_origins | default(None) }}"
  51. default_node_selector: "{{ osm_default_node_selector | default(None) }}"
  52. project_request_message: "{{ osm_project_request_message | default(None) }}"
  53. project_request_template: "{{ osm_project_request_template | default(None) }}"
  54. mcs_allocator_range: "{{ osm_mcs_allocator_range | default(None) }}"
  55. mcs_labels_per_project: "{{ osm_mcs_labels_per_project | default(None) }}"
  56. uid_allocator_range: "{{ osm_uid_allocator_range | default(None) }}"
  57. router_selector: "{{ openshift_router_selector | default(None) }}"
  58. registry_selector: "{{ openshift_registry_selector | default(None) }}"
  59. api_server_args: "{{ osm_api_server_args | default(None) }}"
  60. controller_args: "{{ osm_controller_args | default(None) }}"
  61. infra_nodes: "{{ num_infra | default(None) }}"
  62. disabled_features: "{{ osm_disabled_features | default(None) }}"
  63. master_count: "{{ openshift_master_count | default(None) }}"
  64. - name: Install Master package
  65. yum: pkg={{ openshift.common.service_type }}-master state=present
  66. register: install_result
  67. # TODO: These values need to be configurable
  68. - name: Set dns facts
  69. openshift_facts:
  70. role: dns
  71. local_facts:
  72. ip: "{{ openshift_master_cluster_vip | default(openshift.common.ip, true) | default(None) }}"
  73. domain: cluster.local
  74. when: openshift.master.embedded_dns
  75. - name: Create config parent directory if it doesn't exist
  76. file:
  77. path: "{{ openshift_master_config_dir }}"
  78. state: directory
  79. - name: Create the policy file if it does not already exist
  80. command: >
  81. {{ openshift.common.admin_binary }} create-bootstrap-policy-file
  82. --filename={{ openshift_master_policy }}
  83. args:
  84. creates: "{{ openshift_master_policy }}"
  85. notify:
  86. - restart master
  87. - restart master api
  88. - restart master controllers
  89. - name: Create the scheduler config
  90. template:
  91. dest: "{{ openshift_master_scheduler_conf }}"
  92. src: scheduler.json.j2
  93. backup: true
  94. notify:
  95. - restart master
  96. - restart master api
  97. - restart master controllers
  98. - name: Install httpd-tools if needed
  99. yum: pkg=httpd-tools state=present
  100. when: item.kind == 'HTPasswdPasswordIdentityProvider'
  101. with_items: openshift.master.identity_providers
  102. - name: Ensure htpasswd directory exists
  103. file:
  104. path: "{{ item.filename | dirname }}"
  105. state: directory
  106. when: item.kind == 'HTPasswdPasswordIdentityProvider'
  107. with_items: openshift.master.identity_providers
  108. - name: Create the htpasswd file if needed
  109. copy:
  110. dest: "{{ item.filename }}"
  111. content: ""
  112. mode: 0600
  113. force: no
  114. when: item.kind == 'HTPasswdPasswordIdentityProvider'
  115. with_items: openshift.master.identity_providers
  116. # workaround for missing systemd unit files for controllers/api
  117. - name: Create the api service file
  118. copy:
  119. src: atomic-openshift-master-api.service
  120. dest: /usr/lib/systemd/system/atomic-openshift-master-api.service
  121. force: no
  122. - name: Create the controllers service file
  123. copy:
  124. src: atomic-openshift-master-controllers.service
  125. dest: /usr/lib/systemd/system/atomic-openshift-master-controllers.service
  126. force: no
  127. - name: Create the api env file
  128. copy:
  129. src: atomic-openshift-master-api
  130. dest: /etc/sysconfig/atomic-openshift-master-api
  131. force: no
  132. - name: Create the controllers env file
  133. copy:
  134. src: atomic-openshift-master-controllers
  135. dest: /etc/sysconfig/atomic-openshift-master-controllers
  136. force: no
  137. - command: systemctl daemon-reload
  138. # end workaround for missing systemd unit files
  139. # TODO: add the validate parameter when there is a validation command to run
  140. - name: Create master config
  141. template:
  142. dest: "{{ openshift_master_config_file }}"
  143. src: master.yaml.v1.j2
  144. backup: true
  145. notify:
  146. - restart master
  147. - restart master api
  148. - restart master controllers
  149. - name: Configure master settings
  150. lineinfile:
  151. dest: /etc/sysconfig/{{ openshift.common.service_type }}-master
  152. regexp: "{{ item.regex }}"
  153. line: "{{ item.line }}"
  154. with_items:
  155. - regex: '^OPTIONS='
  156. line: "OPTIONS=--loglevel={{ openshift.master.debug_level }}"
  157. - regex: '^CONFIG_FILE='
  158. line: "CONFIG_FILE={{ openshift_master_config_file }}"
  159. notify:
  160. - restart master
  161. - name: Configure master api settings
  162. lineinfile:
  163. dest: /etc/sysconfig/{{ openshift.common.service_type }}-master-api
  164. regexp: "{{ item.regex }}"
  165. line: "{{ item.line }}"
  166. with_items:
  167. - regex: '^OPTIONS='
  168. line: "OPTIONS=--loglevel={{ openshift.master.debug_level }} --listen=https://0.0.0.0:8443 --master=https://{{ openshift.common.ip }}:8443"
  169. - regex: '^CONFIG_FILE='
  170. line: "CONFIG_FILE={{ openshift_master_config_file }}"
  171. notify:
  172. - restart master api
  173. - name: Configure master controller settings
  174. lineinfile:
  175. dest: /etc/sysconfig/{{ openshift.common.service_type }}-master-controllers
  176. regexp: "{{ item.regex }}"
  177. line: "{{ item.line }}"
  178. with_items:
  179. - regex: '^OPTIONS='
  180. line: "OPTIONS=--loglevel={{ openshift.master.debug_level }} --listen=https://0.0.0.0:8444"
  181. - regex: '^CONFIG_FILE='
  182. line: "CONFIG_FILE={{ openshift_master_config_file }}"
  183. notify:
  184. - restart master controllers
  185. - name: Start and enable master
  186. service: name={{ openshift.common.service_type }}-master enabled=yes state=started
  187. when: not openshift_master_ha | bool
  188. register: start_result
  189. - name: Start and enable master api
  190. service: name={{ openshift.common.service_type }}-master-api enabled=yes state=started
  191. when: openshift_master_ha | bool
  192. register: start_result
  193. # TODO: work to eliminate this workaround
  194. - name: pause a random interval to avoid startup errors for controller
  195. pause: seconds={{ 60 | random(step=5) }}
  196. when: openshift_master_ha | bool
  197. - name: Start and enable master controller
  198. service: name={{ openshift.common.service_type }}-master-controllers enabled=yes state=started
  199. when: openshift_master_ha | bool
  200. register: start_result
  201. - set_fact:
  202. master_service_status_changed = start_result | changed
  203. - name: Install cluster packages
  204. yum: pkg=pcs state=present
  205. when: openshift_master_ha | bool and not openshift.master.cluster_defer_ha | bool
  206. register: install_result
  207. - name: Start and enable cluster service
  208. service: name=pcsd enabled=yes state=started
  209. when: openshift_master_ha | bool and not openshift.master.cluster_defer_ha | bool
  210. - name: Set the cluster user password
  211. shell: echo {{ openshift_master_cluster_password | quote }} | passwd --stdin hacluster
  212. when: install_result | changed
  213. - name: Lookup default group for ansible_ssh_user
  214. command: "/usr/bin/id -g {{ ansible_ssh_user }}"
  215. register: _ansible_ssh_user_gid
  216. - name: Create the client config dir(s)
  217. file:
  218. path: "~{{ item }}/.kube"
  219. state: directory
  220. mode: 0700
  221. owner: "{{ item }}"
  222. group: "{{ 'root' if item == 'root' else _ansible_ssh_user_gid.stdout }}"
  223. with_items:
  224. - root
  225. - "{{ ansible_ssh_user }}"
  226. # TODO: Update this file if the contents of the source file are not present in
  227. # the dest file, will need to make sure to ignore things that could be added
  228. - name: Copy the admin client config(s)
  229. command: cp {{ openshift_master_config_dir }}/admin.kubeconfig ~{{ item }}/.kube/config
  230. args:
  231. creates: ~{{ item }}/.kube/config
  232. with_items:
  233. - root
  234. - "{{ ansible_ssh_user }}"
  235. - name: Update the permissions on the admin client config(s)
  236. file:
  237. path: "~{{ item }}/.kube/config"
  238. state: file
  239. mode: 0700
  240. owner: "{{ item }}"
  241. group: "{{ 'root' if item == 'root' else _ansible_ssh_user_gid.stdout }}"
  242. with_items:
  243. - root
  244. - "{{ ansible_ssh_user }}"