2023-08-05 17:11:17 +00:00
|
|
|
---
|
|
|
|
- name: Update web servers
|
|
|
|
hosts: all
|
|
|
|
remote_user: root
|
2023-08-05 17:46:41 +00:00
|
|
|
vars:
|
|
|
|
forgejo: 1.20.2-0
|
2023-08-05 18:06:35 +00:00
|
|
|
domain: git.keks.cloud
|
|
|
|
sslmail: admin@keks.cloud
|
2023-08-05 17:51:01 +00:00
|
|
|
handlers:
|
|
|
|
- name: Restart forgejo
|
|
|
|
ansible.builtin.service:
|
|
|
|
name: "forgejo"
|
|
|
|
state: restarted
|
2023-08-05 17:53:24 +00:00
|
|
|
|
2023-08-05 17:11:17 +00:00
|
|
|
tasks:
|
|
|
|
- name: Install a list of packages
|
2023-08-05 17:27:30 +00:00
|
|
|
ansible.builtin.apt:
|
|
|
|
pkg:
|
|
|
|
- mariadb-server
|
2023-08-05 17:34:22 +00:00
|
|
|
- python3-pymysql
|
2023-08-05 18:06:35 +00:00
|
|
|
- nginx
|
|
|
|
- certbot
|
|
|
|
- python3-certbot-nginx
|
2023-08-05 17:27:30 +00:00
|
|
|
|
2023-08-05 17:11:17 +00:00
|
|
|
- name: Add the user 'git'
|
|
|
|
ansible.builtin.user:
|
|
|
|
name: git
|
|
|
|
comment: Git Username
|
|
|
|
home: /home/git
|
|
|
|
shell: /bin/bash
|
|
|
|
- name: Create /var/lib/forgejo
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: /var/lib/forgejo
|
|
|
|
state: directory
|
2023-08-05 17:28:50 +00:00
|
|
|
owner: git
|
2023-08-05 17:11:17 +00:00
|
|
|
group: git
|
|
|
|
mode: '0750'
|
|
|
|
- name: Create /etc/forgejo
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: /etc/forgejo
|
|
|
|
state: directory
|
2023-08-05 17:28:50 +00:00
|
|
|
owner: git
|
2023-08-05 17:11:17 +00:00
|
|
|
group: git
|
2023-08-05 17:33:14 +00:00
|
|
|
mode: '0500'
|
2023-08-05 17:46:41 +00:00
|
|
|
|
|
|
|
- name: Create /usr/local/bin/
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: /usr/local/bin/
|
|
|
|
state: directory
|
|
|
|
owner: git
|
|
|
|
group: git
|
|
|
|
mode: '0500'
|
|
|
|
|
2023-08-05 17:53:24 +00:00
|
|
|
- name: Download Forgejo
|
2023-08-05 17:46:41 +00:00
|
|
|
get_url:
|
|
|
|
url: "https://codeberg.org/forgejo/forgejo/releases/download/v{{ forgejo }}/forgejo-{{ forgejo }}-linux-amd64"
|
|
|
|
dest: "/usr/local/bin/forgejo-{{forgejo}}-linux-amd64"
|
|
|
|
mode: '0755'
|
|
|
|
|
|
|
|
- name: Create a symbolic link
|
|
|
|
ansible.builtin.file:
|
|
|
|
src: "/usr/local/bin/forgejo-{{forgejo}}-linux-amd64"
|
2023-08-05 17:53:24 +00:00
|
|
|
dest: "/usr/local/bin/forgejo"
|
2023-08-05 17:46:41 +00:00
|
|
|
state: link
|
2023-08-05 17:47:48 +00:00
|
|
|
notify:
|
|
|
|
- Restart forgejo
|
2023-08-05 17:46:41 +00:00
|
|
|
|
2023-08-05 18:06:35 +00:00
|
|
|
#NGINX + Certbot
|
|
|
|
- name: NGINX Check that the forgejo.conf exists
|
|
|
|
stat:
|
|
|
|
path: /etc/nginx/sites-enabled/forgejo.conf
|
|
|
|
register: stat_result
|
|
|
|
|
|
|
|
- name: NGINX Template forgejo.service
|
|
|
|
ansible.builtin.template:
|
|
|
|
src: forgejo.conf
|
|
|
|
dest: /etc/nginx/sites-enabled/forgejo.conf
|
|
|
|
when: not stat_result.stat.exists
|
|
|
|
|
|
|
|
- name: NGINX Check that the forgejo.conf exists
|
|
|
|
stat:
|
|
|
|
path: "/etc/letsencrypt/live/{{ domain }}/fullchain.pem"
|
|
|
|
register: ssl_file_result
|
|
|
|
|
|
|
|
- name: Return motd to registered var
|
2023-08-05 18:08:06 +00:00
|
|
|
ansible.builtin.command: certbot -n --test-cert --nginx --agree-tos -m {{ sslmail }} -d {{ domain }}
|
2023-08-05 18:06:35 +00:00
|
|
|
when: not ssl_file_result.stat.exists
|
|
|
|
|
|
|
|
|
2023-08-05 17:33:14 +00:00
|
|
|
|
|
|
|
#Database
|
|
|
|
- name: Create a new database with name 'forgejo'
|
|
|
|
community.mysql.mysql_db:
|
|
|
|
name: forgejo
|
|
|
|
state: present
|
|
|
|
login_unix_socket: /run/mysqld/mysqld.sock
|
|
|
|
|
|
|
|
- name: Removes anonymous user account for localhost
|
|
|
|
community.mysql.mysql_user:
|
|
|
|
name: ''
|
|
|
|
host: localhost
|
|
|
|
state: absent
|
|
|
|
login_unix_socket: /run/mysqld/mysqld.sock
|
|
|
|
|
|
|
|
- name: Removes all anonymous user accounts
|
|
|
|
community.mysql.mysql_user:
|
|
|
|
name: ''
|
|
|
|
host_all: true
|
|
|
|
state: absent
|
2023-08-05 17:35:21 +00:00
|
|
|
login_unix_socket: /run/mysqld/mysqld.sock
|
|
|
|
|
2023-08-05 17:33:14 +00:00
|
|
|
|
|
|
|
- name: Create database user forgejo
|
|
|
|
community.mysql.mysql_user:
|
|
|
|
name: forgejo
|
|
|
|
password: "FBnA!wiEJ!W>y@!Tf3$aV&WLvPD628GM%9&JUtssr3hr"
|
|
|
|
priv: 'forgejo.*:ALL'
|
2023-08-05 17:35:21 +00:00
|
|
|
state: present
|
|
|
|
login_unix_socket: /run/mysqld/mysqld.sock
|
2023-08-05 17:46:41 +00:00
|
|
|
|
|
|
|
- name: Template forgejo.service
|
|
|
|
ansible.builtin.template:
|
|
|
|
src: forgejo.service
|
|
|
|
dest: /etc/systemd/system/forgejo.service
|