From 89adafdffc0a6313dca3c99cd328a14f34cd0f52 Mon Sep 17 00:00:00 2001 From: rick Date: Wed, 18 May 2022 20:18:30 +0200 Subject: [PATCH] use role for cgit installation --- main.yml | 57 ++++++++ roles/installations/handlers/main.yml | 5 + roles/installations/tasks/cgit.yml | 122 ++++++++++++++++++ roles/installations/tasks/main.yml | 20 +++ .../installations/templates/cgit-nginx | 0 .../installations/templates/config-cgit.conf | 0 6 files changed, 204 insertions(+) create mode 100644 main.yml create mode 100644 roles/installations/handlers/main.yml create mode 100644 roles/installations/tasks/cgit.yml create mode 100644 roles/installations/tasks/main.yml rename cgit-nginx => roles/installations/templates/cgit-nginx (100%) rename config-cgit.conf => roles/installations/templates/config-cgit.conf (100%) diff --git a/main.yml b/main.yml new file mode 100644 index 0000000..eda24be --- /dev/null +++ b/main.yml @@ -0,0 +1,57 @@ +################################################################################ +# installation automatique de mon infra +# +# Copyright (C) 2022 rick G. +# +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see . +################################################################################ + +--- +- name: cgit + hosts: ubuntu + become: true + + vars_files: + - vars/sites.yml + vars: + git_user: "git" + home_user: "/home/{{ git_user }}" + path_tmp_cgit: "{{ home_user }}/tmp" + path_cgit: "{{ home_user }}/cgit" + path_gitolite: "{{ home_user }}/gitolite" + + pre_tasks: + - name: update de la machine + apt: + update_cache: true + upgrade: yes + + - name: installation des paquets nécessaires + apt: + name: + - make + - gcc + - nginx + - certbot + - git + - sudo + + roles: + - installations + + post_tasks: + - name: démarrage par défaut de nginx + ansible.builtin.service: + name: nginx + enabled: yes + state: restarted diff --git a/roles/installations/handlers/main.yml b/roles/installations/handlers/main.yml new file mode 100644 index 0000000..e14a6ed --- /dev/null +++ b/roles/installations/handlers/main.yml @@ -0,0 +1,5 @@ +--- +- name: restart fcgiwrap + service: + name: fcgiwrap + state: restarted diff --git a/roles/installations/tasks/cgit.yml b/roles/installations/tasks/cgit.yml new file mode 100644 index 0000000..3ef3546 --- /dev/null +++ b/roles/installations/tasks/cgit.yml @@ -0,0 +1,122 @@ +################################################################################ +# installation de cgit et configuration de nginx et gitolite +# +# Copyright (C) 2022 rick G. +# +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see . +################################################################################ + +--- +- name: update de la machine + apt: + update_cache: true + upgrade: yes + +- name: installation des paquets nécessaires + apt: + name: + - libzip-dev + - libssl-dev + - zlib1g-dev + - python3-certbot-nginx + - fcgiwrap + - python3-zipp + +- name: création utilisateur cgit + ansible.builtin.user: + name: "{{ git_user }}" + shell: "/bin/bash" + state: present + #groups: "www" + +- name: clonage de cgit + ansible.builtin.git: + dest: "{{ path_tmp_cgit }}" + repo: "https://git.zx2c4.com/cgit" + single_branch: yes + +- name: configuration de cgit + template: + src: "config-cgit.conf" + dest: "{{ path_tmp_cgit }}/cgit.conf" + mode: 0644 + +- name: compilation de cgit + community.general.make: + chdir: "{{ path_tmp_cgit }}" + +- name: installation de cgit + community.general.make: + chdir: "{{ path_tmp_cgit }}" + target: install + +- name: configuration de Nginx + template: + src: "cgit-nginx" + dest: "/etc/nginx/sites-available/cgit.conf" + mode: 0644 + +- name: lien symbolique pour le site cgit + file: + src: /etc/nginx/sites-available/cgit.conf + dest: /etc/nginx/sites-enabled/cgit.conf + state: link + +- name: clonage de gitolite + ansible.builtin.git: + dest: "{{ path_gitolite }}" + repo: "https://github.com/sitaramc/gitolite" + single_branch: yes + +- name: configuration des droits des dossiers + file: + path: "{{ item }}" + owner: "{{ git_user }}" + group: "{{ git_user }}" + recurse: yes + state: directory + loop: + - "{{ home_user }}/bin" + - "{{ home_user }}/etc" + - "{{ path_cgit }}" + - "{{ path_gitolite }}" + +- name: installation de gitolite + command: + cmd: "{{ path_gitolite }}/install -to {{ home_user }}/bin" + +- name: création de la liste de projets + file: + path: "{{ home_user }}/projects.list" + mode: 0705 + state: touch + owner: "{{ git_user }}" + group: "{{ git_user }}" + +- name: configuration des droits du dossier repositories + file: + path: "{{ home_user }}/repositories" + mode: 0705 + state: directory + recurse: yes + owner: "{{ git_user }}" + group: "{{ git_user }}" + +- name: démarrage par défaut de fcgiwrap + ansible.builtin.service: + name: fcgiwrap + enabled: yes + notify: + - restart fcgiwrap + + # TODO fin de configuration de gitolite (premier utilisateur) diff --git a/roles/installations/tasks/main.yml b/roles/installations/tasks/main.yml new file mode 100644 index 0000000..3279fef --- /dev/null +++ b/roles/installations/tasks/main.yml @@ -0,0 +1,20 @@ +################################################################################ +# installation et configuration des services de l'infra +# +# Copyright (C) 2022 rick G. +# +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see . +################################################################################ + +--- +- include_tasks: cgit.yml diff --git a/cgit-nginx b/roles/installations/templates/cgit-nginx similarity index 100% rename from cgit-nginx rename to roles/installations/templates/cgit-nginx diff --git a/config-cgit.conf b/roles/installations/templates/config-cgit.conf similarity index 100% rename from config-cgit.conf rename to roles/installations/templates/config-cgit.conf