new role gitea_repo
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
---
|
||||
- name: Setup Gitea
|
||||
hosts: hard_disk
|
||||
hosts: gitea:&hard_disk
|
||||
gather_facts: yes
|
||||
become: false
|
||||
run_once: true
|
||||
|
||||
vars:
|
||||
applications: "{{ hard_disk__applications }}"
|
||||
@@ -37,4 +38,117 @@
|
||||
postgres_user: |-
|
||||
{{ applications.gitea.dockercompose.services.gitea.environment.GITEA__database__USER }}
|
||||
postgres_password: |-
|
||||
{{ applications.gitea.dockercompose.services.gitea.environment.GITEA__database__PASSWD }}
|
||||
{{ applications.gitea.dockercompose.services.gitea.environment.GITEA__database__PASSWD }}
|
||||
|
||||
- name: Create admin user
|
||||
block:
|
||||
- name: Use default user identity
|
||||
when: gitea_user is undefined or gitea_user.name is undefined or gitea_user.email is undefined
|
||||
ansible.builtin.set_fact:
|
||||
gitea_base_url: http://{{ inventory_hostname }}:3000
|
||||
gitea_user:
|
||||
name: arcodange
|
||||
email: [email protected]
|
||||
avatar_img_path: '{{ inventory_dir }}/../img/arcodange.jpeg'
|
||||
|
||||
- name: List admin users
|
||||
ansible.builtin.shell:
|
||||
cmd: >-
|
||||
docker exec -u git {{ applications.gitea.dockercompose.services.gitea.container_name }}
|
||||
gitea admin user list --admin
|
||||
| awk '{print $2}'
|
||||
| tail -n +2
|
||||
# tail -n +2 skips the 2-1 ("N-1" with N=2) first lines (so the first line returned by the command)
|
||||
register:
|
||||
gitea_admin_users_list_cmd
|
||||
|
||||
- name: Create admin user
|
||||
when: gitea_user.name not in gitea_admin_users_list_cmd.stdout.split()
|
||||
ansible.builtin.command: >-
|
||||
docker exec -u git {{ applications.gitea.dockercompose.services.gitea.container_name }}
|
||||
gitea admin user create
|
||||
--username {{ gitea_user.name }}
|
||||
--email {{ gitea_user.name }}
|
||||
--random-password
|
||||
|
||||
- name: Generate Gitea Token
|
||||
include_role:
|
||||
name: arcodange.factory.gitea_token
|
||||
|
||||
- name: Lecture bases64 de l'avatar de l'admin
|
||||
local_action:
|
||||
module: slurp
|
||||
path: '{{ gitea_user.avatar_img_path | realpath }}'
|
||||
register:
|
||||
gitea_user_avatar_img
|
||||
|
||||
- name: Upload l'avatar de l'admin
|
||||
uri:
|
||||
url: "{{ gitea_base_url }}/api/v1/user/avatar"
|
||||
method: POST
|
||||
headers:
|
||||
Content-Type: application/json
|
||||
Accept: application/json
|
||||
Authorization: "token {{ gitea_api_token }}"
|
||||
body_format: json
|
||||
body:
|
||||
image: "{{ gitea_user_avatar_img['content'] }}"
|
||||
status_code: 204
|
||||
|
||||
- set_fact:
|
||||
gitea_org_name: arcodange-org
|
||||
gitea_org_full_name: Arcodange
|
||||
gitea_org_description: '🏹💻🪽'
|
||||
gitea_org_website: https://www.arcodange.duckdns.org
|
||||
gitea_org_location: Paris
|
||||
gitea_org_avatar_img_path: '{{ inventory_dir }}/../img/arcodange-org.jpeg'
|
||||
|
||||
- name: Vérifier si l'organisation existe dans Gitea
|
||||
uri:
|
||||
url: "{{ gitea_base_url }}/api/v1/orgs/{{ gitea_org_name }}"
|
||||
method: GET
|
||||
headers:
|
||||
Authorization: "token {{ gitea_api_token }}"
|
||||
status_code: 200
|
||||
register: gitea_org_check
|
||||
ignore_errors: yes
|
||||
|
||||
- when: gitea_org_check.status != 200
|
||||
block:
|
||||
- name: Créer l'organisation dans Gitea quand elle n'existe pas
|
||||
uri:
|
||||
url: "{{ gitea_base_url }}/api/v1/orgs"
|
||||
method: POST
|
||||
headers:
|
||||
Content-Type: application/json
|
||||
Accept: application/json
|
||||
Authorization: "token {{ gitea_api_token }}"
|
||||
body_format: json
|
||||
body:
|
||||
username: "{{ gitea_org_name }}"
|
||||
full_name: "{{ gitea_org_full_name }}"
|
||||
description: "{{ gitea_org_description }}"
|
||||
visibility: private
|
||||
website: "{{ gitea_org_website }}"
|
||||
location: "{{ gitea_org_location }}"
|
||||
status_code: 201
|
||||
|
||||
- name: Lecture bases64 de l'avatar de l'organization
|
||||
local_action:
|
||||
module: slurp
|
||||
path: '{{ gitea_org_avatar_img_path | realpath }}'
|
||||
register:
|
||||
gitea_org_avatar_img
|
||||
|
||||
- name: Upload l'avatar de l'organization
|
||||
uri:
|
||||
url: "{{ gitea_base_url }}/api/v1/orgs/{{ gitea_org_name }}/avatar"
|
||||
method: POST
|
||||
headers:
|
||||
Content-Type: application/json
|
||||
Accept: application/json
|
||||
Authorization: "token {{ gitea_api_token }}"
|
||||
body_format: json
|
||||
body:
|
||||
image: "{{ gitea_org_avatar_img['content'] }}"
|
||||
status_code: 204
|
||||
Reference in New Issue
Block a user