2018-09-29 09:06:19 +08:00
|
|
|
# [optional] to set up a HARBOR, and to integrate the HARBOR with k8s cluster
|
|
|
|
# read the guide: 'guide/harbor.md'
|
|
|
|
|
2021-02-08 21:23:00 +08:00
|
|
|
### --- install harbor ---
|
2017-12-25 15:05:21 +08:00
|
|
|
- hosts: harbor
|
|
|
|
roles:
|
2021-02-08 21:23:00 +08:00
|
|
|
- { role: os-harden, when: "NEW_INSTALL|bool and OS_HARDEN|bool" }
|
|
|
|
- { role: chrony, when: "NEW_INSTALL|bool and groups['chrony']|length > 0" }
|
|
|
|
- { role: prepare, when: "NEW_INSTALL|bool" }
|
|
|
|
- { role: docker, when: "NEW_INSTALL|bool" }
|
|
|
|
- { role: harbor, when: "NEW_INSTALL|bool" }
|
2018-08-26 10:58:27 +08:00
|
|
|
tasks:
|
2018-09-29 09:06:19 +08:00
|
|
|
- name: Fetching the HARBOR SERVER's CA cert
|
2018-08-26 10:58:27 +08:00
|
|
|
fetch:
|
|
|
|
src: "{{ ca_dir }}/ca.pem"
|
|
|
|
dest: "{{ base_dir }}/down/"
|
|
|
|
flat: yes
|
2021-02-08 21:23:00 +08:00
|
|
|
when: 'HARBOR_SELF_SIGNED_CERT|bool'
|
|
|
|
#when: hostvars[groups.harbor[0]]['SELF_SIGNED_CERT']|bool
|
2017-12-25 15:05:21 +08:00
|
|
|
|
2021-02-08 21:23:00 +08:00
|
|
|
### --- config k8s nodes to use with harbor ---
|
2018-02-26 20:45:17 +08:00
|
|
|
- hosts:
|
2021-01-19 17:41:00 +08:00
|
|
|
- kube_master
|
|
|
|
- kube_node
|
2017-12-25 15:05:21 +08:00
|
|
|
tasks:
|
2020-01-06 16:06:35 +08:00
|
|
|
- name: Define 'harbor_hostname', a domain name
|
2021-02-08 21:23:00 +08:00
|
|
|
set_fact: harbor_hostname={{ HARBOR_DOMAIN }}
|
|
|
|
when: "HARBOR_DOMAIN != ''"
|
2019-02-05 12:32:52 +08:00
|
|
|
|
2020-01-06 16:06:35 +08:00
|
|
|
- name: Define 'harbor_hostname', an IP Addr
|
|
|
|
set_fact: harbor_hostname={{ groups['harbor'][0] }}
|
2021-02-08 21:23:00 +08:00
|
|
|
when: "HARBOR_DOMAIN == ''"
|
|
|
|
|
2019-05-19 22:01:40 +08:00
|
|
|
- block:
|
2019-12-16 15:33:44 +08:00
|
|
|
- block:
|
|
|
|
- name: Creating cert dir for the docker daemon
|
2021-02-08 21:23:00 +08:00
|
|
|
file: name=/etc/docker/certs.d/{{ harbor_hostname }}:{{ HARBOR_TLS_PORT }} state=directory
|
2019-12-16 15:33:44 +08:00
|
|
|
|
|
|
|
- name: Installing the HARBOR SERVER's CA cert for docker
|
2021-02-08 21:23:00 +08:00
|
|
|
copy:
|
|
|
|
src: "{{ base_dir }}/down/ca.pem"
|
|
|
|
dest: "/etc/docker/certs.d/{{ harbor_hostname }}:{{ HARBOR_TLS_PORT }}/ca.crt"
|
2019-12-16 15:33:44 +08:00
|
|
|
when: CONTAINER_RUNTIME == 'docker'
|
2019-05-19 22:01:40 +08:00
|
|
|
|
2019-12-16 15:33:44 +08:00
|
|
|
- block:
|
|
|
|
- name: Installing the HARBOR SERVER's CA cert on k8s nodes
|
|
|
|
copy: src={{ base_dir }}/down/ca.pem dest=/usr/share/ca-certificates/harbor-ca.crt
|
2019-05-19 22:01:40 +08:00
|
|
|
|
2019-12-16 15:33:44 +08:00
|
|
|
- name: Add the HARBOR SERVER's CA cert
|
|
|
|
lineinfile:
|
|
|
|
dest: /etc/ca-certificates.conf
|
|
|
|
state: present
|
|
|
|
regexp: 'harbor-ca'
|
|
|
|
line: 'harbor-ca.crt'
|
2019-05-19 22:01:40 +08:00
|
|
|
|
2019-12-16 15:33:44 +08:00
|
|
|
- name: Update the trusted ca-certificates
|
|
|
|
shell: 'update-ca-certificates'
|
2019-05-19 22:01:40 +08:00
|
|
|
|
2019-12-16 15:33:44 +08:00
|
|
|
- name: restart containerd
|
|
|
|
service: name=containerd state=restarted
|
|
|
|
when:
|
|
|
|
- 'CONTAINER_RUNTIME == "containerd"'
|
|
|
|
- 'ansible_distribution == "Ubuntu"'
|
2019-05-19 22:01:40 +08:00
|
|
|
|
2019-12-16 15:33:44 +08:00
|
|
|
- block:
|
|
|
|
- name: Installing the HARBOR SERVER's CA cert on k8s nodes
|
|
|
|
copy: src={{ base_dir }}/down/ca.pem dest=/etc/pki/ca-trust/source/anchors/harbor-ca.crt
|
2019-05-19 22:01:40 +08:00
|
|
|
|
2019-12-16 15:33:44 +08:00
|
|
|
- name: Update the trusted ca-certificates
|
|
|
|
shell: 'update-ca-trust'
|
2019-05-19 22:01:40 +08:00
|
|
|
|
2019-12-16 15:33:44 +08:00
|
|
|
- name: restart containerd
|
|
|
|
service: name=containerd state=restarted
|
|
|
|
when:
|
|
|
|
- 'CONTAINER_RUNTIME == "containerd"'
|
2020-12-30 11:25:54 +08:00
|
|
|
- 'ansible_distribution in ["CentOS","RedHat","Amazon","Aliyun"]'
|
2021-02-08 21:23:00 +08:00
|
|
|
when: 'HARBOR_SELF_SIGNED_CERT|bool'
|
2017-12-25 15:05:21 +08:00
|
|
|
|
2018-09-29 09:06:19 +08:00
|
|
|
# [optional] if you have a DNS server, add an 'A record' instead
|
|
|
|
- name: Adding an '/etc/hosts' entry for the HARBOR DOMAIN
|
2018-05-04 22:11:08 +08:00
|
|
|
lineinfile:
|
|
|
|
dest: /etc/hosts
|
|
|
|
state: present
|
2020-01-06 16:06:35 +08:00
|
|
|
regexp: '{{ harbor_hostname }}'
|
|
|
|
line: "{{ groups['harbor'][0] }} {{ harbor_hostname }}"
|
2019-02-05 12:32:52 +08:00
|
|
|
when: "hostvars[groups.harbor[0]]['HARBOR_DOMAIN'] != ''"
|
2019-12-16 15:33:44 +08:00
|
|
|
|
2020-01-06 16:06:35 +08:00
|
|
|
# [optional] 使用 cloud-init 初始化的虚拟机,/etc/hosts 后会重启时被替换,需修改对应的模板文件
|
2019-12-16 15:33:44 +08:00
|
|
|
- name: Adding cloud-init hosts template (debian) entry for the HARBOR DOMAIN
|
|
|
|
lineinfile:
|
|
|
|
dest: /etc/cloud/templates/hosts.debian.tmpl
|
|
|
|
state: present
|
2020-01-06 16:06:35 +08:00
|
|
|
regexp: '{{ harbor_hostname }}'
|
|
|
|
line: "{{ groups['harbor'][0] }} {{ harbor_hostname }}"
|
2019-12-16 15:33:44 +08:00
|
|
|
when: 'ansible_distribution in ["Ubuntu","Debian"]'
|
|
|
|
|
|
|
|
- name: Adding cloud-init hosts template (redhat) entry for the HARBOR DOMAIN
|
|
|
|
lineinfile:
|
|
|
|
dest: /etc/cloud/templates/hosts.redhat.tmpl
|
|
|
|
state: present
|
2020-01-06 16:06:35 +08:00
|
|
|
regexp: '{{ harbor_hostname }}'
|
|
|
|
line: "{{ groups['harbor'][0] }} {{ harbor_hostname }}"
|
2020-12-30 11:25:54 +08:00
|
|
|
when: 'ansible_distribution in ["CentOS","RedHat","Amazon","Aliyun"]'
|