From eea8a67515d7bef5c585bdcb246258117a5fe8e7 Mon Sep 17 00:00:00 2001 From: "pulsar89.5" Date: Thu, 6 Jul 2023 17:56:19 +0200 Subject: [PATCH] =?UTF-8?q?[INFO]=20Cr=C3=A9er=20le=20d=C3=A9p=C3=B4t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 41 ++++++++++++++++++++++++-- defaults/main.yml | 10 +++++++ handlers/main.yml | 10 +++++++ meta/main.yml | 15 ++++++++-- tasks/main.yml | 57 +++++++++++++++++++++++++++++++++++++ templates/gitea.service.j2 | 24 ++++++++++++++++ templates/logrotate.conf.j2 | 11 +++++++ 7 files changed, 164 insertions(+), 4 deletions(-) create mode 100755 defaults/main.yml create mode 100755 handlers/main.yml create mode 100755 tasks/main.yml create mode 100755 templates/gitea.service.j2 create mode 100755 templates/logrotate.conf.j2 diff --git a/README.md b/README.md index 3edfbf7..88053cc 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,40 @@ -# role_modele +# role_gitea -Modèle \ No newline at end of file +Rôle de déploiement de gitea. + +## Fonctionnement + +Ce rôle nécessite la création d'un utilisateur dédié. La création de cet utilisateur passe par un rôle défini dans `meta/main.yml`.
+La configuration de logrotate est poussée en écrasant le fichier `/etc/logrotate.d/gitea`. + +## Variables + +### gitea_version_file + +URL permettant de déterminer quelle est la dernière version. + +Valeur par défaut: `https://dl.gitea.io/gitea/version.json` + +### gitea_version + +Afin d'installer une version spécifique, définir cette variable. + +Valeur par défaut: aucune + +### gitea_architecture + +Architecture de la machine où est effectué le déploiement. + +Valeur par défaut: `arm64` + +### gitea_install_path + +Emplacement d'installation du binaire. + +Valeur par défaut: `/opt/gitea` + +### gitea_logs_path + +Emplacement où seront stockés les journaux. + +Valeur par défaut: `/var/log/gitea` diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100755 index 0000000..3a5d2f2 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,10 @@ +--- +# vars file for gitea + +gitea_version_file: https://dl.gitea.io/gitea/version.json + +gitea_version: "" +gitea_architecture: arm64 + +gitea_install_path: /opt/gitea +gitea_logs_path: /var/log/gitea diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100755 index 0000000..b93d867 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,10 @@ +--- +# handlers file for gitea + +- name: Redémarrer gitea.service + ansible.builtin.systemd: + enabled: true + daemon_reload: true + state: restarted + name: gitea.service + become: true diff --git a/meta/main.yml b/meta/main.yml index c58bebf..17c295d 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,7 +1,7 @@ galaxy_info: namespace: ykn author: pulsar89.5 - description: Rôle modèle + description: Rôle de déploiement de gitea license: GPL-3.0-or-later @@ -12,4 +12,15 @@ galaxy_info: versions: - all -dependencies: [] +dependencies: + - role: users + vars: + users_role_gitea: + - name: gitea + comment: Dedicated GiTea user + update_password: on_create + password_lock: true + shell: /bin/bash + extras: + authorized_keys: + - command="/opt/gitea/gitea.bin --config='/opt/gitea/custom/conf/app.ini' serv key-1",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100755 index 0000000..e655ca2 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,57 @@ +--- +# tasks file for gitea + +- name: Créer les dossiers + ansible.builtin.file: + owner: gitea + group: gitea + mode: u=rwx,g=rx,o=rx + state: directory + path: "{{ item }}" + become: true + loop: + - "{{ gitea_install_path }}" + - "{{ gitea_logs_path }}" + +- name: Récupérer le contenu du fichier de version + ansible.builtin.uri: + url: "{{ gitea_version_file }}" + return_content: true + follow_redirects: all + when: not gitea_version | length > 0 + register: version_file + +- name: Extraire la dernière version + ansible.builtin.set_fact: + gitea_version: "{{ (version_file.content | from_json).latest.version }}" + when: not gitea_version | length > 0 + +- name: Télécharger le binaire + ansible.builtin.get_url: + owner: gitea + group: gitea + mode: u=rwx,g=,o= + checksum: "sha256:https://dl.gitea.io/gitea/{{ gitea_version }}/gitea-{{ gitea_version }}-linux-{{ gitea_architecture }}.sha256" + url: https://dl.gitea.io/gitea/{{ gitea_version }}/gitea-{{ gitea_version }}-linux-{{ gitea_architecture }} + dest: "{{ gitea_install_path }}/gitea.bin" + become: true + notify: Redémarrer gitea.service + +- name: Déployer le service + become: true + ansible.builtin.template: + owner: root + group: root + mode: u=rw,g=r,o=r + src: gitea.service.j2 + dest: /etc/systemd/system/gitea.service + notify: Redémarrer gitea.service + +- name: Déployer la configuration logrotate + become: true + ansible.builtin.template: + owner: root + group: root + mode: u=rw,g=r,o=r + src: logrotate.conf.j2 + dest: /etc/logrotate.d/gitea diff --git a/templates/gitea.service.j2 b/templates/gitea.service.j2 new file mode 100755 index 0000000..bc5d9d8 --- /dev/null +++ b/templates/gitea.service.j2 @@ -0,0 +1,24 @@ +# {{ ansible_managed }} + +[Unit] +Description=Gitea (Git with a cup of tea) +After=syslog.target +After=network.target + +[Service] +RestartSec=2s +Type=simple + +User=gitea +Group=gitea + +WorkingDirectory={{ gitea_install_path }} +ExecStart={{ gitea_install_path }}/gitea.bin web +Restart=always + +Environment="USER=gitea" +Environment="HOME={{ gitea_install_path }}" +Environment="GITEA_WORK_DIR={{ gitea_install_path }}" + +[Install] +WantedBy=multi-user.target diff --git a/templates/logrotate.conf.j2 b/templates/logrotate.conf.j2 new file mode 100755 index 0000000..88f2119 --- /dev/null +++ b/templates/logrotate.conf.j2 @@ -0,0 +1,11 @@ +# {{ ansible_managed }} + +{{ gitea_logs_path }}/*.log { + daily + missingok + rotate 14 + compress + delaycompress + notifempty + create 0640 gitea gitea +} -- 2.39.5