Refactor gitea role to install the latest version

This commit is contained in:
Ryan Cavicchioni 2020-10-11 21:40:15 -05:00
parent 008779232b
commit 294c1263f6
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D
9 changed files with 159 additions and 84 deletions

View File

@ -1,10 +1,20 @@
--- ---
gitea_go_arch_map:
i386: '386'
x86_64: 'amd64'
gitea_checksums:
x86_64: sha256:3faa3e97a621c3b9ecba7917fd870c07c3c6c88c8cc7c29ecbf2c7b9802d91b0
gitea_go_arch: "{{ gitea_go_arch_map[ansible_architecture] | default('amd64') }}"
gitea_checksum: "{{ gitea_checksums[ansible_architecture] | default('amd64') }}"
gitea_service_name: gitea.service gitea_service_name: gitea.service
gitea_service_state: started gitea_service_state: started
gitea_service_enabled: yes gitea_service_enabled: yes
gitea_version: 1.12.2 gitea_version: 1.12.2
gitea_url: "https://dl.gitea.io/gitea/{{ gitea_version }}/gitea-{{ gitea_version }}-linux-{{ gitea_arch }}" gitea_url: "https://dl.gitea.io/gitea/{{ gitea_version }}/gitea-{{ gitea_version }}-linux-{{ gitea_go_arch }}"
gitea_bin_path: /usr/local/bin gitea_bin_path: /usr/local/bin
gitea_var_path: /var/lib/gitea gitea_var_path: /var/lib/gitea
gitea_log_path: /var/log/gitea gitea_log_path: /var/log/gitea

View File

@ -0,0 +1,11 @@
---
- name: configure
template:
src: app.ini.j2
dest: "{{ gitea_config_path }}"
owner: root
group: "{{ gitea_group }}"
mode: 0640
notify:
- restart gitea

View File

View File

@ -0,0 +1,71 @@
---
- name: "download gitea {{ gitea_version }}"
get_url:
url: "{{ gitea_url }}"
checksum: "{{ gitea_checksum }}"
dest: "{{ gitea_path }}"
owner: root
group: root
mode: 0755
notify:
- restart gitea
retries: 3
- name: create group
user:
name: "{{ gitea_group }}"
system: yes
- name: create user and group
user:
name: "{{ gitea_user }}"
group: "{{ gitea_group }}"
shell: "{{ gitea_shell }}"
comment: "{{ gitea_gecos }}"
system: yes
password: "{{ gitea_password }}"
home: "{{ gitea_home_path }}"
- name: "create {{ gitea_etc_path }}"
file:
path: "{{ gitea_etc_path }}"
owner: root
group: "{{ gitea_group }}"
mode: 0750
state: directory
- name: "create {{ gitea_var_path }} tree"
file:
path: "{{ item }}"
owner: "{{ gitea_user }}"
group: "{{ gitea_group }}"
mode: 0750
state: directory
with_items: "{{ gitea_var_tree }}"
- name: "create {{ gitea_log_path }} path"
file:
path: "{{ gitea_log_path }}"
owner: "{{ gitea_user }}"
group: "{{ gitea_group }}"
mode: 0755
state: directory
- name: configure systemd unit
template:
src: gitea.service.j2
dest: "{{ gitea_systemd_unit_path }}"
owner: root
group: root
mode: 0644
notify:
- gitea daemon-reload
- restart gitea
when: ansible_service_mgr == 'systemd'
- name: manage service
service:
name: "{{ gitea_service_name }}"
state: "{{ gitea_service_state }}"
enabled: "{{ gitea_service_enabled }}"

View File

