main.yml 10 KB

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