main.yml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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. etcd_hosts: "{{ openshift_master_etcd_hosts | default(None)}}"
  41. etcd_port: "{{ openshift_master_etcd_port | default(None) }}"
  42. etcd_use_ssl: "{{ openshift_master_etcd_use_ssl | default(None) }}"
  43. etcd_urls: "{{ openshift_master_etcd_urls | default(None) }}"
  44. embedded_etcd: "{{ openshift_master_embedded_etcd | default(None) }}"
  45. embedded_kube: "{{ openshift_master_embedded_kube | default(None) }}"
  46. embedded_dns: "{{ openshift_master_embedded_dns | default(None) }}"
  47. dns_port: "{{ openshift_master_dns_port | default(None) }}"
  48. bind_addr: "{{ openshift_master_bind_addr | default(None) }}"
  49. portal_net: "{{ openshift_master_portal_net | default(None) }}"
  50. session_max_seconds: "{{ openshift_master_session_max_seconds | default(None) }}"
  51. session_name: "{{ openshift_master_session_name | default(None) }}"
  52. session_auth_secrets: "{{ openshift_master_session_auth_secrets | default(None) }}"
  53. session_encryption_secrets: "{{ openshift_master_session_encryption_secrets | default(None) }}"
  54. session_secrets_file: "{{ openshift_master_session_secrets_file | default(None) }}"
  55. access_token_max_seconds: "{{ openshift_master_access_token_max_seconds | default(None) }}"
  56. auth_token_max_seconds: "{{ openshift_master_auth_token_max_seconds | default(None) }}"
  57. identity_providers: "{{ openshift_master_identity_providers | default(None) }}"
  58. registry_url: "{{ oreg_url | default(None) }}"
  59. oauth_grant_method: "{{ openshift_master_oauth_grant_method | default(None) }}"
  60. sdn_cluster_network_cidr: "{{ osm_cluster_network_cidr | default(None) }}"
  61. sdn_host_subnet_length: "{{ osm_host_subnet_length | default(None) }}"
  62. default_subdomain: "{{ osm_default_subdomain | default(None) }}"
  63. custom_cors_origins: "{{ osm_custom_cors_origins | default(None) }}"
  64. default_node_selector: "{{ osm_default_node_selector | default(None) }}"
  65. project_request_message: "{{ osm_project_request_message | default(None) }}"
  66. project_request_template: "{{ osm_project_request_template | default(None) }}"
  67. mcs_allocator_range: "{{ osm_mcs_allocator_range | default(None) }}"
  68. mcs_labels_per_project: "{{ osm_mcs_labels_per_project | default(None) }}"
  69. uid_allocator_range: "{{ osm_uid_allocator_range | default(None) }}"
  70. router_selector: "{{ openshift_router_selector | default(None) }}"
  71. registry_selector: "{{ openshift_registry_selector | default(None) }}"
  72. api_server_args: "{{ osm_api_server_args | default(None) }}"
  73. controller_args: "{{ osm_controller_args | default(None) }}"
  74. infra_nodes: "{{ num_infra | default(None) }}"
  75. disabled_features: "{{ osm_disabled_features | default(None) }}"
  76. master_count: "{{ openshift_master_count | default(None) }}"
  77. controller_lease_ttl: "{{ osm_controller_lease_ttl | default(None) }}"
  78. master_image: "{{ osm_image | default(None) }}"
  79. - name: Install Master package
  80. action: "{{ ansible_pkg_mgr }} name={{ openshift.common.service_type }}-master{{ openshift_version }} state=present"
  81. when: not openshift.common.is_containerized | bool
  82. - name: Get docker images
  83. command: docker images
  84. changed_when: false
  85. when: openshift.common.is_containerized | bool
  86. register: docker_images
  87. - name: Pull master image
  88. command: >
  89. docker pull {{ openshift.master.master_image }}
  90. when: openshift.common.is_containerized | bool and openshift.master.master_image not in docker_images.stdout
  91. - name: Wait for master image
  92. command: >
  93. docker images
  94. register: docker_images
  95. until: openshift.master.master_image in docker_images.stdout
  96. retries: 30
  97. delay: 10
  98. changed_when: false
  99. when: openshift.common.is_containerized | bool
  100. - name: Install Master docker service file
  101. template:
  102. dest: "/etc/systemd/system/{{ openshift.common.service_type }}-master.service"
  103. src: master.docker.service.j2
  104. register: install_result
  105. when: openshift.common.is_containerized | bool and not openshift_master_ha | bool
  106. - name: Create openshift.common.data_dir
  107. file:
  108. path: "{{ openshift.common.data_dir }}"
  109. state: directory
  110. mode: 0755
  111. owner: root
  112. group: root
  113. when: openshift.common.is_containerized | bool
  114. - name: Reload systemd units
  115. command: systemctl daemon-reload
  116. when: openshift.common.is_containerized | bool and install_result | changed
  117. - name: Re-gather package dependent master facts
  118. openshift_facts:
  119. - name: Create config parent directory if it does not exist
  120. file:
  121. path: "{{ openshift_master_config_dir }}"
  122. state: directory
  123. - name: Create the policy file if it does not already exist
  124. command: >
  125. {{ openshift.common.admin_binary }} create-bootstrap-policy-file
  126. --filename={{ openshift_master_policy }}
  127. args:
  128. creates: "{{ openshift_master_policy }}"
  129. notify:
  130. - restart master
  131. - restart master api
  132. - restart master controllers
  133. - name: Create the scheduler config
  134. template:
  135. dest: "{{ openshift_master_scheduler_conf }}"
  136. src: scheduler.json.j2
  137. backup: true
  138. notify:
  139. - restart master
  140. - restart master api
  141. - restart master controllers
  142. - name: Install httpd-tools if needed
  143. action: "{{ ansible_pkg_mgr }} name=httpd-tools state=present"
  144. when: (item.kind == 'HTPasswdPasswordIdentityProvider') and
  145. not openshift.common.is_atomic | bool
  146. with_items: openshift.master.identity_providers
  147. - name: Ensure htpasswd directory exists
  148. file:
  149. path: "{{ item.filename | dirname }}"
  150. state: directory
  151. when: item.kind == 'HTPasswdPasswordIdentityProvider'
  152. with_items: openshift.master.identity_providers
  153. - name: Create the htpasswd file if needed
  154. copy:
  155. dest: "{{ item.filename }}"
  156. content: ""
  157. mode: 0600
  158. force: no
  159. when: item.kind == 'HTPasswdPasswordIdentityProvider'
  160. with_items: openshift.master.identity_providers
  161. - name: Init HA Service Info
  162. set_fact:
  163. ha_suffix: ""
  164. ha_svcdir: "/usr/lib/systemd/system"
  165. - name: Set HA Service Info for containerized installs
  166. set_fact:
  167. ha_suffix: ".docker"
  168. ha_svcdir: "/etc/systemd/system"
  169. when: openshift.common.is_containerized | bool
  170. # workaround for missing systemd unit files for controllers/api
  171. - name: Create the api service file
  172. template:
  173. src: atomic-openshift-master-api{{ ha_suffix }}.service.j2
  174. dest: "{{ ha_svcdir }}/{{ openshift.common.service_type }}-master-api.service"
  175. when: openshift_master_ha | bool and openshift_master_cluster_method == "native"
  176. - name: Create the controllers service file
  177. template:
  178. src: atomic-openshift-master-controllers{{ ha_suffix }}.service.j2
  179. dest: "{{ ha_svcdir }}/{{ openshift.common.service_type }}-master-controllers.service"
  180. when: openshift_master_ha | bool and openshift_master_cluster_method == "native"
  181. - name: Create the api env file
  182. template:
  183. src: atomic-openshift-master-api.j2
  184. dest: /etc/sysconfig/{{ openshift.common.service_type }}-master-api
  185. force: no
  186. when: openshift_master_ha | bool and openshift_master_cluster_method == "native"
  187. - name: Create the controllers env file
  188. template:
  189. src: atomic-openshift-master-controllers.j2
  190. dest: /etc/sysconfig/{{ openshift.common.service_type }}-master-controllers
  191. force: no
  192. when: openshift_master_ha | bool and openshift_master_cluster_method == "native"
  193. - command: systemctl daemon-reload
  194. when: openshift_master_ha | bool and openshift_master_cluster_method == "native"
  195. # end workaround for missing systemd unit files
  196. - name: Create session secrets file
  197. template:
  198. dest: "{{ openshift.master.session_secrets_file }}"
  199. src: sessionSecretsFile.yaml.v1.j2
  200. force: no
  201. notify:
  202. - restart master
  203. - restart master api
  204. - set_fact:
  205. translated_identity_providers: "{{ openshift.master.identity_providers | translate_idps('v1') }}"
  206. # TODO: add the validate parameter when there is a validation command to run
  207. - name: Create master config
  208. template:
  209. dest: "{{ openshift_master_config_file }}"
  210. src: master.yaml.v1.j2
  211. backup: true
  212. notify:
  213. - restart master
  214. - restart master api
  215. - restart master controllers
  216. - name: Configure master settings
  217. lineinfile:
  218. dest: /etc/sysconfig/{{ openshift.common.service_type }}-master
  219. regexp: "{{ item.regex }}"
  220. line: "{{ item.line }}"
  221. create: yes
  222. with_items:
  223. - regex: '^OPTIONS='
  224. line: "OPTIONS=--loglevel={{ openshift.master.debug_level }}"
  225. - regex: '^CONFIG_FILE='
  226. line: "CONFIG_FILE={{ openshift_master_config_file }}"
  227. notify:
  228. - restart master
  229. - name: Configure master api settings
  230. lineinfile:
  231. dest: /etc/sysconfig/{{ openshift.common.service_type }}-master-api
  232. regexp: "{{ item.regex }}"
  233. line: "{{ item.line }}"
  234. with_items:
  235. - regex: '^OPTIONS='
  236. line: "OPTIONS=--loglevel={{ openshift.master.debug_level }} --listen=https://0.0.0.0:8443 --master=https://{{ openshift.common.ip }}:8443"
  237. - regex: '^CONFIG_FILE='
  238. line: "CONFIG_FILE={{ openshift_master_config_file }}"
  239. when: openshift_master_ha | bool and openshift_master_cluster_method == "native"
  240. notify:
  241. - restart master api
  242. - name: Configure master controller settings
  243. lineinfile:
  244. dest: /etc/sysconfig/{{ openshift.common.service_type }}-master-controllers
  245. regexp: "{{ item.regex }}"
  246. line: "{{ item.line }}"
  247. with_items:
  248. - regex: '^OPTIONS='
  249. line: "OPTIONS=--loglevel={{ openshift.master.debug_level }} --listen=https://0.0.0.0:8444"
  250. - regex: '^CONFIG_FILE='
  251. line: "CONFIG_FILE={{ openshift_master_config_file }}"
  252. when: openshift_master_ha | bool and openshift_master_cluster_method == "native"
  253. notify:
  254. - restart master controllers
  255. - name: Start and enable master
  256. service: name={{ openshift.common.service_type }}-master enabled=yes state=started
  257. when: not openshift_master_ha | bool
  258. register: start_result
  259. - name: Stop and disable non HA master when running HA
  260. service: name={{ openshift.common.service_type }}-master enabled=no state=stopped
  261. when: openshift_master_ha | bool
  262. - set_fact:
  263. master_service_status_changed: start_result | changed
  264. when: not openshift_master_ha | bool
  265. - name: Start and enable master api
  266. service: name={{ openshift.common.service_type }}-master-api enabled=yes state=started
  267. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native'
  268. register: start_result
  269. - set_fact:
  270. master_api_service_status_changed: start_result | changed
  271. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native'
  272. - name: Start and enable master controller
  273. service: name={{ openshift.common.service_type }}-master-controllers enabled=yes state=started
  274. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native'
  275. register: start_result
  276. - set_fact:
  277. master_controllers_service_status_changed: start_result | changed
  278. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native'
  279. - name: Install cluster packages
  280. action: "{{ ansible_pkg_mgr }} name=pcs state=present"
  281. when: openshift_master_ha | bool and openshift.master.cluster_method == 'pacemaker'
  282. and not openshift.common.is_containerized | bool
  283. register: install_result
  284. - name: Start and enable cluster service
  285. service: name=pcsd enabled=yes state=started
  286. when: openshift_master_ha | bool and openshift.master.cluster_method == 'pacemaker'
  287. and not openshift.common.is_containerized | bool
  288. - name: Set the cluster user password
  289. shell: echo {{ openshift_master_cluster_password | quote }} | passwd --stdin hacluster
  290. when: install_result | changed
  291. - name: Lookup default group for ansible_ssh_user
  292. command: "/usr/bin/id -g {{ ansible_ssh_user }}"
  293. changed_when: false
  294. register: _ansible_ssh_user_gid
  295. - name: Create the client config dir(s)
  296. file:
  297. path: "~{{ item }}/.kube"
  298. state: directory
  299. mode: 0700
  300. owner: "{{ item }}"
  301. group: "{{ 'root' if item == 'root' else _ansible_ssh_user_gid.stdout }}"
  302. with_items:
  303. - root
  304. - "{{ ansible_ssh_user }}"
  305. # TODO: Update this file if the contents of the source file are not present in
  306. # the dest file, will need to make sure to ignore things that could be added
  307. - name: Copy the admin client config(s)
  308. command: cp {{ openshift_master_config_dir }}/admin.kubeconfig ~{{ item }}/.kube/config
  309. args:
  310. creates: ~{{ item }}/.kube/config
  311. with_items:
  312. - root
  313. - "{{ ansible_ssh_user }}"
  314. - name: Update the permissions on the admin client config(s)
  315. file:
  316. path: "~{{ item }}/.kube/config"
  317. state: file
  318. mode: 0700
  319. owner: "{{ item }}"
  320. group: "{{ 'root' if item == 'root' else _ansible_ssh_user_gid.stdout }}"
  321. with_items:
  322. - root
  323. - "{{ ansible_ssh_user }}"