Deploy Gitea Podman container unattended via Ansible
Gitea is a popular, lightweight Git frontend that can also be deployed quickly thanks to the Docker image . However, after the container is started, the initial configuration (network options, permissions, database) is done via web interface by default. This is unattractive if you want an unattended and automated installation - for example, because you set up many Gitea instances.
Fortunately, various environment variables can be assigned to the Gitea container to define most of the settings - a complete list of variable fragments can be found in the documentation.
In connection with Podman, it is still important to note that the user account running the container must be allowed to continue executing commands after logout (linger
). This setting must first be made - otherwise the container will stop after a few seconds. If Docker is used, this step is omitted, since Docker uses a background service. Also, if not already done, it is necessary to install the containers.podman
Ansible collection:
1$ ansible-galaxy collection install containers.podman
The creation of the first user requires the execution of a command as git
user in the gitea container - by means of adjusted changed_when
and failed_when
conditions this step can also be implemented idempotently.
The entire installation can then be implemented as follows:
1- name: Deploy Gitea
2 hosts: podman-hosts
3 become: true
4 vars:
5 gitea_user: svc-gitea
6 gitea_admin: fmulder
7 gitea_password: trustno1
8
9 tasks:
10 - name: Enable linger
11 command: loginctl enable-linger "{{ gitea-user }}"
12 changed_when: false
13
14 - name: Create Gitea data directory
15 file:
16 path: "/home/{{ gitea_user }}/gitea"
17 state: directory
18 owner: "{{ gitea_user }}"
19 group: "{{ gitea_user }}"
20 mode: '0755'
21 become: false
22
23 - name: Start Gitea
24 containers.podman.podman_container:
25 name: gitea
26 image: docker.io/gitea/gitea:1.16
27 volume:
28 - "/home/{{ gitea-user }}/gitea:/data"
29 ports:
30 - "3000:3000"
31 - "10022:22"
32 env:
33 APP-NAME: "Pinkepank Gitea"
34 GITEA--DEFAULT--RUN-MODE: prod
35 GITEA--server--DOMAIN: "{{ ansible_fqdn }}"
36 GITEA--server--SSH-DOMAIN: "{{ ansible_fqdn }}"
37 GITEA--server--ROOT-URL: "http://{{ ansible_fqdn }}:3000"
38 GITEA--server--OFFLINE-MODE: true
39 GITEA--database--PATH: /data/gitea/gitea.db
40 GITEA--database--DB-TYPE: sqlite3
41 GITEA--picture--DISABLE-GRAVATAR: true
42 GITEA--service--DISABLE-REGISTRATION: true
43 GITEA--service--REQUIRE-SIGNIN-VIEW: true
44 GITEA--security--INSTALL-LOCK: true
45 become: false
46
47 - name: Create Gitea admin user
48 command: "podman exec -u git gitea /usr/local/bin/gitea admin user create --admin --username {{ gitea_admin }} --password {{ gitea_password }} --email root@localhost"
49 register: create-user
50 changed-when:
51 - create-user.rc != 1
52 - '"already exists" not in create-user.stdout'
53 failed-when:
54 - create-user.rc != 0
55 - '"already exists" not in create-user.stdout'
56 become: false
Image version 1.16 was the most recent at the time of publication - please check whether there is a newer version available!