kubeasz/roles/harbor/tasks/main.yml

100 lines
3.4 KiB
YAML
Raw Normal View History

2022-12-16 09:24:25 +08:00
- name: 创建 {{ HARBOR_PATH }} 目录
file:
2022-12-16 09:24:25 +08:00
path: "{{ HARBOR_PATH }}"
state: directory
mode: 0755
2022-12-16 09:24:25 +08:00
# 注册变量 result如果 {{ HARBOR_PATH }} 目录下存在 registry 目录说明已经安装过 harbor则不进行安装
- name: 注册变量 result
2022-12-16 09:24:25 +08:00
command: ls {{ HARBOR_PATH }}
2017-12-25 15:05:21 +08:00
register: result
- block:
2021-02-08 21:23:00 +08:00
- name: 生成 harbor 随机密码
shell: < /dev/urandom tr -dc 0-9A-Za-z-_ | head -c 16
register: harbor_password_gen
- debug: var="harbor_password_gen.stdout"
- name: 生成 DB 随机密码
shell: < /dev/urandom tr -dc 0-9A-Za-z-_ | head -c 16
register: db_password_gen
- debug: var="db_password_gen.stdout"
- name: 下发 docker compose 二进制文件
copy: src={{ base_dir }}/bin/docker-compose dest={{ bin_dir }}/docker-compose mode=0755
- name: 下发 harbor 离线安装包
copy:
src: "{{ base_dir }}/down/harbor-offline-installer-{{ HARBOR_VER }}.tgz"
2022-12-16 09:24:25 +08:00
dest: "{{ HARBOR_PATH }}/harbor-offline-installer-{{ HARBOR_VER }}.tgz"
- name: 解压 harbor 离线安装包
2022-12-16 09:24:25 +08:00
shell: "cd {{ HARBOR_PATH }} && tar zxf harbor-offline-installer-{{ HARBOR_VER }}.tgz"
- name: 导入 harbor 所需 docker images
2022-12-16 09:24:25 +08:00
shell: "{{ bin_dir }}/docker load -i {{ HARBOR_PATH }}/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
- 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
2021-02-08 21:23:00 +08:00
- name: 分发自签名证书
2020-12-30 11:25:54 +08:00
copy: src={{ cluster_dir }}/ssl/{{ item }} dest={{ ca_dir }}/{{ item }}
with_items:
2021-02-08 21:23:00 +08:00
- ca.pem
2020-12-30 11:25:54 +08:00
- harbor.pem
- harbor-key.pem
2021-02-08 21:23:00 +08:00
when: 'HARBOR_SELF_SIGNED_CERT|bool'
2021-02-08 21:23:00 +08:00
- name: 推送非自签名证书(需提前在{{ base_dir }}/down/ 下载好证书)
copy: src={{ base_dir }}/down/{{ item }} dest={{ ca_dir }}/{{ item }}
with_items:
- harbor.pem
- harbor-key.pem
2021-02-08 21:23:00 +08:00
when: 'not HARBOR_SELF_SIGNED_CERT|bool'
2021-02-08 21:23:00 +08:00
- name: 准备 harbor 配置文件
2022-12-16 09:24:25 +08:00
template: src=harbor-{{ HARBOR_VER_MAIN }}.yml.j2 dest={{ HARBOR_PATH }}/harbor/harbor.yml
2021-02-08 21:23:00 +08:00
#- name: 配置 harbor.yml 文件
2022-12-16 09:24:25 +08:00
#template: src=harbor-{{ HARBOR_VER_MAIN }}.yml.j2 dest={{ HARBOR_PATH }}/harbor/harbor.yml
2021-02-08 21:23:00 +08:00
#when: HARBOR_VER_MAIN in ["v1.8", "v1.9", "v1.10"]
- set_fact: HARBOR_INST_OPS="{{ HARBOR_INST_OPS }} --with-chartmuseum"
when: "HARBOR_WITH_CHARTMUSEUM|bool"
- set_fact: HARBOR_INST_OPS="{{ HARBOR_INST_OPS }} --with-notary"
when: "HARBOR_WITH_NOTARY|bool"
- set_fact: HARBOR_INST_OPS="{{ HARBOR_INST_OPS }} --with-trivy"
when: "HARBOR_WITH_TRIVY|bool"
- set_fact: HARBOR_INST_OPS="{{ HARBOR_INST_OPS }} --with-clair"
when: "HARBOR_WITH_CLAIR|bool"
- debug: var="HARBOR_INST_OPS"
- name: 安装 harbor
2022-12-16 09:24:25 +08:00
shell: "cd {{ HARBOR_PATH }}/harbor && \
2021-02-08 21:23:00 +08:00
export PATH={{ bin_dir }}:$PATH && \
./install.sh {{ HARBOR_INST_OPS }} >> /tmp/harbor-`date +'%Y%m%d%H%M%S'`.log 2>&1"
when: '"registry" not in result.stdout'
- name: 检测 harbor 端口是否正常
wait_for:
host: "{{ inventory_hostname }}"
port: "{{ HARBOR_TLS_PORT }}"
timeout: 60
run_once: true