2019-12-16 15:33:44 +08:00
|
|
|
|
- name: 生成 harbor 随机密码
|
|
|
|
|
shell: < /dev/urandom tr -dc 0-9A-Za-z-_ | head -c 16
|
|
|
|
|
register: harbor_password_gen
|
|
|
|
|
|
|
|
|
|
- name: 生成 DB 随机密码
|
|
|
|
|
shell: < /dev/urandom tr -dc 0-9A-Za-z-_ | head -c 16
|
|
|
|
|
register: db_password_gen
|
|
|
|
|
|
|
|
|
|
- name: 创建 data 目录
|
2018-06-08 09:22:43 +08:00
|
|
|
|
file:
|
|
|
|
|
path: /data
|
|
|
|
|
state: directory
|
|
|
|
|
mode: 0755
|
|
|
|
|
|
2019-12-16 15:33:44 +08:00
|
|
|
|
# 注册变量 result,如果 /data 目录下存在 registry 目录说明已经安装过 harbor,则不进行安装
|
|
|
|
|
- name: 注册变量 result
|
2018-08-26 10:58:27 +08:00
|
|
|
|
command: ls /data
|
2017-12-25 15:05:21 +08:00
|
|
|
|
register: result
|
|
|
|
|
|
2018-08-26 10:58:27 +08:00
|
|
|
|
- block:
|
2019-12-16 15:33:44 +08:00
|
|
|
|
- name: 下发 docker compose 二进制文件
|
|
|
|
|
copy: src={{ base_dir }}/bin/docker-compose dest={{ bin_dir }}/docker-compose mode=0755
|
2018-08-26 10:58:27 +08:00
|
|
|
|
|
2019-12-16 15:33:44 +08:00
|
|
|
|
- name: 下发 harbor 离线安装包
|
|
|
|
|
copy:
|
|
|
|
|
src: "{{ base_dir }}/down/harbor-offline-installer-{{ HARBOR_VER }}.tgz"
|
|
|
|
|
dest: "/data/harbor-offline-installer-{{ HARBOR_VER }}.tgz"
|
2019-02-05 09:46:26 +08:00
|
|
|
|
|
2019-12-16 15:33:44 +08:00
|
|
|
|
- name: 解压 harbor 离线安装包
|
|
|
|
|
shell: "cd /data && tar zxf harbor-offline-installer-{{ HARBOR_VER }}.tgz"
|
2019-02-05 09:46:26 +08:00
|
|
|
|
|
2019-12-16 15:33:44 +08:00
|
|
|
|
- name: 导入 harbor 所需 docker images
|
|
|
|
|
shell: "{{ bin_dir }}/docker load -i /data/harbor/harbor.{{ HARBOR_VER }}.tar.gz"
|
|
|
|
|
|
|
|
|
|
- block:
|
|
|
|
|
- name: 创建 harbor 证书请求
|
2020-12-30 11:25:54 +08:00
|
|
|
|
template: src=harbor-csr.json.j2 dest={{ cluster_dir }}/ssl/harbor-csr.json
|
|
|
|
|
connection: local
|
2018-08-26 10:58:27 +08:00
|
|
|
|
|
2019-12-16 15:33:44 +08:00
|
|
|
|
- name: 创建 harbor 证书和私钥
|
2020-12-30 11:25:54 +08:00
|
|
|
|
shell: "cd {{ cluster_dir }}/ssl && {{ base_dir }}/bin/cfssl gencert \
|
|
|
|
|
-ca=ca.pem \
|
|
|
|
|
-ca-key=ca-key.pem \
|
|
|
|
|
-config=ca-config.json \
|
|
|
|
|
-profile=kubernetes harbor-csr.json|{{ base_dir }}/bin/cfssljson -bare harbor"
|
|
|
|
|
connection: local
|
|
|
|
|
|
|
|
|
|
- name: 生成自签名证书相关
|
|
|
|
|
copy: src={{ cluster_dir }}/ssl/{{ item }} dest={{ ca_dir }}/{{ item }}
|
|
|
|
|
with_items:
|
|
|
|
|
- harbor.pem
|
|
|
|
|
- harbor-key.pem
|
2019-12-16 15:33:44 +08:00
|
|
|
|
when: SELF_SIGNED_CERT == 'yes'
|
|
|
|
|
|
|
|
|
|
- name: 复制 down 目录下 harbor 证书
|
|
|
|
|
copy: src={{ base_dir }}/down/{{ item }} dest={{ ca_dir }}/{{ item }}
|
|
|
|
|
with_items:
|
|
|
|
|
- harbor.pem
|
|
|
|
|
- harbor-key.pem
|
|
|
|
|
when: SELF_SIGNED_CERT == 'no'
|
|
|
|
|
|
|
|
|
|
- name: 配置 harbor.cfg 文件
|
|
|
|
|
template: src=harbor-{{ HARBOR_VER_MAIN }}.cfg.j2 dest=/data/harbor/harbor.cfg
|
|
|
|
|
when: HARBOR_VER_MAIN in ["v1.5", "v1.6", "v1.7"]
|
|
|
|
|
|
|
|
|
|
- name: 配置 harbor.yml 文件
|
|
|
|
|
template: src=harbor-{{ HARBOR_VER_MAIN }}.yml.j2 dest=/data/harbor/harbor.yml
|
|
|
|
|
when: HARBOR_VER_MAIN in ["v1.8", "v1.9", "v1.10"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: 安装 harbor --with-clair
|
|
|
|
|
shell: "cd /data/harbor && \
|
|
|
|
|
export PATH={{ bin_dir }}:$PATH && \
|
|
|
|
|
./install.sh --with-clair"
|
2018-08-26 10:58:27 +08:00
|
|
|
|
when: '"registry" not in result.stdout'
|