main.yml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 }}
  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. mode: 0600
  83. backup: yes
  84. when: item.kind == 'HTPasswdPasswordIdentityProvider'
  85. with_items: "{{ openshift.master.identity_providers }}"
  86. - name: Create the ldap ca file if needed
  87. copy:
  88. dest: "{{ item.ca if 'ca' in item and '/' in item.ca else openshift_master_config_dir ~ '/' ~ item.ca | default('ldap_ca.crt') }}"
  89. content: "{{ openshift.master.ldap_ca }}"
  90. mode: 0600
  91. backup: yes
  92. when: openshift.master.ldap_ca is defined and item.kind == 'LDAPPasswordIdentityProvider'
  93. with_items: "{{ openshift.master.identity_providers }}"
  94. - name: Create the openid ca file if needed
  95. copy:
  96. dest: "{{ item.ca if 'ca' in item and '/' in item.ca else openshift_master_config_dir ~ '/' ~ item.ca | default('openid_ca.crt') }}"
  97. content: "{{ openshift.master.openid_ca }}"
  98. mode: 0600
  99. backup: yes
  100. when: openshift.master.openid_ca is defined and item.kind == 'OpenIDIdentityProvider' and item.ca | default('') != ''
  101. with_items: "{{ openshift.master.identity_providers }}"
  102. - name: Create the request header ca file if needed
  103. copy:
  104. dest: "{{ item.clientCA if 'clientCA' in item and '/' in item.clientCA else openshift_master_config_dir ~ '/' ~ item.clientCA | default('request_header_ca.crt') }}"
  105. content: "{{ openshift.master.request_header_ca }}"
  106. mode: 0600
  107. backup: yes
  108. when: openshift.master.request_header_ca is defined and item.kind == 'RequestHeaderIdentityProvider' and item.clientCA | default('') != ''
  109. with_items: "{{ openshift.master.identity_providers }}"
  110. - name: Install the systemd units
  111. include: systemd_units.yml
  112. - name: Create session secrets file
  113. template:
  114. dest: "{{ openshift.master.session_secrets_file }}"
  115. src: sessionSecretsFile.yaml.v1.j2
  116. owner: root
  117. group: root
  118. mode: 0600
  119. when: openshift.master.session_auth_secrets is defined and openshift.master.session_encryption_secrets is defined
  120. notify:
  121. - restart master
  122. - restart master api
  123. - set_fact:
  124. translated_identity_providers: "{{ openshift.master.identity_providers | translate_idps('v1', openshift.common.version, openshift.common.deployment_type) }}"
  125. # TODO: add the validate parameter when there is a validation command to run
  126. - name: Create master config
  127. template:
  128. dest: "{{ openshift_master_config_file }}"
  129. src: master.yaml.v1.j2
  130. backup: true
  131. owner: root
  132. group: root
  133. mode: 0600
  134. notify:
  135. - restart master
  136. - restart master api
  137. - restart master controllers
  138. - include: set_loopback_context.yml
  139. when: openshift.common.version_gte_3_2_or_1_2
  140. - name: Start and enable master
  141. service: name={{ openshift.common.service_type }}-master enabled=yes state=started
  142. when: not openshift_master_ha | bool
  143. register: start_result
  144. notify: Verify API Server
  145. - name: Check for non-HA master service presence
  146. command: systemctl show {{ openshift.common.service_type }}-master.service
  147. register: master_svc_show
  148. changed_when: false
  149. - name: Stop and disable non-HA master when running HA
  150. service: name={{ openshift.common.service_type }}-master enabled=no state=stopped
  151. when: openshift_master_ha | bool and 'LoadState=not-found' not in master_svc_show.stdout
  152. - set_fact:
  153. master_service_status_changed: "{{ start_result | changed }}"
  154. when: not openshift_master_ha | bool
  155. - name: Mask master service
  156. command: systemctl mask {{ openshift.common.service_type }}-master
  157. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native' and not openshift.common.is_containerized | bool
  158. - name: Start and enable master api
  159. service: name={{ openshift.common.service_type }}-master-api enabled=yes state=started
  160. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native'
  161. register: start_result
  162. - set_fact:
  163. master_api_service_status_changed: "{{ start_result | changed }}"
  164. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native'
  165. # A separate wait is required here for native HA since notifies will
  166. # be resolved after all tasks in the role.
  167. - name: Wait for API to become available
  168. # Using curl here since the uri module requires python-httplib2 and
  169. # wait_for port doesn't provide health information.
  170. command: >
  171. curl --silent --cacert {{ openshift.common.config_base }}/master/ca.crt
  172. {{ openshift.master.api_url }}/healthz/ready
  173. register: api_available_output
  174. until: api_available_output.stdout == 'ok'
  175. retries: 120
  176. delay: 1
  177. changed_when: false
  178. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native' and master_api_service_status_changed | bool
  179. - name: Start and enable master controller
  180. service: name={{ openshift.common.service_type }}-master-controllers enabled=yes state=started
  181. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native'
  182. register: start_result
  183. - set_fact:
  184. master_controllers_service_status_changed: "{{ start_result | changed }}"
  185. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native'
  186. - name: Install cluster packages
  187. action: "{{ ansible_pkg_mgr }} name=pcs state=present"
  188. when: openshift_master_ha | bool and openshift.master.cluster_method == 'pacemaker'
  189. and not openshift.common.is_containerized | bool
  190. register: install_result
  191. - name: Start and enable cluster service
  192. service: name=pcsd enabled=yes state=started
  193. when: openshift_master_ha | bool and openshift.master.cluster_method == 'pacemaker'
  194. and not openshift.common.is_containerized | bool
  195. - name: Set the cluster user password
  196. shell: echo {{ openshift_master_cluster_password | quote }} | passwd --stdin hacluster
  197. when: install_result | changed
  198. - name: Lookup default group for ansible_ssh_user
  199. command: "/usr/bin/id -g {{ ansible_ssh_user }}"
  200. changed_when: false
  201. register: _ansible_ssh_user_gid
  202. - set_fact:
  203. client_users: "{{ [ansible_ssh_user, 'root'] | unique }}"
  204. - name: Create the client config dir(s)
  205. file:
  206. path: "~{{ item }}/.kube"
  207. state: directory
  208. mode: 0700
  209. owner: "{{ item }}"
  210. group: "{{ 'root' if item == 'root' else _ansible_ssh_user_gid.stdout }}"
  211. with_items: "{{ client_users }}"
  212. # TODO: Update this file if the contents of the source file are not present in
  213. # the dest file, will need to make sure to ignore things that could be added
  214. - name: Copy the admin client config(s)
  215. command: cp {{ openshift_master_config_dir }}/admin.kubeconfig ~{{ item }}/.kube/config
  216. args:
  217. creates: ~{{ item }}/.kube/config
  218. with_items: "{{ client_users }}"
  219. - name: Update the permissions on the admin client config(s)
  220. file:
  221. path: "~{{ item }}/.kube/config"
  222. state: file
  223. mode: 0700
  224. owner: "{{ item }}"
  225. group: "{{ 'root' if item == 'root' else _ansible_ssh_user_gid.stdout }}"
  226. with_items: "{{ client_users }}"