main.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. - debug: var=openshift_version
  5. # Authentication Variable Validation
  6. # TODO: validate the different identity provider kinds as well
  7. - fail:
  8. msg: >
  9. Invalid OAuth grant method: {{ openshift_master_oauth_grant_method }}
  10. when: openshift_master_oauth_grant_method is defined and openshift_master_oauth_grant_method not in openshift_master_valid_grant_methods
  11. # HA Variable Validation
  12. - fail:
  13. msg: "openshift_master_cluster_method must be set to either 'native' or 'pacemaker' for multi-master installations"
  14. 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"]))
  15. - fail:
  16. msg: "'native' high availability is not supported for the requested OpenShift version"
  17. when: openshift_master_ha | bool and openshift_master_cluster_method == "native" and not openshift.common.version_gte_3_1_or_1_1 | bool
  18. - fail:
  19. msg: "openshift_master_cluster_password must be set for multi-master installations"
  20. 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)
  21. - fail:
  22. msg: "Pacemaker based HA is not supported at this time when used with containerized installs"
  23. when: openshift_master_ha | bool and openshift_master_cluster_method == "pacemaker" and openshift.common.is_containerized | bool
  24. - name: Install Master package
  25. action: "{{ ansible_pkg_mgr }} name={{ openshift.common.service_type }}-master{{ openshift_version | default('') | oo_image_tag_to_rpm_version(include_dash=True) }} state=present"
  26. when: not openshift.common.is_containerized | bool
  27. - name: Pull master image
  28. command: >
  29. docker pull {{ openshift.master.master_image }}{{ ':v' + openshift_version if openshift_version is defined and openshift_version != '' else '' }}
  30. when: openshift.common.is_containerized | bool
  31. - name: Create openshift.common.data_dir
  32. file:
  33. path: "{{ openshift.common.data_dir }}"
  34. state: directory
  35. mode: 0755
  36. owner: root
  37. group: root
  38. when: openshift.common.is_containerized | bool
  39. - name: Reload systemd units
  40. command: systemctl daemon-reload
  41. when: openshift.common.is_containerized | bool and install_result | changed
  42. - name: Re-gather package dependent master facts
  43. openshift_facts:
  44. - name: Create config parent directory if it does not exist
  45. file:
  46. path: "{{ openshift_master_config_dir }}"
  47. state: directory
  48. - name: Create the policy file if it does not already exist
  49. command: >
  50. {{ openshift.common.admin_binary }} create-bootstrap-policy-file
  51. --filename={{ openshift_master_policy }}
  52. args:
  53. creates: "{{ openshift_master_policy }}"
  54. notify:
  55. - restart master
  56. - restart master api
  57. - restart master controllers
  58. - name: Create the scheduler config
  59. copy:
  60. content: "{{ scheduler_config | to_nice_json }}"
  61. dest: "{{ openshift_master_scheduler_conf }}"
  62. backup: true
  63. notify:
  64. - restart master
  65. - restart master api
  66. - restart master controllers
  67. - name: Install httpd-tools if needed
  68. action: "{{ ansible_pkg_mgr }} name=httpd-tools state=present"
  69. when: (item.kind == 'HTPasswdPasswordIdentityProvider') and
  70. not openshift.common.is_atomic | bool
  71. with_items: "{{ openshift.master.identity_providers }}"
  72. - name: Ensure htpasswd directory exists
  73. file:
  74. path: "{{ item.filename | dirname }}"
  75. state: directory
  76. when: item.kind == 'HTPasswdPasswordIdentityProvider'
  77. with_items: "{{ openshift.master.identity_providers }}"
  78. - name: Create the htpasswd file if needed
  79. template:
  80. dest: "{{ item.filename }}"
  81. src: htpasswd.j2
  82. backup: yes
  83. when: item.kind == 'HTPasswdPasswordIdentityProvider' and openshift.master.manage_htpasswd | bool
  84. with_items: "{{ openshift.master.identity_providers }}"
  85. - name: Ensure htpasswd file exists
  86. copy:
  87. dest: "{{ item.filename }}"
  88. force: no
  89. content: ""
  90. mode: 0600
  91. when: item.kind == 'HTPasswdPasswordIdentityProvider'
  92. with_items: "{{ openshift.master.identity_providers }}"
  93. - name: Create the ldap ca file if needed
  94. copy:
  95. dest: "{{ item.ca if 'ca' in item and '/' in item.ca else openshift_master_config_dir ~ '/' ~ item.ca | default('ldap_ca.crt') }}"
  96. content: "{{ openshift.master.ldap_ca }}"
  97. mode: 0600
  98. backup: yes
  99. when: openshift.master.ldap_ca is defined and item.kind == 'LDAPPasswordIdentityProvider'
  100. with_items: "{{ openshift.master.identity_providers }}"
  101. - name: Create the openid ca file if needed
  102. copy:
  103. dest: "{{ item.ca if 'ca' in item and '/' in item.ca else openshift_master_config_dir ~ '/' ~ item.ca | default('openid_ca.crt') }}"
  104. content: "{{ openshift.master.openid_ca }}"
  105. mode: 0600
  106. backup: yes
  107. when: openshift.master.openid_ca is defined and item.kind == 'OpenIDIdentityProvider' and item.ca | default('') != ''
  108. with_items: "{{ openshift.master.identity_providers }}"
  109. - name: Create the request header ca file if needed
  110. copy:
  111. dest: "{{ item.clientCA if 'clientCA' in item and '/' in item.clientCA else openshift_master_config_dir ~ '/' ~ item.clientCA | default('request_header_ca.crt') }}"
  112. content: "{{ openshift.master.request_header_ca }}"
  113. mode: 0600
  114. backup: yes
  115. when: openshift.master.request_header_ca is defined and item.kind == 'RequestHeaderIdentityProvider' and item.clientCA | default('') != ''
  116. with_items: "{{ openshift.master.identity_providers }}"
  117. - name: Install the systemd units
  118. include: systemd_units.yml
  119. - name: Create session secrets file
  120. template:
  121. dest: "{{ openshift.master.session_secrets_file }}"
  122. src: sessionSecretsFile.yaml.v1.j2
  123. owner: root
  124. group: root
  125. mode: 0600
  126. when: openshift.master.session_auth_secrets is defined and openshift.master.session_encryption_secrets is defined
  127. notify:
  128. - restart master
  129. - restart master api
  130. - set_fact:
  131. translated_identity_providers: "{{ openshift.master.identity_providers | translate_idps('v1', openshift.common.version, openshift.common.deployment_type) }}"
  132. # TODO: add the validate parameter when there is a validation command to run
  133. - name: Create master config
  134. template:
  135. dest: "{{ openshift_master_config_file }}"
  136. src: master.yaml.v1.j2
  137. backup: true
  138. owner: root
  139. group: root
  140. mode: 0600
  141. notify:
  142. - restart master
  143. - restart master api
  144. - restart master controllers
  145. - include: set_loopback_context.yml
  146. when: openshift.common.version_gte_3_2_or_1_2
  147. - name: Start and enable master
  148. service: name={{ openshift.common.service_type }}-master enabled=yes state=started
  149. when: not openshift_master_ha | bool
  150. register: start_result
  151. notify: Verify API Server
  152. - name: Check for non-HA master service presence
  153. command: systemctl show {{ openshift.common.service_type }}-master.service
  154. register: master_svc_show
  155. changed_when: false
  156. - name: Stop and disable non-HA master when running HA
  157. service: name={{ openshift.common.service_type }}-master enabled=no state=stopped
  158. when: openshift_master_ha | bool and 'LoadState=not-found' not in master_svc_show.stdout
  159. - set_fact:
  160. master_service_status_changed: "{{ start_result | changed }}"
  161. when: not openshift_master_ha | bool
  162. - name: Mask master service
  163. command: systemctl mask {{ openshift.common.service_type }}-master
  164. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native' and not openshift.common.is_containerized | bool
  165. - name: Start and enable master api
  166. service: name={{ openshift.common.service_type }}-master-api enabled=yes state=started
  167. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native'
  168. register: start_result
  169. - set_fact:
  170. master_api_service_status_changed: "{{ start_result | changed }}"
  171. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native'
  172. # A separate wait is required here for native HA since notifies will
  173. # be resolved after all tasks in the role.
  174. - name: Wait for API to become available
  175. # Using curl here since the uri module requires python-httplib2 and
  176. # wait_for port doesn't provide health information.
  177. command: >
  178. curl --silent --cacert {{ openshift.common.config_base }}/master/ca.crt
  179. {{ openshift.master.api_url }}/healthz/ready
  180. register: api_available_output
  181. until: api_available_output.stdout == 'ok'
  182. retries: 120
  183. delay: 1
  184. changed_when: false
  185. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native' and master_api_service_status_changed | bool
  186. - name: Start and enable master controller
  187. service: name={{ openshift.common.service_type }}-master-controllers enabled=yes state=started
  188. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native'
  189. register: start_result
  190. - set_fact:
  191. master_controllers_service_status_changed: "{{ start_result | changed }}"
  192. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native'
  193. - name: Install cluster packages
  194. action: "{{ ansible_pkg_mgr }} name=pcs state=present"
  195. when: openshift_master_ha | bool and openshift.master.cluster_method == 'pacemaker'
  196. and not openshift.common.is_containerized | bool
  197. register: install_result
  198. - name: Start and enable cluster service
  199. service: name=pcsd enabled=yes state=started
  200. when: openshift_master_ha | bool and openshift.master.cluster_method == 'pacemaker'
  201. and not openshift.common.is_containerized | bool
  202. - name: Set the cluster user password
  203. shell: echo {{ openshift_master_cluster_password | quote }} | passwd --stdin hacluster
  204. when: install_result | changed
  205. - name: Lookup default group for ansible_ssh_user
  206. command: "/usr/bin/id -g {{ ansible_ssh_user }}"
  207. changed_when: false
  208. register: _ansible_ssh_user_gid
  209. - set_fact:
  210. client_users: "{{ [ansible_ssh_user, 'root'] | unique }}"
  211. - name: Create the client config dir(s)
  212. file:
  213. path: "~{{ item }}/.kube"
  214. state: directory
  215. mode: 0700
  216. owner: "{{ item }}"
  217. group: "{{ 'root' if item == 'root' else _ansible_ssh_user_gid.stdout }}"
  218. with_items: "{{ client_users }}"
  219. # TODO: Update this file if the contents of the source file are not present in
  220. # the dest file, will need to make sure to ignore things that could be added
  221. - name: Copy the admin client config(s)
  222. command: cp {{ openshift_master_config_dir }}/admin.kubeconfig ~{{ item }}/.kube/config
  223. args:
  224. creates: ~{{ item }}/.kube/config
  225. with_items: "{{ client_users }}"
  226. - name: Update the permissions on the admin client config(s)
  227. file:
  228. path: "~{{ item }}/.kube/config"
  229. state: file
  230. mode: 0700
  231. owner: "{{ item }}"
  232. group: "{{ 'root' if item == 'root' else _ansible_ssh_user_gid.stdout }}"
  233. with_items: "{{ client_users }}"