Changed all 'become: ' values from 'yes' to 'true' to satisfy the schema (and also make the lsp shut up).
125 lines
3.6 KiB
YAML
125 lines
3.6 KiB
YAML
---
|
|
## Prepare woodpecker ci
|
|
- name: "Select tasks for {{ ansible_distribution }} {{ ansible_distribution_major_version }}"
|
|
include_tasks: "{{ distribution }}"
|
|
with_first_found:
|
|
- "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
|
|
- "{{ ansible_distribution }}.yml"
|
|
- "{{ ansible_os_family }}.yml"
|
|
loop_control:
|
|
loop_var: distribution
|
|
when: gitea_use_ci == True
|
|
|
|
# TODO only generate when no existing (check with docker inspect?)
|
|
- name: Generate agent key
|
|
ansible.builtin.shell: openssl rand -hex 32
|
|
register: gitea_woodpecker_agent_secret
|
|
when: gitea_use_ci == True
|
|
|
|
- name: Set agent key
|
|
ansible.builtin.set_fact:
|
|
gitea_woodpecker_agent_secret: "{{ gitea_woodpecker_agent_secret.stdout }}"
|
|
when: gitea_woodpecker_agent_secret.stdout is not undefined and not None
|
|
|
|
## Prepare gitea
|
|
- name: Ensure git user exists with ssh key
|
|
ansible.builtin.user:
|
|
name: "{{ gitea_git_username }}"
|
|
generate_ssh_key: yes
|
|
ssh_key_type: rsa
|
|
ssh_key_bits: 4096
|
|
ssh_key_comment: "Gitea Host Key"
|
|
become: true
|
|
register: git_user
|
|
|
|
- name: Ensure git passthrough command directory exists
|
|
ansible.builtin.file:
|
|
path: "/app/gitea/"
|
|
state: directory
|
|
mode: '0770'
|
|
owner: "{{ git_user['uid'] }}"
|
|
group: "{{ git_user['group'] }}"
|
|
become: true
|
|
|
|
- name: Save git passthrough command in right location
|
|
ansible.builtin.copy:
|
|
src: gitea
|
|
dest: "/app/gitea/gitea"
|
|
owner: "{{ git_user['uid'] }}"
|
|
group: "{{ git_user['group'] }}"
|
|
mode: '0750'
|
|
become: true
|
|
|
|
- name: Fetch keyfile
|
|
fetch:
|
|
src: "{{ git_user['home'] }}/.ssh/id_rsa.pub"
|
|
dest: "buffer/{{ansible_hostname}}-id_rsa.pub"
|
|
flat: yes
|
|
become: true
|
|
|
|
- name: Ensure git user has its own key authorized for access
|
|
ansible.posix.authorized_key:
|
|
user: "{{ git_user['name'] }}"
|
|
state: present
|
|
key: "{{ lookup('file', 'buffer/{{ ansible_hostname }}-id_rsa.pub') }}"
|
|
become: true
|
|
|
|
- name: Clean up buffer dir
|
|
ansible.builtin.file:
|
|
path: buffer
|
|
state: absent
|
|
delegate_to: localhost
|
|
|
|
## install gitea container
|
|
- name: Check upstream status
|
|
community.docker.docker_container_exec:
|
|
container: "{{ caddy_container_id }}"
|
|
command: >
|
|
curl localhost:2019/id/{{ stack_name }}_upstream/
|
|
register: result
|
|
changed_when: (result.stdout | from_json) != (lookup('template', 'upstream.json.j2') | from_yaml)
|
|
become: true
|
|
notify: "update gitea upstream"
|
|
|
|
- name: Deploy gitea to swarm
|
|
community.general.docker_stack:
|
|
name: "{{ stack_name }}"
|
|
state: present
|
|
prune: yes
|
|
compose:
|
|
- "{{ stack_compose }}"
|
|
become: true
|
|
tags:
|
|
- docker-swarm
|
|
register: gitea_deployment
|
|
notify: "update gitea upstream"
|
|
|
|
- name: Wait 30 seconds for gitea to become healthy
|
|
wait_for:
|
|
timeout: 30
|
|
delegate_to: localhost
|
|
when: gitea_deployment is changed
|
|
|
|
- name: Get app container info
|
|
ansible.builtin.command:
|
|
cmd: docker ps -q -f name={{ stack_name }}_app
|
|
become: true
|
|
until: gitea_app_container_name['rc'] == 0 and gitea_app_container_name['stdout'] | length >= 1
|
|
retries: 10
|
|
delay: 10
|
|
changed_when: False
|
|
register: gitea_app_container_name
|
|
|
|
- name: Look for existing admin user
|
|
community.docker.docker_container_exec:
|
|
container: "{{ gitea_app_container_name['stdout'] }}"
|
|
user: git
|
|
command: >
|
|
gitea admin user list --admin
|
|
until: gitea_admin_list is defined and gitea_admin_list['rc'] == 0
|
|
retries: 15
|
|
delay: 10
|
|
become: true
|
|
register: gitea_admin_list
|
|
changed_when: gitea_admin_list['stdout_lines'] | length <= 1 and 'Username' in gitea_admin_list['stdout']
|
|
notify: "no admin user"
|