diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2023-04-14 17:22:21 +0200 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2023-04-14 17:22:21 +0200 |
commit | 613cc4b223fe2fd29070a2df52cc6a8f4cf0e271 (patch) | |
tree | e077f4ab47f94c5ecfa2908e58b3386b26528756 | |
parent | 59b5e6cbb13bf00f074ec9cd4944055cc36192bc (diff) | |
download | ansible_collection-613cc4b223fe2fd29070a2df52cc6a8f4cf0e271.tar.gz |
gitea_runner
-rw-r--r-- | galaxy.yml | 2 | ||||
-rw-r--r-- | roles/gitea_runner/defaults/main.yml | 28 | ||||
-rw-r--r-- | roles/gitea_runner/files/act_runner.service | 15 | ||||
-rw-r--r-- | roles/gitea_runner/handlers/main.yml | 7 | ||||
-rw-r--r-- | roles/gitea_runner/tasks/main.yml | 87 |
5 files changed, 138 insertions, 1 deletions
@@ -1,6 +1,6 @@ namespace: kompetenzbolzen name: stuff -version: 0.18.5 +version: 0.19.0 readme: README.md authors: - Jonas Gunz <himself@jonasgunz.de> diff --git a/roles/gitea_runner/defaults/main.yml b/roles/gitea_runner/defaults/main.yml new file mode 100644 index 0000000..aebcd2e --- /dev/null +++ b/roles/gitea_runner/defaults/main.yml @@ -0,0 +1,28 @@ +--- +gitea_runner: + version: + ver: 0.1.2 + gitea_url: 'https://gitea.example.com/' + runner_token: 'TOKEN' + tags: + ubuntu-latest: docker://node:16-bullseye + python-latest: docker://docker:latest + config: + log: + level: info + runner: + file: /var/lib/act_runner/runner.conf + capacity: 1 + envs: {} + env_file: '' + timeout: 3h + insecure: false + fetch_timeout: 5s + fetch_interval: 2s + cache: + enabled: true + dir: /var/lib/act_runner/runner.conf + host: '' + port: 0 + container: + network_mode: bridge diff --git a/roles/gitea_runner/files/act_runner.service b/roles/gitea_runner/files/act_runner.service new file mode 100644 index 0000000..f6bbca0 --- /dev/null +++ b/roles/gitea_runner/files/act_runner.service @@ -0,0 +1,15 @@ +[Unit] +Description=Gitea act_runner +After=syslog.target +After=network.target + +[Service] +RestartSec=2s +Type=simple +User=runner +Group=runner +ExecStart=/usr/local/bin/act_runner -c /etc/act_runner/config.yaml daemon +Restart=always + +[Install] +WantedBy=multi-user.target diff --git a/roles/gitea_runner/handlers/main.yml b/roles/gitea_runner/handlers/main.yml new file mode 100644 index 0000000..6eb4fa0 --- /dev/null +++ b/roles/gitea_runner/handlers/main.yml @@ -0,0 +1,7 @@ +--- +- name: Handle systemd + systemd: + name: act_runner.service + enabled: true + state: restarted + become: true diff --git a/roles/gitea_runner/tasks/main.yml b/roles/gitea_runner/tasks/main.yml new file mode 100644 index 0000000..b050a12 --- /dev/null +++ b/roles/gitea_runner/tasks/main.yml @@ -0,0 +1,87 @@ +--- +- name: Install packages + apt: + name: + - docker.io + become: true + +- name: Create User + user: + name: runner + system: true + state: present + groups: + - docker + become: true + +- name: Folder structure + file: + path: '{{ item }}' + owner: runner + group: runner + mode: '750' + state: directory + become: true + loop: + - /var/lib/act_runner/ + - /etc/act_runner/ + +- name: Configuration + copy: + dest: /etc/act_runner/config.yaml + owner: runner + group: runner + content: '{{ gitea_runner.config | to_yaml }}' + become: true + +- name: pull sha256sum + uri: + url: 'https://dl.gitea.io/act_runner/{{ gitea_runner.version.ver }}/act_runner-{{ gitea_runner.version.ver }}-linux-amd64.sha256' + method: GET + return_content: yes + register: runner_sha256 + +- name: Download Gitea act_runner + get_url: + url: 'https://dl.gitea.io/act_runner/{{ gitea_runner.version.ver }}/act_runner-{{ gitea_runner.version.ver }}-linux-amd64' + checksum: 'sha256:{{ (runner_sha256.content | split(" "))[0] }}' + dest: /usr/local/bin/act_runner + owner: root + group: root + mode: '755' + become: yes + notify: + - Handle systemd + +- name: Install gitea unit file + copy: + src: act_runner.service + dest: /etc/systemd/system/act_runner.service + become: yes + notify: + - Handle systemd + +- debug: + msg: '--labels {% for k, v in gitea_runner.tags.items() %}{{ k }}:{{ v }},{% endfor %}' + + +- name: Register runner + shell: + cmd: '/usr/local/bin/act_runner -c /etc/act_runner/config.yaml register --instance {{ gitea_runner.gitea_url }} --token {{ gitea_runner.runner_token }} --no-interactive --labels {% for k, v in gitea_runner.tags.items() %}{{ k }}:{{ v }},{% endfor %}' + creates: '/var/lib/act_runner/runner.conf' + become_user: runner + become: true + notify: + - Handle systemd + +- name: Configure labels + lineinfile: + path: '/var/lib/act_runner/runner.conf' + state: present + insertafter: '"labels"' + line: ' "{{ item.key }}:{{ item.value }}",' + search_string: ' "{{ item.key }}:{{ item.value }}",' + with_dict: '{{ gitea_runner.tags }}' + become: true + notify: + - Handle systemd |