Giter VIP home page Giter VIP logo

ansible-role-gitea's Introduction

Ansible role gitea - Install a gitea server

Build Status Ansible Role Ansible Role Ansible Quality Score

This role installs and manages a gitea server - Source code & screenshots.

Gitea is a Golang Git repository webapp, having the same look and feel as GitHub.

Sample example of use in a playbook

The following code has been tested with Debian 8, it should work on Ubuntu as well.

- name: "Install gitea"
  hosts: all
  vars:
    gitea_user: "gitea"
    gitea_home: "/var/lib/gitea"
    # To limit your users to 30 repos
    gitea_user_repo_limit: 30
    # Don't use a public CDN for frontend assets
    gitea_offline_mode: true

    # Some 'rendering' options for your URLs
    gitea_http_domain: git.yourdomain.fr
    gitea_root_url: https://git.yourdomain.fr

    # Here we assume we are behind a reverse proxy that will
    # handle https for us, so we bind on localhost:3000 using HTTP
    gitea_protocol: http
    gitea_http_listen: 127.0.0.1
    gitea_http_port: 3000

    # SSH server configuration
    gitea_ssh_listen: 0.0.0.0
    gitea_ssh_port: 2222
    # For URLs rendering again
    gitea_ssh_domain: git.yourdomain.fr
    gitea_start_ssh: true

    gitea_secret_key: 3sp00ky5me
    gitea_disable_gravatar: true
    # To make at least your first user register
    gitea_disable_registration: false
    gitea_require_signin: true
    gitea_enable_captcha: true

    gitea_show_user_email: false
  roles:
    - gitea

More detailed options

General

  • gitea_version_check: Check if installed version != gitea_version before initiating binary download
  • gitea_user: UNIX user used by Gitea
  • gitea_group: UNIX group used by Gitea
  • gitea_home: Base directory to work
  • gitea_dl_url: The URL, the compiled gitea-binary will be downloaded from
  • gitea_systemd_cap_net_bind_service: Adds AmbientCapabilities=CAP_NET_BIND_SERVICE to systemd service file
  • gitea_extra_config: Additional configuration

Look and feel

  • gitea_app_name: Displayed application name
  • gitea_show_user_email: Do you want to display email addresses ? (true/false)
  • gitea_disable_gravatar: Do you want to disable Gravatar ? (privacy and so on) (true/false)
  • gitea_offline_mode: Same but for disabling CDNs for frontend assets (true/false)
  • gitea_disable_registration: Do you want to disable user registration ? (true/false)
  • gitea_only_allow_external_registration: Do you want to force registration only using third-party services ? (true/false)
  • gitea_show_registration_button: Do you want to show the registration button? (true/false)
  • gitea_require_signin: Do you require a signin to see repo's (even public ones) ? (true/false)
  • gitea_enable_captcha: Do you want to enable captcha's ? (true/false)
  • gitea_themes: List of enabled themes
  • gitea_theme_default: Default theme

Security

  • gitea_secret_key: Cookie secret key
  • gitea_internal_token: Internal API token
  • gitea_disable_git_hooks: Do you want to disable the interface to add git hooks? If enabled it could be a security bug as it can be used for RCE. Defaults to true (true/false)

Limits

  • gitea_user_repo_limit: Limit how many repos a user can have (-1 for unlimited)

HTTP configuration

  • gitea_http_domain: HTTP domain (displayed in your clone URLs, just the domain like git.foo.fr)
  • gitea_root_url: Root URL used to access your web app (full URL)
  • gitea_protocol: Listening protocol (http/https)
  • gitea_http_listen: Bind address
  • gitea_http_port: Bind port
  • gitea_disable_http_git: Disable the use of Git over HTTP ? (true/false)

SSH configuration

  • gitea_ssh_listen: Bind address for the SSH server
  • gitea_ssh_domain: SSH domain (displayed in your clone URLs)
  • gitea_start_ssh: Do you want to start a built-in SSH server ? (true/false)
  • gitea_ssh_port: SSH bind port

Database configuration

  • gitea_db_type: Database type, can be mysql, postgres or sqlite3
  • gitea_db_host: Database host string host:port or /run/postgresql/ when connectiong to postgres via local unix socket (peer authentication)
  • gitea_db_name: Database name
  • gitea_db_user: Database username
  • gitea_db_password: Database password
  • gitea_db_ssl: Use SSL ? (postgres only!). Can be require, disable, verify-ca or verify-full
  • gitea_db_path: DB path, if you use sqlite3. The default is good enough to work though.

