runner

Ansible role that deployes services on my runner machine

4 KBYML
harbor.yml
4 KB117 lines • yaml
1---
2# ========================================
3# HARBOR CONTAINER REGISTRY DEPLOYMENT
4# ========================================
5# Special deployment for Harbor registry using official installer
6# Requires: Download installer, run install.sh, then fix permissions
7
8- name: "Display Harbor deployment information"
9  ansible.builtin.debug:
10    msg:
11      - "Deploying Harbor Container Registry"
12      - "Config Directory: {{ harbor_config_dir }}"
13      - "NFS Storage: {{ runner_nfs_mount_dir }}/harbor"
14      - "Registry Domain: {{ harbor_hostname | default('registry.local') }}"
15  tags: [harbor, info]
16
17- name: "Create Harbor configuration directory"
18  ansible.builtin.file:
19    path: "{{ harbor_config_dir }}"
20    state: directory
21    owner: "{{ runner_user }}"
22    group: "{{ runner_group }}"
23    mode: "0755"
24  tags: [harbor, setup]
25
26- name: "Create Harbor configuration template"
27  ansible.builtin.template:
28    src: harbor.yml.j2
29    dest: "{{ harbor_config_dir }}/harbor.yml"
30    owner: "{{ runner_user }}"
31    group: "{{ runner_group }}"
32    mode: "0644"
33  tags: [harbor, config]
34
35- name: "Download Harbor offline installer"
36  ansible.builtin.get_url:
37    url: "https://github.com/goharbor/harbor/releases/download/v{{ harbor_version | default('2.13.0') }}/harbor-offline-installer-v{{ harbor_version | default('2.13.0') }}.tgz"
38    dest: "/tmp/harbor-offline-installer-v{{ harbor_version | default('2.13.0') }}.tgz"
39    checksum: "sha256:{{ harbor_checksum | default('b4a3b0e7d8e3a8b1c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1') }}"
40    timeout: 300
41  tags: [harbor, download]
42
43- name: "Extract Harbor installer"
44  ansible.builtin.unarchive:
45    src: "/tmp/harbor-offline-installer-v{{ harbor_version | default('2.13.0') }}.tgz"
46    dest: "/tmp"
47    remote_src: yes
48    creates: "/tmp/harbor"
49  tags: [harbor, extract]
50
51- name: "Copy Harbor files to config directory"
52  ansible.builtin.copy:
53    src: "/tmp/harbor/"
54    dest: "{{ harbor_config_dir }}"
55    owner: "{{ runner_user }}"
56    group: "{{ runner_group }}"
57    mode: "0755"
58    remote_src: yes
59  tags: [harbor, setup]
60
61- name: "Run Harbor installer with sudo"
62  ansible.builtin.command:
63    cmd: sudo ./install.sh
64    chdir: "{{ harbor_config_dir }}"
65  environment:
66    HARBOR_CONFIG: "{{ harbor_config_dir }}/harbor.yml"
67  when: not ansible_check_mode  # SAFETY: Prevent actual installer execution in check mode
68  tags: [harbor, install]
69
70- name: "Stop Harbor services after installation"
71  ansible.builtin.command:
72    cmd: docker compose down
73    chdir: "{{ harbor_config_dir }}"
74  ignore_errors: yes
75  when: not ansible_check_mode  # SAFETY: Prevent service stoppage in check mode
76  tags: [harbor, setup]
77
78- name: "Fix Harbor directory permissions"
79  ansible.builtin.file:
80    path: "{{ harbor_config_dir }}"
81    state: directory
82    owner: "{{ runner_user }}"
83    group: "{{ runner_group }}"
84    mode: "0775"
85    recurse: yes
86  tags: [harbor, permissions]
87
88- name: "Start Harbor services with proper user"
89  community.docker.docker_compose:
90    project_src: "{{ harbor_config_dir }}"
91    state: present
92  tags: [harbor, services]
93
94- name: "Wait for Harbor to be ready"
95  ansible.builtin.wait_for:
96    port: "{{ harbor_http_port | default(8080) }}"
97    host: "{{ ansible_default_ipv4.address }}"
98    delay: 10
99    timeout: 120
100  tags: [harbor, verification]
101
102- name: "Verify Harbor container is running"
103  community.docker.docker_container_info:
104    name: harbor-core
105  register: harbor_container_status
106  tags: [harbor, verify]
107
108- name: "Display Harbor deployment status"
109  ansible.builtin.debug:
110    msg:
111      - "Harbor Container Registry deployed successfully"
112      - "Status: {{ harbor_container_status.container.State.Status | default('unknown') }}"
113      - "Web UI: http://{{ ansible_default_ipv4.address }}:{{ harbor_http_port | default(8080) }}"
114      - "Admin User: admin"
115      - "Admin Password: {{ harbor_admin_password | default('Harbor12345') }}"
116      - "Registry: {{ ansible_default_ipv4.address }}:{{ harbor_registry_port | default(5000) }}"
117  tags: [harbor, info]