@ -1,93 +1,35 @@
--- ---
- name: gather architecture specific variables - name: gather os specific variables
include_vars: "{{ lookup('first_found', possible_files) }}" include_vars: "{{ lookup('first_found', possible_files) }}"
vars: vars:
possible_files: possible_files:
files: files:
- "{{ ansible_userspace_architecture }}.yaml" - "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yaml"
- "{{ ansible_distribution }}.yaml"
- "{{ ansible_os_family }}.yaml"
- "default.yaml" - "default.yaml"
paths: paths:
- vars - vars
- name: "download gitea {{ gitea_version }}" - name: include os specific tasks
get_url: include_tasks: "{{ lookup('first_found', possible_files) }}"
url: "{{ gitea_url }}" vars:
checksum: "{{ gitea_checksum }}" possible_files:
dest: "{{ gitea_path }}" files:
owner: root - "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yaml"
group: root - "{{ ansible_distribution }}.yaml"
mode: 0755 - "{{ ansible_os_family }}.yaml"
notify: - "default.yaml"
- restart gitea paths:
- tasks
- name: create group - include: pre.yaml
user:
name: "{{ gitea_group }}"
system: yes
- name: create user and group - include: install.yaml
user: when:
name: "{{ gitea_user }}" - gitea_version is version(gitea_local_version, '>')
group: "{{ gitea_group }}"
shell: "{{ gitea_shell }}"
comment: "{{ gitea_gecos }}"
system: yes
password: "{{ gitea_password }}"
home: "{{ gitea_home_path }}"
- name: "create {{ gitea_etc_path }}" - include: configure.yaml
file:
path: "{{ gitea_etc_path }}"
owner: root
group: "{{ gitea_group }}"
mode: 0750
state: directory
- name: configure - include: nginx.yaml
template: when: '"nginx" in ansible_play_role_names'
src: app.ini.j2
dest: "{{ gitea_config_path }}"
owner: root
group: "{{ gitea_group }}"
mode: 0640
notify:
- restart gitea
- name: "create {{ gitea_var_path }} tree"
file:
path: "{{ item }}"
owner: "{{ gitea_user }}"
group: "{{ gitea_group }}"
mode: 0750
state: directory
with_items: "{{ gitea_var_tree }}"
- name: "create {{ gitea_log_path }} path"
file:
path: "{{ gitea_log_path }}"
owner: "{{ gitea_user }}"
group: "{{ gitea_group }}"
mode: 0755
state: directory
- name: configure systemd unit
template:
src: gitea.service.j2
dest: "{{ gitea_systemd_unit_path }}"
owner: root
group: root
mode: 0644
notify:
- gitea daemon-reload
- restart gitea
when: ansible_service_mgr == 'systemd'
- name: manage service
service:
name: "{{ gitea_service_name }}"
state: "{{ gitea_service_state }}"
enabled: "{{ gitea_service_enabled }}"
- name: configure nginx
include: nginx.yaml
when: "'nginx' in ansible_play_role_names"

View File

@ -1,3 +1,4 @@
---
- name: configure nginx - name: configure nginx
template: template:
src: nginx.conf.j2 src: nginx.conf.j2

View File

@ -0,0 +1,43 @@
---
- block:
- name: determine if installed
stat:
path: "{{ gitea_bin_path }}/gitea"
register: st
- name: determine latest version
uri:
url: https://api.github.com/repos/go-gitea/gitea/releases/latest
return_content: true
body_format: json
register: _latest_version
until: _latest_version.status == 200
retries: 3
- name: determine installed version
command: "{{ gitea_bin_path }}/gitea --version"
register: _installed_version_string
changed_when: false
when: st.stat.exists
- name: set gitea facts
set_fact:
gitea_local_version: "{{ _installed_version_string.stdout | regex_search('^Gitea version ([\\d.]+)', '\\1') | first }}"
when: st.stat.exists
- name: set gitea facts
set_fact:
gitea_local_version: "0"
when: not st.stat.exists
- name: set gitea facts
set_fact:
gitea_version: "{{ _latest_version.json['tag_name'] | regex_replace('^v', '') }}"
- name: download checksums
set_fact:
checksum_string: "{{ lookup('url', gitea_url + '.sha256') }}"
- name: set gitea checksum
set_fact:
gitea_checksum: "sha256:{{ checksum_string.split(' ') | first }}"

View File

View File

@ -1,3 +0,0 @@
---
gitea_arch: amd64
gitea_checksum: sha256:3faa3e97a621c3b9ecba7917fd870c07c3c6c88c8cc7c29ecbf2c7b9802d91b0