/
/
/
Ansible role that deployes services on my runner machine
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 }}/harbor-offline-installer-v{{ harbor_version }}.tgz"
38 dest: "/tmp/harbor-offline-installer-v{{ harbor_version }}.tgz"
39 timeout: 300
40 tags: [harbor, download]
41 check_mode: no
42
43- name: "Extract Harbor installer"
44 ansible.builtin.unarchive:
45 src: "/tmp/harbor-offline-installer-v{{ harbor_version }}.tgz"
46 dest: "/tmp"
47 remote_src: yes
48 creates: "/tmp/harbor"
49 tags: [harbor, extract]
50 check_mode: no
51
52- name: "Copy Harbor files to config directory"
53 ansible.builtin.copy:
54 src: "/tmp/harbor/"
55 dest: "{{ harbor_config_dir }}"
56 owner: "{{ runner_user }}"
57 group: "{{ runner_group }}"
58 mode: "0755"
59 remote_src: yes
60 tags: [harbor, setup]
61 check_mode: no
62
63- name: "Run Harbor installer with sudo"
64 ansible.builtin.command:
65 cmd: sudo ./install.sh
66 chdir: "{{ harbor_config_dir }}"
67 environment:
68 HARBOR_CONFIG: "{{ harbor_config_dir }}/harbor.yml"
69 when: not ansible_check_mode # SAFETY: Prevent actual installer execution in check mode
70 tags: [harbor, install]
71
72- name: "Stop Harbor services after installation"
73 ansible.builtin.command:
74 cmd: docker compose down
75 chdir: "{{ harbor_config_dir }}"
76 ignore_errors: yes
77 when: not ansible_check_mode # SAFETY: Prevent service stoppage in check mode
78 tags: [harbor, setup]
79
80- name: "Fix Harbor directory permissions"
81 ansible.builtin.file:
82 path: "{{ harbor_config_dir }}"
83 state: directory
84 owner: "{{ runner_user }}"
85 group: "{{ runner_group }}"
86 mode: "0775"
87 recurse: yes
88 tags: [harbor, permissions]
89
90- name: "Start Harbor services with proper user"
91 community.docker.docker_compose_v2:
92 project_src: "{{ harbor_config_dir }}"
93 state: present
94 tags: [harbor, services]
95 check_mode: no
96
97- name: "Wait for Harbor to be ready"
98 ansible.builtin.wait_for:
99 port: "{{ harbor_http_port | default(8080) }}"
100 host: "{{ ansible_default_ipv4.address }}"
101 delay: 10
102 timeout: 120
103 tags: [harbor, verification]
104
105- name: "Verify Harbor container is running"
106 community.docker.docker_container_info:
107 name: harbor-core
108 register: harbor_container_status
109 tags: [harbor, verify]
110
111- name: "Display Harbor deployment status"
112 ansible.builtin.debug:
113 msg:
114 - "Harbor Container Registry deployed successfully"
115 - "Status: {{ harbor_container_status.container.State.Status | default('unknown') }}"
116 - "Web UI: http://{{ ansible_default_ipv4.address }}:{{ harbor_http_port | default(8080) }}"
117 - "Admin User: admin"
118 - "Admin Password: {{ harbor_admin_password | default('Harbor12345') }}"
119 - "Registry: {{ ansible_default_ipv4.address }}:{{ harbor_registry_port | default(5000) }}"
120 tags: [harbor, info]