Mailer configuration

  • gitea_mailer_enabled: Whether to enable the mailer. Default: false
  • gitea_mailer_skip_verify: Skip SMTP TLS certificate verification (true/false)
  • gitea_mailer_tls_enabled: Enable TLS for SMTP connections (true/false)
  • gitea_mailer_host: SMTP server hostname and port
  • gitea_mailer_user: SMTP server username
  • gitea_mailer_password: SMTP server password
  • gitea_mailer_from: Sender mail address
  • gitea_enable_notify_mail: Whether e-mail should be send to watchers of a repository when something happens. Default: false
  • gitea_mail_default: Default configuration for email notifications for users (user configurable). Options: enabled, onmention, disable (Default: onmention )
  • gitea_autowatch_new_repo: Enable this to let all organisation users watch new repos when they are created (Default: false)
  • gitea_autowatch_on_change: Enable this to make users watch a repository after their first commit to it (Default: true)
  • gitea_show_mailstones_dashboard: Enable this to show the milestones dashboard page - a view of all the user’s milestones (Default: true)

Fail2Ban configuration

If enabled, this will deploy a fail2ban filter and jail config for Gitea as described in the Gitea Documentation.

As this will only deploy config files, fail2ban already has to be installed or otherwise the role will fail.

  • gitea_fail2ban_enabled: Whether to deploy the fail2ban config or not
  • gitea_fail2ban_jail_maxretry: fail2ban jail maxretry setting. Default: 10
  • gitea_fail2ban_jail_findtime: fail2ban jail findtime setting. Default: 3600
  • gitea_fail2ban_jail_bantime: fail2ban jail bantime setting. Default: 900
  • gitea_fail2ban_jail_action: fail2ban jail action setting. Default: iptables-allports

Oauth2 provider configuration

  • gitea_oauth2_enabled: Enable the Oauth2 provider (true/false)
  • gitea_oauth2_jwt_secret: Oauth2 JWT secret. Can be generated with gitea generate secret JWT_SECRET

GIT LFS configuration

  • gitea_lfs_enabled: Enable GIT LFS (large filesystem)
  • gitea_lfs_mode: should lfs be in offline mode (true/false)
  • gitea_lfs_secret: JWT secret for remote LFS usage

Metrics endpoint configuration

  • gitea_metrics_enabled: Enable the metrics endpoint
  • gitea_metrics_token: Bearer token for the Prometheus scrape job

Repository Indexer configuration

  • gitea_repo_indexer_enabled: Whether to enable the repository indexer (code search). Default: false
  • gitea_repo_indexer_include: Glob patterns to include in the index (comma-separated list). Default: "" (all files)
  • gitea_repo_indexer_exclude: Glob patterns to exclude from the index (comma-separated list). Default: "" (no files)
  • gitea_repo_exclude_vendored: Exclude vendored files from the index. Default: true
  • gitea_repo_indexer_max_file_size: Maximum size of files to be indexed (in bytes). Default: 1048576 (1 MB)

backup on upgrade

  • gitea_backup_on_upgrade: Optionally a backup can be created with every update of gitea. Default: false
  • gitea_backup_location: Where to store the gitea backup if one is created with this role. Default: {{ gitea_home }}/backups/

Contributing

Don't hesitate to create a pull request, and when in doubt you can reach me on Twitter @thomas_maurice.

I'm happy to fix any issue that's been opened, or even better, review your pull requests :)

Testing

Testing uses molecule. To start the tests, install the dependencies first. I would recommend you use a virtual env for that but who am I to tell you what to do.

pip install pew # install pew to manage the venvs
pew new ansible # create the venv
pip install -r requirements-travis.txt # install the requirements
molecule test # Run the actual tests

Note: you need Docker installed

Known testing limitations

Currently it's mainly validating that the playbook runs, the lint is ok, and that kind of things. Since it runs in Docker, we currently have no way to check if the service is actually launched by systemd and so on. This has to be worked on.

License

Copyright 2019-present Thomas Maurice

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

ansible-role-gitea's People

Contributors

