commit 0a8fdc88f0af4074d694cfe703006fd03c02491a Author: nono Date: Wed Dec 21 23:12:47 2022 +0100 init role diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..22f1903 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,34 @@ +--- +gitea_version: 1.17.3 +gitea_arch: "amd64" +gitea_user: "gitea" +gitea_dir: "/opt/gitea" +gitea_dir_etc: "{{gitea_dir}}/etc" +gitea_dir_bin: "{{gitea_dir}}/bin" +gitea_dir_var: "{{gitea_dir}}/var" + + +gitea_domain: "git.corp.local" +gitea_http_port: 3000 +gitea_local_url: "http://localhost:3000" +gitea_external_url: "https://{{gitea_domain}}" + +gitea_ssh_disable: "FALSE" +gitea_ssh_port: 2222 +gitea_ssh_start: "TRUE" +gitea_ssh_builtin_user: "git" + +gitea_lfs_start: "TRUE" + +# gitea_db_type: "mysql" +gitea_db_type: "sqlite3" +gitea_db_host: "localhost:3306" +gitea_db_name: "gitea" +gitea_db_user: "gitea" +gitea_db_passwd: "mypassword" +gitea_db_ssl_mode: "disable" +gitea_db_path: "{{gitea_dir_var}}/data/gitea.db" + +gitea_admin_user: "myadmin" +gitea_admin_email: "{{gitea_admin_user}}@{{gitea_domain}}" +gitea_admin_password: "mypassword" \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..89d8f40 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,87 @@ +- name: Install prerequisites + ansible.builtin.package: + name: git + state: present + update_cache : true + +- name: Create gitea user + ansible.builtin.user: + name: "{{gitea_user}}" + shell: /bin/bash + create_home: no + home: '{{gitea_dir}}' + +- name: create gitea dir + file: + path: '{{gitea_dir}}' + state: directory + owner: "{{gitea_user}}" + group: "{{gitea_user}}" + mode: 0755 + +- name: create gitea bin dir + file: + path: '{{gitea_dir_bin}}' + state: directory + owner: "{{gitea_user}}" + group: "{{gitea_user}}" + mode: 0755 + +- name: create gitea etc dir + file: + path: '{{gitea_dir_etc}}' + state: directory + owner: "{{gitea_user}}" + group: "{{gitea_user}}" + mode: 0755 + +- name: create gitea var dir + file: + path: '{{gitea_dir_var}}' + state: directory + owner: "{{gitea_user}}" + group: "{{gitea_user}}" + mode: 0755 + +- name: Check if gitea binarie is already installed + stat: + path: '{{gitea_dir_bin}}/gitea' + register: gitea_exist + +- name: Download statically linked cfssl binary + get_url: + url: https://dl.gitea.io/gitea/{{gitea_version}}/gitea-{{gitea_version}}-linux-{{gitea_arch}} + dest: '{{gitea_dir_bin}}/gitea' + mode: 0755 + when: gitea_exist.stat.exists == false + +- name: creating gitea config file + template: + src: app.ini.j2 + dest: '{{gitea_dir_etc}}/app.ini' + owner: "{{gitea_user}}" + group: "{{gitea_user}}" + mode: 0700 + +- name: Création du fichier de service /lib/systemd/system/gitea.service + ansible.builtin.template: + src: gitea.service.j2 + dest: /lib/systemd/system/gitea.service + owner: root + group: root + mode: 0644 + +- name : Create firewall rules + ansible.builtin.shell: 'firewall-cmd --zone=public --permanent --add-port={{gitea_http_port}}/tcp && firewall-cmd --reload' + +- name: create gitea database + shell: "su - {{gitea_user}} -c '{{gitea_dir_bin}}/gitea migrate --config {{gitea_dir_etc}}/app.ini'" + +- name: create gitea admin user + shell: "su - {{gitea_user}} -c '{{gitea_dir_bin}}/gitea admin user create --username {{gitea_admin_user}} --password {{gitea_admin_password}} --email {{gitea_admin_email}} --admin --config {{gitea_dir_etc}}/app.ini'" + +- name: Démarrage et activation du service gitea + ansible.builtin.service: + name: gitea + state: started + enabled: true \ No newline at end of file diff --git a/templates/app.ini.j2 b/templates/app.ini.j2 new file mode 100644 index 0000000..a1eda52 --- /dev/null +++ b/templates/app.ini.j2 @@ -0,0 +1,82 @@ +APP_NAME = {{gitea_domain}} +RUN_USER = {{gitea_user}} +RUN_MODE = prod + +[server] +LOCAL_ROOT_URL = {{gitea_local_url}} +SSH_DOMAIN = {{gitea_domain}} +DOMAIN = {{gitea_domain}} +HTTP_PORT = {{gitea_http_port}} +ROOT_URL = {{gitea_external_url}} +DISABLE_SSH = {{gitea_ssh_disable}} +BUILTIN_SSH_SERVER_USER = {{gitea_ssh_builtin_user}} +SSH_PORT = {{gitea_ssh_port}} +START_SSH_SERVER = {{gitea_ssh_start}} +LFS_START_SERVER = {{gitea_lfs_start}} +LFS_JWT_SECRET = +OFFLINE_MODE = false + +[database] +DB_TYPE = {{gitea_db_type}} +HOST = {{gitea_db_host}} +NAME = {{gitea_db_name}} +USER = {{gitea_db_user}} +PASSWD = {{gitea_db_passwd}} +SCHEMA = +SSL_MODE = {{gitea_db_ssl_mode}} +CHARSET = utf8 +LOG_SQL = false +PATH = {{gitea_db_path}} + +[repository] +ROOT = {{gitea_dir}}/var/data/gitea-repositories + +[lfs] +PATH = {{gitea_dir}}/var/data/lfs + +[mailer] +ENABLED = true +MAILER_TYPE = smtp +HOST=localhost:25 +FROM = no-reply@git.gresse.net +IS_TLS_ENABLED = false + +[service] +REGISTER_EMAIL_CONFIRM = false +ENABLE_NOTIFY_MAIL = false +DISABLE_REGISTRATION = true +ALLOW_ONLY_EXTERNAL_REGISTRATION = false +ENABLE_CAPTCHA = false +REQUIRE_SIGNIN_VIEW = false +DEFAULT_KEEP_EMAIL_PRIVATE = false +DEFAULT_ALLOW_CREATE_ORGANIZATION = true +DEFAULT_ENABLE_TIMETRACKING = true +NO_REPLY_ADDRESS = noreply.localhost + +[picture] +DISABLE_GRAVATAR = false +ENABLE_FEDERATED_AVATAR = true + +[openid] +ENABLE_OPENID_SIGNIN = false +ENABLE_OPENID_SIGNUP = false + +[session] +PROVIDER = file + +[log] +MODE = console +LEVEL = info +ROOT_PATH = /opt/gitea/var/log +ROUTER = console + +[repository.pull-request] +DEFAULT_MERGE_STYLE = merge + +[repository.signing] +DEFAULT_TRUST_MODEL = committer + +[security] +INSTALL_LOCK = true +INTERNAL_TOKEN = +PASSWORD_HASH_ALGO = pbkdf2 diff --git a/templates/gitea.service.j2 b/templates/gitea.service.j2 new file mode 100644 index 0000000..c11c641 --- /dev/null +++ b/templates/gitea.service.j2 @@ -0,0 +1,21 @@ +[Unit] +Description=Gitea (Git with a cup of tea) +After=syslog.target +After=network.target + +Wants=mariadb.service +After=mariadb.service + +[Service] +LimitNOFILE=524288:524288 +RestartSec=2s +Type=simple +User={{gitea_user}} +Group={{gitea_user}} +WorkingDirectory={{gitea_dir_var}} +ExecStart={{gitea_dir_bin}}/gitea web --config {{gitea_dir_etc}}/app.ini +Restart=always +Environment=USER=gitea HOME={{gitea_dir}} GITEA_WORK_DIR={{gitea_dir_var}} + +[Install] +WantedBy=multi-user.target \ No newline at end of file