main.yml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. ---
  2. # TODO: add ability to configure certificates given either a local file to
  3. # point to or certificate contents, set in default cert locations.
  4. # Authentication Variable Validation
  5. # TODO: validate the different identity provider kinds as well
  6. - fail:
  7. msg: >
  8. Invalid OAuth grant method: {{ openshift_master_oauth_grant_method }}
  9. when: openshift_master_oauth_grant_method is defined and openshift_master_oauth_grant_method not in openshift_master_valid_grant_methods
  10. # HA Variable Validation
  11. - fail:
  12. msg: "openshift_master_cluster_method must be set to either 'native' or 'pacemaker' for multi-master installations"
  13. 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 not in ["native", "pacemaker"]))
  14. - fail:
  15. msg: "'native' high availability is not supported for the requested OpenShift version"
  16. when: openshift_master_ha | bool and openshift_master_cluster_method == "native" and not openshift.common.version_greater_than_3_1_or_1_1 | bool
  17. - fail:
  18. msg: "openshift_master_cluster_password must be set for multi-master installations"
  19. when: openshift_master_ha | bool and openshift_master_cluster_method == "pacemaker" and (openshift_master_cluster_password is not defined or not openshift_master_cluster_password)
  20. - fail:
  21. msg: "Pacemaker based HA is not supported at this time when used with containerized installs"
  22. when: openshift_master_ha | bool and openshift_master_cluster_method == "pacemaker" and openshift.common.is_containerized | bool
  23. - name: Set master facts
  24. openshift_facts:
  25. role: master
  26. local_facts:
  27. cluster_method: "{{ openshift_master_cluster_method | default(None) }}"
  28. cluster_hostname: "{{ openshift_master_cluster_hostname | default(None) }}"
  29. cluster_public_hostname: "{{ openshift_master_cluster_public_hostname | default(None) }}"
  30. debug_level: "{{ openshift_master_debug_level | default(openshift.common.debug_level) }}"
  31. api_port: "{{ openshift_master_api_port | default(None) }}"
  32. api_url: "{{ openshift_master_api_url | default(None) }}"
  33. api_use_ssl: "{{ openshift_master_api_use_ssl | default(None) }}"
  34. public_api_url: "{{ openshift_master_public_api_url | default(None) }}"
  35. console_path: "{{ openshift_master_console_path | default(None) }}"
  36. console_port: "{{ openshift_master_console_port | default(None) }}"
  37. console_url: "{{ openshift_master_console_url | default(None) }}"
  38. console_use_ssl: "{{ openshift_master_console_use_ssl | default(None) }}"
  39. public_console_url: "{{ openshift_master_public_console_url | default(None) }}"
  40. logging_public_url: "{{ openshift_master_logging_public_url | default(None) }}"
  41. metrics_public_url: "{{ openshift_master_metrics_public_url | default(None) }}"
  42. etcd_hosts: "{{ openshift_master_etcd_hosts | default(None)}}"
  43. etcd_port: "{{ openshift_master_etcd_port | default(None) }}"
  44. etcd_use_ssl: "{{ openshift_master_etcd_use_ssl | default(None) }}"
  45. etcd_urls: "{{ openshift_master_etcd_urls | default(None) }}"
  46. embedded_etcd: "{{ openshift_master_embedded_etcd | default(None) }}"
  47. embedded_kube: "{{ openshift_master_embedded_kube | default(None) }}"
  48. embedded_dns: "{{ openshift_master_embedded_dns | default(None) }}"
  49. dns_port: "{{ openshift_master_dns_port | default(None) }}"
  50. bind_addr: "{{ openshift_master_bind_addr | default(None) }}"
  51. pod_eviction_timeout: "{{ openshift_master_pod_eviction_timeout | default(None) }}"
  52. portal_net: "{{ openshift_master_portal_net | default(None) }}"
  53. session_max_seconds: "{{ openshift_master_session_max_seconds | default(None) }}"
  54. session_name: "{{ openshift_master_session_name | default(None) }}"
  55. session_secrets_file: "{{ openshift_master_session_secrets_file | default(None) }}"
  56. session_auth_secrets: "{{ openshift_master_session_auth_secrets | default(None) }}"
  57. session_encryption_secrets: "{{ openshift_master_session_encryption_secrets | default(None) }}"
  58. access_token_max_seconds: "{{ openshift_master_access_token_max_seconds | default(None) }}"
  59. auth_token_max_seconds: "{{ openshift_master_auth_token_max_seconds | default(None) }}"
  60. identity_providers: "{{ openshift_master_identity_providers | default(None) }}"
  61. registry_url: "{{ oreg_url | default(None) }}"
  62. oauth_grant_method: "{{ openshift_master_oauth_grant_method | default(None) }}"
  63. sdn_cluster_network_cidr: "{{ osm_cluster_network_cidr | default(None) }}"
  64. sdn_host_subnet_length: "{{ osm_host_subnet_length | default(None) }}"
  65. default_subdomain: "{{ osm_default_subdomain | default(None) }}"
  66. custom_cors_origins: "{{ osm_custom_cors_origins | default(None) }}"
  67. default_node_selector: "{{ osm_default_node_selector | default(None) }}"
  68. project_request_message: "{{ osm_project_request_message | default(None) }}"
  69. project_request_template: "{{ osm_project_request_template | default(None) }}"
  70. mcs_allocator_range: "{{ osm_mcs_allocator_range | default(None) }}"
  71. mcs_labels_per_project: "{{ osm_mcs_labels_per_project | default(None) }}"
  72. uid_allocator_range: "{{ osm_uid_allocator_range | default(None) }}"
  73. router_selector: "{{ openshift_router_selector | default(None) }}"
  74. registry_selector: "{{ openshift_registry_selector | default(None) }}"
  75. api_server_args: "{{ osm_api_server_args | default(None) }}"
  76. controller_args: "{{ osm_controller_args | default(None) }}"
  77. infra_nodes: "{{ num_infra | default(None) }}"
  78. disabled_features: "{{ osm_disabled_features | default(None) }}"
  79. master_count: "{{ openshift_master_count | default(None) }}"
  80. controller_lease_ttl: "{{ osm_controller_lease_ttl | default(None) }}"
  81. master_image: "{{ osm_image | default(None) }}"
  82. - name: Install Master package
  83. action: "{{ ansible_pkg_mgr }} name={{ openshift.common.service_type }}-master{{ openshift_version }} state=present"
  84. when: not openshift.common.is_containerized | bool
  85. - name: Pull master image
  86. command: >
  87. docker pull {{ openshift.master.master_image }}
  88. when: openshift.common.is_containerized | bool
  89. - name: Install Master docker service file
  90. template:
  91. dest: "/etc/systemd/system/{{ openshift.common.service_type }}-master.service"
  92. src: docker/master.docker.service.j2
  93. register: install_result
  94. when: openshift.common.is_containerized | bool and not openshift_master_ha | bool
  95. - name: Create openshift.common.data_dir
  96. file:
  97. path: "{{ openshift.common.data_dir }}"
  98. state: directory
  99. mode: 0755
  100. owner: root
  101. group: root
  102. when: openshift.common.is_containerized | bool
  103. - name: Reload systemd units
  104. command: systemctl daemon-reload
  105. when: openshift.common.is_containerized | bool and install_result | changed
  106. - name: Re-gather package dependent master facts
  107. openshift_facts:
  108. - name: Create config parent directory if it does not exist
  109. file:
  110. path: "{{ openshift_master_config_dir }}"
  111. state: directory
  112. - name: Create the policy file if it does not already exist
  113. command: >
  114. {{ openshift.common.admin_binary }} create-bootstrap-policy-file
  115. --filename={{ openshift_master_policy }}
  116. args:
  117. creates: "{{ openshift_master_policy }}"
  118. notify:
  119. - restart master
  120. - restart master api
  121. - restart master controllers
  122. - name: Create the scheduler config
  123. template:
  124. dest: "{{ openshift_master_scheduler_conf }}"
  125. src: scheduler.json.j2
  126. backup: true
  127. notify:
  128. - restart master
  129. - restart master api
  130. - restart master controllers
  131. - name: Install httpd-tools if needed
  132. action: "{{ ansible_pkg_mgr }} name=httpd-tools state=present"
  133. when: (item.kind == 'HTPasswdPasswordIdentityProvider') and
  134. not openshift.common.is_atomic | bool
  135. with_items: openshift.master.identity_providers
  136. - name: Ensure htpasswd directory exists
  137. file:
  138. path: "{{ item.filename | dirname }}"
  139. state: directory
  140. when: item.kind == 'HTPasswdPasswordIdentityProvider'
  141. with_items: openshift.master.identity_providers
  142. - name: Create the htpasswd file if needed
  143. copy:
  144. dest: "{{ item.filename }}"
  145. content: ""
  146. mode: 0600
  147. force: no
  148. when: item.kind == 'HTPasswdPasswordIdentityProvider'
  149. with_items: openshift.master.identity_providers
  150. - name: Init HA Service Info
  151. set_fact:
  152. ha_suffix: ""
  153. ha_svcdir: "/usr/lib/systemd/system"
  154. - name: Set HA Service Info for containerized installs
  155. set_fact:
  156. ha_suffix: ".docker"
  157. ha_svcdir: "/etc/systemd/system"
  158. when: openshift.common.is_containerized | bool
  159. # workaround for missing systemd unit files for controllers/api
  160. - name: Create the systemd unit files
  161. template:
  162. src: "{{ ha_svc_template_path }}/atomic-openshift-master-{{ item }}.service.j2"
  163. dest: "{{ ha_svcdir }}/{{ openshift.common.service_type }}-master-{{ item }}.service"
  164. when: openshift_master_ha | bool and openshift_master_cluster_method == "native"
  165. with_items:
  166. - api
  167. - controllers
  168. register: create_unit_files
  169. - command: systemctl daemon-reload
  170. when: create_unit_files | changed
  171. # end workaround for missing systemd unit files
  172. - name: Create the master api service env file
  173. template:
  174. src: "{{ ha_svc_template_path }}/atomic-openshift-master-api.j2"
  175. dest: /etc/sysconfig/{{ openshift.common.service_type }}-master-api
  176. when: openshift_master_ha | bool and openshift_master_cluster_method == "native"
  177. notify:
  178. - restart master api
  179. - name: Create the master controllers service env file
  180. template:
  181. src: "{{ ha_svc_template_path }}/atomic-openshift-master-controllers.j2"
  182. dest: /etc/sysconfig/{{ openshift.common.service_type }}-master-controllers
  183. when: openshift_master_ha | bool and openshift_master_cluster_method == "native"
  184. notify:
  185. - restart master controllers
  186. - name: Create the master service env file
  187. template:
  188. src: "atomic-openshift-master.j2"
  189. dest: /etc/sysconfig/{{ openshift.common.service_type }}-master
  190. notify:
  191. - restart master
  192. - name: Create session secrets file
  193. template:
  194. dest: "{{ openshift.master.session_secrets_file }}"
  195. src: sessionSecretsFile.yaml.v1.j2
  196. when: openshift.master.session_auth_secrets is defined and openshift.master.session_encryption_secrets is defined
  197. notify:
  198. - restart master
  199. - restart master api
  200. - set_fact:
  201. translated_identity_providers: "{{ openshift.master.identity_providers | translate_idps('v1') }}"
  202. # TODO: add the validate parameter when there is a validation command to run
  203. - name: Create master config
  204. template:
  205. dest: "{{ openshift_master_config_file }}"
  206. src: master.yaml.v1.j2
  207. backup: true
  208. notify:
  209. - restart master
  210. - restart master api
  211. - restart master controllers
  212. - name: Test local loopback context
  213. command: >
  214. {{ openshift.common.client_binary }} config view
  215. --config={{ openshift_master_loopback_config }}
  216. changed_when: false
  217. register: loopback_config
  218. - command: >
  219. {{ openshift.common.client_binary }} config set-cluster
  220. --certificate-authority={{ openshift_master_config_dir }}/ca.crt
  221. --embed-certs=true --server={{ openshift.master.loopback_api_url }}
  222. {{ openshift.master.loopback_cluster_name }}
  223. --config={{ openshift_master_loopback_config }}
  224. when: loopback_context_string not in loopback_config.stdout
  225. register: set_loopback_cluster
  226. - command: >
  227. {{ openshift.common.client_binary }} config set-context
  228. --cluster={{ openshift.master.loopback_cluster_name }}
  229. --namespace=default --user={{ openshift.master.loopback_user }}
  230. {{ openshift.master.loopback_context_name }}
  231. --config={{ openshift_master_loopback_config }}
  232. when: set_loopback_cluster | changed
  233. register: set_loopback_context
  234. - command: >
  235. {{ openshift.common.client_binary }} config use-context {{ openshift.master.loopback_context_name }}
  236. --config={{ openshift_master_loopback_config }}
  237. when: set_loopback_context | changed
  238. register: set_current_context
  239. - name: Start and enable master
  240. service: name={{ openshift.common.service_type }}-master enabled=yes state=started
  241. when: not openshift_master_ha | bool
  242. register: start_result
  243. notify: Verify API Server
  244. - name: Stop and disable non HA master when running HA
  245. service: name={{ openshift.common.service_type }}-master enabled=no state=stopped
  246. when: openshift_master_ha | bool
  247. - set_fact:
  248. master_service_status_changed: "{{ start_result | changed }}"
  249. when: not openshift_master_ha | bool
  250. - name: Start and enable master api
  251. service: name={{ openshift.common.service_type }}-master-api enabled=yes state=started
  252. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native'
  253. register: start_result
  254. - set_fact:
  255. master_api_service_status_changed: "{{ start_result | changed }}"
  256. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native'
  257. # A separate wait is required here for native HA since notifies will
  258. # be resolved after all tasks in the role.
  259. - name: Wait for API to become available
  260. # Using curl here since the uri module requires python-httplib2 and
  261. # wait_for port doesn't provide health information.
  262. command: >
  263. curl -k --head --silent {{ openshift.master.api_url }}
  264. register: api_available_output
  265. until: api_available_output.stdout.find("200 OK") != -1
  266. retries: 120
  267. delay: 1
  268. changed_when: false
  269. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native' and master_api_service_status_changed | bool
  270. - name: Start and enable master controller
  271. service: name={{ openshift.common.service_type }}-master-controllers enabled=yes state=started
  272. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native'
  273. register: start_result
  274. - set_fact:
  275. master_controllers_service_status_changed: "{{ start_result | changed }}"
  276. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native'
  277. - name: Install cluster packages
  278. action: "{{ ansible_pkg_mgr }} name=pcs state=present"
  279. when: openshift_master_ha | bool and openshift.master.cluster_method == 'pacemaker'
  280. and not openshift.common.is_containerized | bool
  281. register: install_result
  282. - name: Start and enable cluster service
  283. service: name=pcsd enabled=yes state=started
  284. when: openshift_master_ha | bool and openshift.master.cluster_method == 'pacemaker'
  285. and not openshift.common.is_containerized | bool
  286. - name: Set the cluster user password
  287. shell: echo {{ openshift_master_cluster_password | quote }} | passwd --stdin hacluster
  288. when: install_result | changed
  289. - name: Lookup default group for ansible_ssh_user
  290. command: "/usr/bin/id -g {{ ansible_ssh_user }}"
  291. changed_when: false
  292. register: _ansible_ssh_user_gid
  293. - name: Create the client config dir(s)
  294. file:
  295. path: "~{{ item }}/.kube"
  296. state: directory
  297. mode: 0700
  298. owner: "{{ item }}"
  299. group: "{{ 'root' if item == 'root' else _ansible_ssh_user_gid.stdout }}"
  300. with_items:
  301. - root
  302. - "{{ ansible_ssh_user }}"
  303. # TODO: Update this file if the contents of the source file are not present in
  304. # the dest file, will need to make sure to ignore things that could be added
  305. - name: Copy the admin client config(s)
  306. command: cp {{ openshift_master_config_dir }}/admin.kubeconfig ~{{ item }}/.kube/config
  307. args:
  308. creates: ~{{ item }}/.kube/config
  309. with_items:
  310. - root
  311. - "{{ ansible_ssh_user }}"
  312. - name: Update the permissions on the admin client config(s)
  313. file:
  314. path: "~{{ item }}/.kube/config"
  315. state: file
  316. mode: 0700
  317. owner: "{{ item }}"
  318. group: "{{ 'root' if item == 'root' else _ansible_ssh_user_gid.stdout }}"
  319. with_items:
  320. - root
  321. - "{{ ansible_ssh_user }}"