2018-06-08 09:22:43 +08:00
|
|
|
|
- name: 创建data目录
|
|
|
|
|
file:
|
|
|
|
|
path: /data
|
|
|
|
|
state: directory
|
|
|
|
|
mode: 0755
|
|
|
|
|
|
2018-08-26 10:58:27 +08:00
|
|
|
|
# 注册变量result,如果/data目录下存在registry目录说明已经安装过harbor,则不进行安装
|
2017-12-25 15:05:21 +08:00
|
|
|
|
- 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:
|
|
|
|
|
- name: 下载docker compose 二进制文件
|
|
|
|
|
copy: src={{ base_dir }}/bin/docker-compose dest={{ bin_dir }}/docker-compose mode=0755
|
|
|
|
|
|
|
|
|
|
- name: 安装解压工具
|
|
|
|
|
package: name={{ item }} state=present
|
|
|
|
|
with_items:
|
|
|
|
|
- zip
|
|
|
|
|
- unzip
|
|
|
|
|
|
|
|
|
|
- name: 解压harbor离线安装包
|
|
|
|
|
unarchive:
|
|
|
|
|
src: "{{ base_dir }}/down/harbor-offline-installer-{{ HARBOR_VER }}.zip"
|
|
|
|
|
dest: /data
|
|
|
|
|
copy: yes
|
|
|
|
|
keep_newer: yes
|
|
|
|
|
mode: 0755
|
|
|
|
|
|
|
|
|
|
- name: 导入harbor所需 docker images
|
|
|
|
|
shell: "{{ bin_dir }}/docker load -i /data/harbor/harbor.{{ HARBOR_VER }}.tar.gz"
|
|
|
|
|
|
|
|
|
|
- name: 创建harbor证书请求
|
|
|
|
|
template: src=harbor-csr.json.j2 dest={{ ca_dir }}/harbor-csr.json
|
|
|
|
|
|
|
|
|
|
- name: 创建harbor证书和私钥
|
|
|
|
|
shell: "cd {{ ca_dir }} && {{ bin_dir }}/cfssl gencert \
|
|
|
|
|
-ca={{ ca_dir }}/ca.pem \
|
|
|
|
|
-ca-key={{ ca_dir }}/ca-key.pem \
|
|
|
|
|
-config={{ ca_dir }}/ca-config.json \
|
|
|
|
|
-profile=kubernetes harbor-csr.json | {{ bin_dir }}/cfssljson -bare harbor"
|
|
|
|
|
|
|
|
|
|
- name: 配置 harbor.cfg 文件
|
|
|
|
|
template: src=harbor.cfg.j2 dest=/data/harbor/harbor.cfg
|
|
|
|
|
|
|
|
|
|
- name: 安装 harbor
|
|
|
|
|
shell: "cd /data/harbor && \
|
|
|
|
|
export PATH={{ bin_dir }}:$PATH && \
|
|
|
|
|
./install.sh --with-clair"
|
|
|
|
|
when: '"registry" not in result.stdout'
|