2024-09-07 14:34:44 +00:00
|
|
|
---
|
2024-09-22 01:47:57 +00:00
|
|
|
- name: This playbook installs and setups gitea along with postgresql
|
2024-09-07 14:34:44 +00:00
|
|
|
hosts: aws
|
|
|
|
become: true
|
2024-09-07 21:10:38 +00:00
|
|
|
vars_files:
|
2024-11-05 15:14:16 +00:00
|
|
|
- ../../vars/secrets.yml
|
2024-11-05 19:47:02 +00:00
|
|
|
- ../../vars/vars.yml
|
2024-09-07 21:10:38 +00:00
|
|
|
vars:
|
|
|
|
postgresql_user: gitea
|
|
|
|
postgresql_db: giteadb
|
2024-09-07 23:31:04 +00:00
|
|
|
container_network: host
|
2024-09-07 23:03:57 +00:00
|
|
|
gitea_directory: /home/ubuntu/hifadhi_kuu/gitea
|
2024-09-07 14:34:44 +00:00
|
|
|
tasks:
|
|
|
|
- name: install postgresql
|
|
|
|
apt:
|
2024-09-07 21:10:38 +00:00
|
|
|
name: "{{item}}"
|
2024-11-05 15:14:16 +00:00
|
|
|
state: present
|
2024-09-07 21:10:38 +00:00
|
|
|
loop:
|
|
|
|
- postgresql
|
|
|
|
- postgresql-contrib
|
|
|
|
- libpq-dev
|
|
|
|
- python3-dev
|
|
|
|
- python3-pip
|
|
|
|
- acl
|
|
|
|
|
|
|
|
- name: install pyscopg python module
|
|
|
|
ansible.builtin.pip:
|
|
|
|
name: psycopg2
|
2024-09-07 14:34:44 +00:00
|
|
|
|
|
|
|
- name: enable the postgresql service
|
|
|
|
service:
|
|
|
|
name: postgresql
|
|
|
|
enabled: true
|
|
|
|
|
|
|
|
- name: start the postgresql service
|
|
|
|
service:
|
|
|
|
name: postgresql
|
|
|
|
state: started
|
2024-09-07 21:10:38 +00:00
|
|
|
|
|
|
|
- name: create giteadb database
|
|
|
|
become_user: postgres
|
|
|
|
community.postgresql.postgresql_db:
|
|
|
|
name: "{{postgresql_db}}"
|
|
|
|
encoding: UTF-8
|
|
|
|
lc_collate: en_US.UTF-8
|
|
|
|
lc_ctype: en_US.UTF-8
|
|
|
|
template: template0
|
|
|
|
|
|
|
|
- name: create user gitea
|
|
|
|
become_user: postgres
|
|
|
|
community.postgresql.postgresql_user:
|
|
|
|
name: "{{postgresql_user}}"
|
|
|
|
password: "{{postgresql_password}}"
|
|
|
|
environment:
|
|
|
|
PGOPTIONS: "-c password_encryption=scram-sha-256"
|
|
|
|
|
|
|
|
- name: grant priviledges to giteadb to user gitea
|
|
|
|
become_user: postgres
|
|
|
|
community.postgresql.postgresql_privs:
|
|
|
|
db: giteadb
|
|
|
|
privs: ALL
|
|
|
|
type: database
|
|
|
|
role: gitea
|
|
|
|
|
|
|
|
- name: let gitea authenticate as a peer
|
|
|
|
ansible.builtin.lineinfile:
|
|
|
|
path: /etc/postgresql/14/main/pg_hba.conf
|
|
|
|
regexp: "^local.*all.*all.*peer"
|
|
|
|
line: "local all all scram-sha-256"
|
2024-09-07 23:03:57 +00:00
|
|
|
|
|
|
|
- name: create the gitea directory for the service
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: "{{gitea_directory}}"
|
|
|
|
state: directory
|
|
|
|
mode: '0755'
|
|
|
|
|
2024-09-21 20:55:59 +00:00
|
|
|
- name: download the gitea binary if it doesn't exist
|
|
|
|
ansible.builtin.get_url:
|
|
|
|
url: https://dl.gitea.com/gitea/1.22.2/gitea-1.22.2-linux-amd64.asc
|
|
|
|
dest: /home/ubuntu/hifadhi_kuu/gitea
|
|
|
|
|
|
|
|
- name: download the gitea binary if it doesn't exist
|
|
|
|
ansible.builtin.get_url:
|
|
|
|
url: https://dl.gitea.com/gitea/1.22.2/gitea-1.22.2-linux-amd64
|
|
|
|
dest: /home/ubuntu/hifadhi_kuu/gitea
|
|
|
|
checksum: sha256:https://dl.gitea.com/gitea/1.22.2/gitea-1.22.2-linux-amd64.sha256
|
|
|
|
|
|
|
|
- name: use shell command to execute a bunch of gpg commands to verify binary
|
|
|
|
ansible.builtin.shell: |
|
|
|
|
gpg --keyserver keys.openpgp.org --recv 7C9E68152594688862D62AF62D9AE806EC1592E2
|
|
|
|
gpg --verify gitea-1.22.2-linux-amd64.asc gitea-1.22.2-linux-amd64
|
|
|
|
args:
|
|
|
|
chdir: /home/ubuntu/hifadhi_kuu/gitea
|
|
|
|
ignore_errors: true
|
|
|
|
register: gpg_result
|
|
|
|
|
|
|
|
- name: display results of gpg verification for go binary
|
|
|
|
ansible.builtin.debug:
|
|
|
|
var: gpg_result
|
2024-09-21 22:31:16 +00:00
|
|
|
ignore_errors: true
|
2024-09-21 20:55:59 +00:00
|
|
|
|
|
|
|
|
2024-09-21 22:31:16 +00:00
|
|
|
- name: creates user to run gitea
|
|
|
|
ansible.builtin.user:
|
|
|
|
name: git
|
|
|
|
shell: /bin/bash
|
|
|
|
system: true
|
|
|
|
comment: "Gitea repo manager"
|
|
|
|
state: present
|
2024-09-21 20:55:59 +00:00
|
|
|
|
2024-09-22 01:47:57 +00:00
|
|
|
- name: create gitea core directories
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: /var/lib/gitea/{{item}}
|
|
|
|
state: directory
|
|
|
|
recurse: yes
|
|
|
|
owner: git
|
|
|
|
group: git
|
|
|
|
mode: '0750'
|
|
|
|
loop:
|
|
|
|
- ""
|
|
|
|
- custom
|
|
|
|
- data
|
|
|
|
- log
|
2024-09-21 20:55:59 +00:00
|
|
|
|
2024-09-22 02:07:45 +00:00
|
|
|
- name: create gitea config directory
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: /etc/gitea
|
|
|
|
state: directory
|
|
|
|
owner: root
|
|
|
|
group: git
|
|
|
|
mode: '770'
|
|
|
|
|
2024-09-22 02:18:47 +00:00
|
|
|
- name: download gitea systemd service
|
|
|
|
ansible.builtin.get_url:
|
|
|
|
url: https://raw.githubusercontent.com/go-gitea/gitea/refs/heads/release/v1.22/contrib/systemd/gitea.service
|
|
|
|
dest: /etc/systemd/system/gitea.service
|
2024-09-22 03:04:16 +00:00
|
|
|
|
|
|
|
- name: copy the gitea binary to /usr/local/bin directory
|
|
|
|
copy:
|
|
|
|
src: /home/ubuntu/hifadhi_kuu/gitea/gitea-1.22.2-linux-amd64
|
|
|
|
remote_src: yes
|
|
|
|
dest: /usr/local/bin/gitea
|
|
|
|
owner: git
|
2024-09-22 03:37:01 +00:00
|
|
|
mode: '0744'
|
|
|
|
|
|
|
|
|
|
|
|
- name: start the gitea service
|
|
|
|
service:
|
|
|
|
name: gitea
|
|
|
|
state: started
|
|
|
|
enabled: yes
|
2024-11-05 15:14:16 +00:00
|
|
|
|
2024-11-05 16:02:03 +00:00
|
|
|
- name: download the gitea action binary if it doesn't exist
|
|
|
|
ansible.builtin.get_url:
|
|
|
|
url: https://gitea.com/gitea/act_runner/releases/download/v0.2.11/act_runner-0.2.11-linux-amd64
|
|
|
|
dest: /home/ubuntu/hifadhi_kuu/gitea
|
|
|
|
|
|
|
|
- name: copy the gitea runner binary to /usr/local/bin directory
|
|
|
|
copy:
|
|
|
|
src: /home/ubuntu/hifadhi_kuu/gitea/act_runner-0.2.11-linux-amd64
|
|
|
|
remote_src: true
|
|
|
|
dest: /usr/local/bin/act_runner
|
2024-11-05 19:47:02 +00:00
|
|
|
owner: git
|
|
|
|
mode: '0755'
|
2024-11-05 16:02:03 +00:00
|
|
|
|
|
|
|
- name: configure the gitea action runner non-interactively
|
|
|
|
ansible.builtin.shell:
|
|
|
|
cmd: |
|
|
|
|
chmod +x /usr/local/bin/act_runner
|
|
|
|
act_runner --version
|
|
|
|
act_runner register --no-interactive --instance \
|
|
|
|
https://gitea.kwerezigua.org --token "{{gitea_action_token}}" \
|
|
|
|
--name mfanyakazi
|
|
|
|
args:
|
|
|
|
chdir: /home/ubuntu/hifadhi_kuu/gitea
|
|
|
|
|
2024-11-05 19:47:02 +00:00
|
|
|
- name: install the act_runner systemd service
|
|
|
|
ansible.builtin.template:
|
|
|
|
src: ../../templates/act_runner.service.j2
|
|
|
|
dest: /etc/systemd/system/act_runner.service
|
|
|
|
|
|
|
|
- name: start the gitea action service
|
|
|
|
service:
|
|
|
|
name: act_runner
|
|
|
|
state: restarted
|
|
|
|
enabled: true
|