ansible/roles/gitea/tasks/main.yml

136 lines
3.9 KiB
YAML
Raw Normal View History

2020-04-30 05:06:49 -05:00
#!/usr/bin/ansible-playbook
# vim:ft=ansible:
---
- name: Set up Gitea
block:
- name: Set up MySQL
block:
- name: Create DB
mysql_db:
name: gitea
login_user: root
2020-08-02 19:36:46 -05:00
login_password: "{{ mysql.root_password }}"
2020-04-30 05:06:49 -05:00
state: present
notify: gitea add default user
2020-04-30 05:06:49 -05:00
- name: Create user
mysql_user:
name: gitea
host: localhost
password: "{{ gitea_mysql_password }}"
priv: "gitea.*:ALL,GRANT"
login_user: root
2020-08-02 19:36:46 -05:00
login_password: "{{ mysql.root_password }}"
2020-04-30 05:06:49 -05:00
- name: Set up Apache
block:
2020-04-30 06:21:25 -05:00
- name: Enable modules
command:
cmd: a2enmod "{{ item }}"
creates: "/etc/apache2/mods-enabled/{{ item }}.load"
loop:
- proxy
- proxy_http
notify: restart apache
2020-04-30 05:06:49 -05:00
- name: Template out vhost
template:
src: "apache2-vhost-ssl.conf"
dest: "/etc/apache2/sites-available/{{ gitea_url }}.conf"
notify: restart apache
- name: Create webroot
file:
state: directory
path: "{{ gitea_webroot }}"
2020-04-30 05:06:49 -05:00
- name: Enable site
command:
cmd: "a2ensite {{ gitea_url }}.conf"
creates: "/etc/apache2/sites-enabled/{{ gitea_url }}.conf"
notify: restart apache
- name: Generate certificate
include_role:
name: https
vars:
website_url: "{{ gitea_url }}"
- name: Install git
apt:
name: git
- name: Install Gitea
get_url:
2020-06-01 01:49:04 -05:00
url: "https://dl.gitea.io/gitea/1.12/gitea-1.12-linux-amd64"
2020-04-30 05:06:49 -05:00
dest: "/usr/local/bin/gitea"
mode: "0755"
2020-06-01 01:47:25 -05:00
notify: restart gitea
2020-04-30 05:06:49 -05:00
- name: Create Gitea user
user:
name: git
password: "!"
home: "/home/git"
2020-04-30 08:10:02 -05:00
shell: "/bin/bash"
2020-04-30 05:06:49 -05:00
- name: Create directory structure
file:
state: directory
owner: git
group: git
mode: "0750"
path: "/var/lib/{{ item }}"
loop:
- "gitea"
- "gitea/custom"
- "gitea/data"
- "gitea/log"
- name: Create config directory
file:
state: directory
recurse: yes
mode: "0750"
owner: "root"
group: "git"
path: "/etc/gitea"
2020-05-01 14:01:53 -05:00
- name: Create repositories directory
file:
state: directory
mode: "0700"
owner: git
group: git
path: "{{ gitea_root_directory }}"
- name: Check for config
stat: path="/etc/gitea/app.ini"
register: p
- name: Deploy config
block:
- name: Generate INTERNAL_TOKEN
command: /usr/local/bin/gitea generate secret INTERNAL_TOKEN
register: gitea_internal_token
- name: Generate SECRET_KEY
command: /usr/local/bin/gitea generate secret SECRET_KEY
register: gitea_secret_key
- name: Generate JWT_SECRET
command: /usr/local/bin/gitea generate secret JWT_SECRET
register: gitea_jwt_secret
- name: Generate LFS_JWT_SECRET
command: /usr/local/bin/gitea generate secret LFS_JWT_SECRET
register: gitea_lfs_jwt_secret
- name: Template out app.ini
template:
src: "app.ini"
dest: "/etc/gitea/app.ini"
mode: "0640"
owner: "root"
group: "git"
when: not p.stat.exists
2020-04-30 05:25:35 -05:00
- name: Template out service
template:
src: "gitea.service"
dest: "/etc/systemd/system/gitea.service"
2020-04-30 06:45:04 -05:00
notify: restart gitea
2020-04-30 05:25:35 -05:00
- name: Start and enable service
systemd:
daemon_reload: yes
2020-04-30 05:25:35 -05:00
name: "gitea.service"
enabled: yes
state: "started"
2020-05-03 06:37:58 -05:00
- name: Template out backup module
template:
src: "backup.sh"
dest: "/opt/backups/modules/{{ gitea_url }}.sh"
2020-05-03 06:37:58 -05:00
mode: "0600"
2020-04-30 05:06:49 -05:00
become: yes