agimenez avatar berkes avatar cybre-finn avatar dependabot[bot] avatar dhach avatar disasmwinnie avatar do1jlr avatar finwevi avatar firesoft-de avatar genofire avatar jenstimmerman avatar kimausloos avatar leona-ya avatar madddi avatar max-wittig avatar n0emis avatar orangerkater avatar therojam avatar thomas-maurice avatar trysdyn avatar wzzrd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ansible-role-gitea's Issues

Fix the quality score for the package

I suspect the version check PR introduced things the linter didnt like very much

  • E601: Don't compare to literal True/False
  • E306: Shells that use pipes should set the pipefail option

That should be fixed at some point.

error templating gitea.ini

there are to endif blocks in templates/gitea.ini.j2 but just one if

if: L 56
endif: L 63
endif: L 69

this leads to templating errors and seems to be in current master as well as v0.0.0
i think deleting the one in L63 should be right.

thanks for all the work you are putting into this, greatly appreciate it
Cheers,
Steffen

gitea builtin update: permission denied

I just noticed that the backup can't work like this. The folder /var/backups/ belongs to the user root on my system (debian 10).

My suggestion would be here once to design the backup as opt-in. and then also the backup path on the the one hand to design as variable, on the other hand with access authorization for the gitea user.

- name: Backing up gitea before upgrade
command:
cmd: "gitea dump -c /etc/gitea/gitea.ini"
chdir: /var/backups/
become: true
become_method: su
become_user: "{{ gitea_user }}"
become_flags: "-s /bin/sh"

cmd/dump.go:171:fatal() [F] Unable to open gitea-dump-1613185611.zip: open gitea-dump-1613185611.zip: permission denied

How should we deal with gitea updates in the future?

Gitea has been updated more often lately. And the practice of updating it every time in this role can be done... But it doesn't seem to make that much sense in the long run.

What do you think about extending this ansible role by adding some magic that automatically downloads the newest gitea version? For example by evaluating a curl on https://github.com/go-gitea/gitea/releases/latest...

Of course the variable gitea_version: 1.12.1 should still be valid. But if you write something like gitea_version: latest, a download of the latest version would be nice.

Or what do you think?

Versioning

Hi Thomas,

thanks for this role, it is awesome and really helpful in maintaining my Gitea server.

One small request I have is to implement versioning and tagging for this role. It would be good if it would be possible to deploy a known working or older version for some scenarios.

Thanks!

Template not idempotent

Although I modified the the playbook for my needs, I think this will still apply also on an unmodified playbook.

Somehow the task "Configure gitea" is not idempotent (not sure why, because it basically just copies a file generated from the config template). Because of this, the deamon-restart gets notified every time, and the service is also restarted every time.

I use ansible 2.9.6 on ubuntu 20.04 from the ubuntu repos (both, server and client are ubuntu 20.04)

git via ssh - (maybe) require a shell

By performing git via ssh I got this error:

$ git pull
fatal: Konnte nicht vom Remote-Repository lesen.

Bitte stellen Sie sicher, dass die korrekten Zugriffsberechtigungen bestehen
und das Repository existiert.

If I just try to ssh directly to the gitea server as user gitea, I got the error

PTY allocation request failed on channel 0
Connection to gitea.localhost closed.

I fixed the error by giving the user gitea a shell (/bin/bash) instead of /bin/false.

And now git over ssh works like usual.

And if I know ssh directly to the host, it looks usual to me:

$ ssh [email protected]
PTY allocation request failed on channel 0
Hi there, You've successfully authenticated, but Gitea does not provide shell access.
If this is unexpected, please log in with password and setup Gitea under another user.
Connection to gitea.localhost closed.

I changed it here: DO1JLR@c8602dd
Should I create a pull request or is this probably a issue with the ssh roles I use (add users + keys and configure sshd)

Couldnt start gitea service?

Hi!

I am trying to install gitea on ubuntu 18.04.

After trying to start the service I get

gitea.service: Failed to reset devices.list: Operation not permitted

Any clue how to solve it?

Version check fails silently due -o pipefail

The version check command with set -eo pipefail fails silently.

Relevant output of ansible -vvv on Debian Buster:

"msg": "non-zero return code",
"rc": 2,
"start": "2020-06-15 02:59:18.807048",
"stderr": "/bin/sh: 1: set: Illegal option -o pipefail",
"stderr_lines": [  
"/bin/sh: 1: set: Illegal option -o pipefail" 
],

