Linux OSBN/Ubuntuusers Planet XING / LinkedIn

Deploy Gitea Podman container unattended via Ansible

Gitea installation assistant

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:

$ 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:

- name: Deploy Gitea
  hosts: podman-hosts
  become: true
    gitea_user: svc-gitea
    gitea_admin: fmulder
    gitea_password: trustno1

    - name: Enable linger
      command: loginctl enable-linger "{{ gitea_user }}"
      changed_when: false

    - name: Create Gitea data directory
        path: "/home/{{ gitea_user }}/gitea"
        state: directory
        owner: "{{ gitea_user }}"
        group: "{{ gitea_user }}"
        mode: '0755'
      become: false

    - name: Start Gitea
        name: gitea
          - "/home/{{ gitea_user }}/gitea:/data"
          - "3000:3000"
          - "10022:22"
          APP_NAME: "Pinkepank Gitea"
          GITEA__DEFAULT__RUN_MODE: prod
          GITEA__server__DOMAIN: "{{ ansible_fqdn }}"
          GITEA__server__SSH_DOMAIN: "{{ ansible_fqdn }}"
          GITEA__server__ROOT_URL: "http://{{ ansible_fqdn }}:3000"
          GITEA__server__OFFLINE_MODE: true
          GITEA__database__PATH: /data/gitea/gitea.db
          GITEA__database__DB_TYPE: sqlite3
          GITEA__picture__DISABLE_GRAVATAR: true
          GITEA__service__DISABLE_REGISTRATION: true
          GITEA__service__REQUIRE_SIGNIN_VIEW: true
          GITEA__security__INSTALL_LOCK: true
      become: false

    - name: Create Gitea admin user
      command: "podman exec -u git gitea /usr/local/bin/gitea admin user create --admin --username {{ gitea_admin }} --password {{ gitea_password }} --email root@localhost"
      register: create_user
        - create_user.rc != 1
        - '"already exists" not in create_user.stdout'
        - create_user.rc != 0
        - '"already exists" not in create_user.stdout'
      become: false
Image version 1.16 was the most recent at the time of publication – please check whether there is a newer version available!

Sharing is caring

Leave a Reply

Your email address will not be published.