main.yml 15 KB

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