The problem was already discussed in ansible/ansible-lint#497.

Short: there is no guarantee which shell Ansible uses on which distro and -o pipefail is not likely to be supported.
The solution could be leaving it out or using suggestion from ansible/ansible-lint#497 (comment).

Despite pipefail being best practice, I tend to support the former. Having checks for bash, although likely to be present, require bash to be installed.

OpenId Connect Configuration

HI,
First, great work for this role. It works perfectly.

It would be great to have the possibility to configure gitea to retrieve user identity from a OpenID Connect provider . This is a functionality support by Gitea natively.

thx

Gitea Key not found on Keyserver

The key server used to retrieve the key (keyserver.ubuntu.com) for the signature answers to a query for the gitea key with "not found", thus the task "Download gitea asc file" in install.yml fails.

The keyserver should be changed to one that has the key. I used keys.gnupg.org, but not sure which server is the most reliable. Maybe the official key server that gitea uses should be used for this role as well.

define mailer type

In order to set the MAILER_TYPE = sendmail in the config, it is necessary to define it as variable as all changes in gitea.ini will be overwritten by ansible.

Web not accessible after installation

Hi,

Just deployed this Gitea role, with the following variables set in group_vars:

gitea_version: "1.16.7"
gitea_home: /opt/data/gitea
gitea_http_domain: gitea.mydomain.com
gitea_ssh_domain: gitea.mydomain.com
# gitea_http_listen: 10.10.1.10
gitea_http_listen: 0.0.0.0
gitea_ssh_port: 2223
# gitea_root_url: https://gitea.mydomain.com:3000
gitea_root_url: https://gitea.mydomain.com
gitea_protocol: https

But after execution, I am only able to access port 2223 (telnet), but not port 3000. No firewall loaded/running.

root@control:~# netstat -tlpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 10.10.1.10:53           0.0.0.0:*               LISTEN      14010/named
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      618/systemd-resolve
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1339/sshd: /usr/sbi
tcp        0      0 127.0.0.1:953           0.0.0.0:*               LISTEN      14010/named
tcp6       0      0 :::2223                 :::*                    LISTEN      25255/gitea
tcp6       0      0 ::1:53                  :::*                    LISTEN      14010/named
tcp6       0      0 :::22                   :::*                    LISTEN      1339/sshd: /usr/sbi
tcp6       0      0 ::1:953                 :::*                    LISTEN      14010/named
root@control:~# curl https://gitea.mydomain.com:3000
curl: (7) Failed to connect to gitea.mydomain.com port 3000: Connection refused
root@control:~# curl https://localhost:3000
curl: (7) Failed to connect to localhost port 3000: Connection refused
root@control:~# ping gitea.mydomain.com
PING control01.mydomain.com (10.10.1.10) 56(84) bytes of data.
64 bytes from control (10.10.1.10): icmp_seq=1 ttl=64 time=0.075 ms
^C
--- control01.mydomain.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.075/0.075/0.075/0.000 ms
root@control:~#

Running Ubuntu 20.04. What am I doing wrong? (I am not using a Web proxy)

Sqlite3 has being defined as default engine is the database something else?

Hi!

I've mostly used default settings on my ubuntu 18.04 instance.
Database should be sqlite3 and gitea also see it as that.

Problem comes when I use
/usr/local/bin/gitea dump -c /etc/gitea/gitea.ini

and then try to restore then it fails.
Weird part is that true and false don’t exist in SQLite3 and it contains in the dump.

dublicated entries in config

{% if gitea_lfs_server_enabled | bool -%}
;Enables git-lfs support.
LFS_START_SERVER = true
; Where to store LFS files.
LFS_CONTENT_PATH = {{ gitea_lfs_content_path }}
; LFS authentication secret
LFS_JWT_SECRET = {{ gitea_lfs_jwt_secret }}
{% endif %}
LFS_CONTENT_PATH = {{ gitea_lfs_content_path }}
; if the LFS sotre is not offline/local
LFS_JWT_SECRET = {{ gitea_lfs_secret }}
OFFLINE_MODE = {{ gitea_lfs_mode }}

LFS_CONTENT_PATH and LFS_JWT_SECRET appear multiple times in the config.

And there are different ansible variables that will define the same secret (LFS_JWT_SECRET)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.