2022-05-27 04:02:45 +00:00
|
|
|
- name: Create Gitea directory
|
2023-05-04 03:42:55 +00:00
|
|
|
ansible.builtin.file:
|
2022-05-27 04:02:45 +00:00
|
|
|
path: "{{ gitea_root }}"
|
|
|
|
state: directory
|
2020-07-28 03:20:50 +00:00
|
|
|
|
2022-05-27 04:02:45 +00:00
|
|
|
- name: Create Gitea database
|
2023-05-04 03:42:55 +00:00
|
|
|
community.mysql.mysql_db:
|
2020-07-28 03:20:50 +00:00
|
|
|
name: "{{ gitea_dbname }}"
|
2022-08-12 01:04:07 +00:00
|
|
|
state: present
|
|
|
|
login_unix_socket: /var/run/mysqld/mysqld.sock
|
2020-07-28 03:20:50 +00:00
|
|
|
|
2022-05-27 04:02:45 +00:00
|
|
|
- name: Create Gitea database user
|
2023-05-04 03:42:55 +00:00
|
|
|
community.mysql.mysql_user:
|
2022-05-27 04:02:45 +00:00
|
|
|
name: "{{ gitea_dbuser }}"
|
|
|
|
password: "{{ gitea_dbpass }}"
|
2022-08-12 01:04:07 +00:00
|
|
|
host: '%'
|
|
|
|
state: present
|
|
|
|
priv: "{{ gitea_dbname }}.*:ALL"
|
|
|
|
login_unix_socket: /var/run/mysqld/mysqld.sock
|
2022-05-27 04:02:45 +00:00
|
|
|
|
2022-05-27 06:28:51 +00:00
|
|
|
- name: Create git user
|
2023-05-04 03:42:55 +00:00
|
|
|
ansible.builtin.user:
|
2022-05-27 06:28:51 +00:00
|
|
|
name: git
|
|
|
|
state: present
|
|
|
|
|
|
|
|
- name: Git user uid
|
2023-05-04 03:42:55 +00:00
|
|
|
ansible.builtin.getent:
|
2022-05-27 06:28:51 +00:00
|
|
|
database: passwd
|
|
|
|
key: git
|
|
|
|
|
|
|
|
- name: Git user gid
|
2023-05-04 03:42:55 +00:00
|
|
|
ansible.builtin.getent:
|
2022-05-27 06:28:51 +00:00
|
|
|
database: group
|
|
|
|
key: git
|
|
|
|
|
|
|
|
- name: Create git's .ssh directory
|
2023-05-04 03:42:55 +00:00
|
|
|
ansible.builtin.file:
|
2022-05-27 06:28:51 +00:00
|
|
|
path: /home/git/.ssh
|
|
|
|
state: directory
|
|
|
|
|
|
|
|
- name: Generate git's SSH keys
|
2023-05-04 03:42:55 +00:00
|
|
|
community.crypto.openssh_keypair:
|
2022-05-27 06:28:51 +00:00
|
|
|
path: /home/git/.ssh/id_rsa
|
|
|
|
|
|
|
|
- name: Find git's public SSH key
|
2023-05-04 03:42:55 +00:00
|
|
|
ansible.builtin.slurp:
|
2022-05-27 06:28:51 +00:00
|
|
|
src: /home/git/.ssh/id_rsa.pub
|
|
|
|
register: git_rsapub
|
|
|
|
|
2022-05-28 03:14:06 +00:00
|
|
|
- name: Get stats on git's authorized_keys file
|
2023-05-04 03:42:55 +00:00
|
|
|
ansible.builtin.stat:
|
2022-05-28 03:14:06 +00:00
|
|
|
path: /home/git/.ssh/authorized_keys
|
|
|
|
register: git_authkeys
|
|
|
|
|
2022-05-27 06:28:51 +00:00
|
|
|
- name: Create git's authorized_keys file
|
2023-05-04 03:42:55 +00:00
|
|
|
ansible.builtin.file:
|
2022-05-27 06:28:51 +00:00
|
|
|
path: /home/git/.ssh/authorized_keys
|
|
|
|
state: touch
|
2022-05-28 03:14:06 +00:00
|
|
|
when: not git_authkeys.stat.exists
|
2022-05-27 06:28:51 +00:00
|
|
|
|
|
|
|
- name: Add git's public SSH key to authorized_keys
|
2023-05-04 03:42:55 +00:00
|
|
|
ansible.builtin.lineinfile:
|
2022-05-27 06:28:51 +00:00
|
|
|
path: /home/git/.ssh/authorized_keys
|
2022-05-28 03:14:06 +00:00
|
|
|
regex: "^ssh-rsa"
|
2022-05-27 06:28:51 +00:00
|
|
|
line: "{{ git_rsapub['content'] | b64decode }}"
|
|
|
|
|
|
|
|
- name: Create Gitea host script for SSH
|
2023-05-04 03:42:55 +00:00
|
|
|
ansible.builtin.template:
|
2022-05-27 06:28:51 +00:00
|
|
|
src: gitea.sh.j2
|
|
|
|
dest: /usr/local/bin/gitea
|
|
|
|
mode: 0755
|
|
|
|
|
2022-05-27 04:02:45 +00:00
|
|
|
- name: Install Gitea's docker-compose file
|
2023-05-04 03:42:55 +00:00
|
|
|
ansible.builtin.template:
|
2022-05-27 04:02:45 +00:00
|
|
|
src: docker-compose.yml.j2
|
|
|
|
dest: "{{ gitea_root }}/docker-compose.yml"
|
2022-05-28 04:18:15 +00:00
|
|
|
notify: restart_gitea
|
2022-05-27 04:02:45 +00:00
|
|
|
|
|
|
|
- name: Install Gitea's docker-compose variables
|
2023-05-04 03:42:55 +00:00
|
|
|
ansible.builtin.template:
|
2022-05-27 04:02:45 +00:00
|
|
|
src: compose-env.j2
|
|
|
|
dest: "{{ gitea_root }}/.env"
|
2022-05-28 04:18:15 +00:00
|
|
|
notify: restart_gitea
|
2022-05-22 04:19:56 +00:00
|
|
|
|
2022-06-07 04:25:47 +00:00
|
|
|
- name: Create Gitea's logging directory
|
2023-05-04 03:42:55 +00:00
|
|
|
ansible.builtin.file:
|
2022-06-07 04:25:47 +00:00
|
|
|
name: /var/log/gitea
|
|
|
|
state: directory
|
|
|
|
|
|
|
|
- name: Create Gitea's initial log file
|
2023-05-04 03:42:55 +00:00
|
|
|
ansible.builtin.file:
|
2022-06-07 04:25:47 +00:00
|
|
|
name: /var/log/gitea/gitea.log
|
|
|
|
state: touch
|
|
|
|
|
2022-05-28 06:31:41 +00:00
|
|
|
- name: Install Gitea's Fail2ban filter
|
2023-05-04 03:42:55 +00:00
|
|
|
ansible.builtin.template:
|
2022-05-28 06:31:41 +00:00
|
|
|
src: fail2ban-filter.conf.j2
|
|
|
|
dest: /etc/fail2ban/filter.d/gitea.conf
|
|
|
|
notify: restart_fail2ban
|
|
|
|
|
|
|
|
- name: Install Gitea's Fail2ban jail
|
2023-05-04 03:42:55 +00:00
|
|
|
ansible.builtin.template:
|
2022-05-28 06:31:41 +00:00
|
|
|
src: fail2ban-jail.conf.j2
|
|
|
|
dest: /etc/fail2ban/jail.d/gitea.conf
|
|
|
|
notify: restart_fail2ban
|
|
|
|
|
2022-05-27 04:02:45 +00:00
|
|
|
- name: Start and enable Gitea service
|
2023-05-04 03:42:55 +00:00
|
|
|
ansible.builtin.service:
|
2022-05-27 04:02:45 +00:00
|
|
|
name: "{{ docker_compose_service }}@{{ gitea_name }}"
|
2022-05-22 04:19:56 +00:00
|
|
|
state: started
|
2022-05-27 04:02:45 +00:00
|
|
|
enabled: true
|