deploy_gitea_runner/tasks/install_host.yml

57 lines
2.4 KiB
YAML
Raw Normal View History

2023-08-10 16:09:44 +00:00
---
2023-08-11 18:06:15 +00:00
# task/install_host file for deploy_gitea_runner
- name: "Get release for gitea_runner:{{ deploy_gitea_runner_version }}"
2023-08-10 16:09:44 +00:00
vars:
2023-08-11 18:06:15 +00:00
_gitea_actions_url_ext: "{% if deploy_gitea_runner_version == 'latest'%}releases{% else %}releases/tags{% endif %}"
2023-08-10 16:09:44 +00:00
ansible.builtin.uri:
2023-08-11 18:53:23 +00:00
url: "{{ deploy_gitea_runner_gitea_api }}/{{ _gitea_actions_url_ext }}/{{ deploy_gitea_runner_version }}"
2023-08-10 16:09:44 +00:00
return_content: true
2023-08-11 18:06:15 +00:00
register: _gitea_runner_new_release
2023-08-10 16:09:44 +00:00
2023-08-11 18:06:15 +00:00
- name: "Check if gitea_runner is already installed"
ansible.builtin.stat:
path: "{{ deploy_gitea_runner_directory }}/.version"
changed_when: false
check_mode: false
register: _gitea_runner_is_installed
- name: "Check current gitea_runner version"
ansible.builtin.command: "cat {{ deploy_gitea_runner_directory }}/.version"
register: _gitea_runner_old_release
2023-08-10 16:09:44 +00:00
check_mode: false
changed_when: false
2023-08-11 18:06:15 +00:00
when: _gitea_runner_is_installed.stat.exists
2023-08-10 16:09:44 +00:00
2023-08-11 18:06:15 +00:00
- name: "Set facts for wanted gitea_runner release"
2023-08-10 16:09:44 +00:00
ansible.builtin.set_fact:
2023-08-11 18:06:15 +00:00
deploy_gitea_runner_wanted_version: "{{ _gitea_runner_new_release.json['tag_name']|regex_replace('v', '') }}"
when: _gitea_runner_new_release.json is defined
and (_gitea_runner_new_release.json | length > 0)
2023-08-10 16:09:44 +00:00
2023-08-11 18:06:15 +00:00
- name: "Set facts for current gitea_runner release"
2023-08-10 16:09:44 +00:00
ansible.builtin.set_fact:
2023-08-11 18:06:15 +00:00
deploy_gitea_runner_current_version: "{{ _gitea_runner_old_release.stdout | regex_replace('v', '') }}"
when: _gitea_runner_old_release.stdout is defined
and (_gitea_runner_old_release.stdout | length > 0)
2023-08-10 16:09:44 +00:00
2023-08-11 18:06:15 +00:00
- name: "Install gitea_runner"
when: deploy_gitea_runner_current_version is not defined
or deploy_gitea_runner_wanted_version not in deploy_gitea_runner_current_version
block:
2023-08-11 18:53:23 +00:00
- name: "Download and install gitea_runner version:{{ deploy_gitea_runner_version }}"
2023-08-11 18:06:15 +00:00
ansible.builtin.get_url:
2023-08-11 18:53:23 +00:00
url: "{{ deploy_gitea_runner_gitea_url }}/releases/download/v{{ deploy_gitea_runner_wanted_version }}/act_runner-{{ deploy_gitea_runner_wanted_version }}-linux-{{ deploy_gitea_runner_arch_map[ansible_architecture] }}"
dest: "{{ deploy_gitea_runner_path }}"
2023-08-11 18:06:15 +00:00
force: true
owner: root
group: root
mode: '0755'
notify:
- systemctl-restart-gitea-runner
2023-08-10 16:09:44 +00:00
2023-08-11 18:06:15 +00:00
- name: "Update version file"
ansible.builtin.copy:
content: "{{ deploy_gitea_runner_wanted_version }}"
dest: "{{ deploy_gitea_runner_directory }}/.version"
mode: "0600"