Skip to content

Commit 0c8ce9b

Browse files
Merge pull request #34 from pvlltvk/master
Fix idempotence issues and use tempfile for archive
2 parents 43762f4 + 34ef684 commit 0c8ce9b

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ This role will deploy/redeploy/uninstall and register/unregister local GitHub Ac
1313
* System must have access to the GitHub.
1414

1515
* The role require Personal Access Token to access the GitHub. The token has to be a value of `PERSONAL_ACCESS_TOKEN` variable.
16-
Export the token to the local host environment. The token has to have admin rights for the repo.
17-
Personal Access Token for GitHub account can be created [here](https://github.com/settings/tokens).
16+
Export the token to the local host environment. The token has to have admin rights for the repo.
17+
Personal Access Token for GitHub account can be created [here](https://github.com/settings/tokens).
1818
**Note:** Never store you personal access token in the GitHub repository. Use [GitHub Secrets](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets) or some different secrets service.
1919

20-
* Runner user has to be pre-created.
20+
* Runner user has to be pre-created.
2121
Recommended role: `monolithprojects.user_management`
2222

23-
* CentOS systems require EPEL repository.
23+
* CentOS systems require EPEL repository.
2424
Recommended role: `robertdebock.epel`
2525

2626
* Weekly tested on:
@@ -48,6 +48,9 @@ runner_version: "latest"
4848
# If found, replace already registered runner
4949
replace_runner: yes
5050

51+
# If found, delete already existed runner before install
52+
uninstall_runner: no
53+
5154
# Do not show Ansible logs which may contain sensitive data (registration token)
5255
hide_sensitive_logs: yes
5356

defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ runner_version: "latest"
1111
# If found, replace already registered runner
1212
replace_runner: yes
1313

14+
# If found, delete already existed runner before install
15+
uninstall_runner: no
16+
1417
# Do not show Ansible logs which may contain sensitive data (registration token)
1518
hide_sensitive_logs: yes
1619

tasks/install_runner.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,44 @@
3434
runner_version: "{{ api_response.json.tag_name | regex_replace('^v', '') }}"
3535
when: runner_version == "latest"
3636

37+
- name: Check if desired version already installed
38+
command: "grep -i {{ runner_version }} {{ runner_dir }}/bin/Runner.Listener.deps.json"
39+
register: runner_installed
40+
changed_when: False
41+
ignore_errors: yes
42+
tags:
43+
- install
44+
45+
- name: Create temporary directory for archive
46+
tempfile:
47+
state: directory
48+
register: tempdir
49+
run_once: yes
50+
delegate_to: localhost
51+
become: false
52+
when: runner_version not in runner_installed.stdout
53+
tags:
54+
- install
55+
3756
- name: Download runner package version - "{{ runner_version }}" (RUN ONCE)
3857
get_url:
3958
url: "https://github.com/actions/runner/releases/download/v{{ runner_version }}/actions-runner-linux-x64-{{ runner_version }}.tar.gz"
40-
dest: "./actions-runner-linux-{{ runner_version }}.tar.gz"
59+
dest: "{{ tempdir.path }}/actions-runner-linux-{{ runner_version }}.tar.gz"
4160
force: no
4261
run_once: yes
4362
become: false
4463
delegate_to: localhost
64+
when: runner_version not in runner_installed.stdout
4565
tags:
4666
- install
4767

4868
- name: Unarchive package
4969
unarchive:
50-
src: "./actions-runner-linux-{{ runner_version }}.tar.gz"
70+
src: "{{ tempdir.path }}/actions-runner-linux-{{ runner_version }}.tar.gz"
5171
dest: "{{ runner_dir }}/"
5272
owner: "{{ runner_user }}"
5373
mode: 0755
74+
when: runner_version not in runner_installed.stdout
5475
tags:
5576
- install
5677

tasks/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- install
1010

1111
- include_tasks: uninstall_runner.yml
12+
when: uninstall_runner
1213
tags:
1314
- uninstall
1415

0 commit comments

Comments
 (0)