
We need to create repos in gitea before we do so in Gerrit (because they will not be replicated correctly if Gerrit pushes to a repo that doesn't already exist in gitea). Therefore, we need to add gitea to the repo creation playbook so that we create new repos based on the contents of project-config. This updates the gitea sync-repos playbook to use that instead of fetching the list from Gerrit. It also improves the gitea bootstrap playbook to wait for the load balancer to come online. Change-Id: I783a2eed497a830aaf71ad95dea03594774ff6d7
120 lines
4.1 KiB
YAML
120 lines
4.1 KiB
YAML
- hosts: localhost
|
|
tasks:
|
|
- name: Set up gitea namespace
|
|
k8s:
|
|
state: present
|
|
definition: "{{ lookup('template', 'k8s/namespace.yaml') | from_yaml }}"
|
|
- name: Set up gitea secrets
|
|
k8s:
|
|
state: present
|
|
definition: "{{ lookup('template', 'k8s/secret.yaml') | from_yaml }}"
|
|
- name: Set up gitea configmap
|
|
k8s:
|
|
state: present
|
|
definition:
|
|
apiVersion: v1
|
|
kind: ConfigMap
|
|
metadata:
|
|
name: gitea-conf
|
|
namespace: gitea
|
|
data:
|
|
# Note: we are not asking ansible to template this, it
|
|
# will be run by jinja-init
|
|
app.ini.j2: "{{ lookup('file', 'app.ini.j2') }}"
|
|
- name: Set up gitea deployment
|
|
k8s:
|
|
state: present
|
|
definition: "{{ lookup('template', 'k8s/deployment.yaml') | from_yaml }}"
|
|
- name: Set up gitea service
|
|
k8s:
|
|
state: present
|
|
definition: "{{ lookup('template', 'k8s/service.yaml') | from_yaml }}"
|
|
- name: Get service IP
|
|
k8s:
|
|
namespace: gitea
|
|
kind: Service
|
|
name: gitea-service
|
|
register: gitea_service
|
|
until: gitea_service.result.status.loadBalancer and gitea_service.result.status.loadBalancer.ingress and gitea_service.result.status.loadBalancer.ingress | length > 0 and gitea_service.result.status.loadBalancer.ingress[0].ip
|
|
delay: 1
|
|
retries: 300
|
|
- name: Set service url fact
|
|
set_fact:
|
|
gitea_url: "http://{{ gitea_service.result.status.loadBalancer.ingress[0].ip }}"
|
|
- name: Check if root user exists
|
|
uri:
|
|
url: "{{ gitea_url }}/api/v1/users/root"
|
|
status_code: 200, 404
|
|
register: root_user_check
|
|
- name: Create root user
|
|
when: root_user_check.status==404
|
|
block:
|
|
- name: Find gitea pods
|
|
k8s_facts:
|
|
namespace: gitea
|
|
kind: Pod
|
|
label_selectors:
|
|
- "app = gitea"
|
|
register: gitea_pods
|
|
- name: Create root user
|
|
command: "kubectl exec {{ gitea_pods.resources[0].metadata.name }} -n gitea -c gitea -- gitea admin create-user --name root --password {{ gitea_root_password }} --email {{ gitea_root_email }} --admin"
|
|
no_log: true
|
|
- name: Check if gerrit user exists
|
|
uri:
|
|
url: "{{ gitea_url }}/api/v1/users/gerrit"
|
|
status_code: 200, 404
|
|
register: gerrit_user_check
|
|
- name: Create gerrit user
|
|
when: gerrit_user_check.status==404
|
|
no_log: true
|
|
uri:
|
|
url: "{{ gitea_url }}/api/v1/admin/users"
|
|
method: POST
|
|
user: root
|
|
password: "{{ gitea_root_password }}"
|
|
force_basic_auth: true
|
|
status_code: 201
|
|
body_format: json
|
|
body:
|
|
email: "gerrit@review.opendev.org"
|
|
full_name: Gerrit
|
|
login_name: gerrit
|
|
password: "{{ gitea_gerrit_password }}"
|
|
send_notify: false
|
|
source_id: 0
|
|
username: gerrit
|
|
- name: Check if gerrit ssh key exists
|
|
uri:
|
|
user: root
|
|
password: "{{ gitea_root_password }}"
|
|
force_basic_auth: true
|
|
url: "{{ gitea_url }}/api/v1/users/gerrit/keys"
|
|
status_code: 200
|
|
register: gerrit_key_check
|
|
no_log: true
|
|
- name: Delete old gerrit ssh key
|
|
when: gerrit_key_check.json | length > 0 and gerrit_key_check.json[0].key != gitea_gerrit_public_key
|
|
no_log: true
|
|
uri:
|
|
user: root
|
|
password: "{{ gitea_root_password }}"
|
|
force_basic_auth: true
|
|
url: "{{ gitea_url }}/api/v1/user/keys/{{ gerrit_key_check.json[0].id }}"
|
|
method: DELETE
|
|
status_code: 204
|
|
- name: Add gerrit ssh key
|
|
when: gerrit_key_check.json | length == 0
|
|
no_log: true
|
|
uri:
|
|
user: root
|
|
password: "{{ gitea_root_password }}"
|
|
force_basic_auth: true
|
|
url: "{{ gitea_url }}/api/v1/admin/users/gerrit/keys"
|
|
method: POST
|
|
status_code: 201
|
|
body_format: json
|
|
body:
|
|
key: "{{ gitea_gerrit_public_key }}"
|
|
read_only: false
|
|
title: "Gerrit replication key"
|