|
10 | 10 | tags:
|
11 | 11 | - install
|
12 | 12 |
|
13 |
| -- name: Download runner package |
| 13 | +- name: Download runner package version - "{{ runner_version }}" |
14 | 14 | local_action:
|
15 | 15 | module: get_url
|
16 | 16 | url: "https://github.com/actions/runner/releases/download/v{{ runner_version }}/actions-runner-linux-x64-{{ runner_version }}.tar.gz"
|
17 | 17 | dest: ./actions-runner-linux.tar.gz
|
18 | 18 | run_once: yes
|
| 19 | + when: runner_version != "latest" |
19 | 20 | tags:
|
20 | 21 | - install
|
21 |
| - |
| 22 | + |
22 | 23 | - name: Unarchive package
|
23 | 24 | unarchive:
|
24 | 25 | src: ./actions-runner-linux.tar.gz
|
|
27 | 28 | tags:
|
28 | 29 | - install
|
29 | 30 |
|
30 |
| -- name: Get registration token |
| 31 | +- name: Get registration token (RUN ONCE) |
31 | 32 | uri:
|
32 | 33 | url: "https://api.github.com/repos/{{ github_account }}/{{ github_repo }}/actions/runners/registration-token"
|
33 | 34 | user: "{{ github_account }}"
|
|
41 | 42 | - install
|
42 | 43 | - uninstall
|
43 | 44 |
|
44 |
| -# - name: Sstop and disable Github Actions Runner service if it is running |
45 |
| -# systemd: |
46 |
| -# name: "actions.runner.{{ github_account }}-{{ github_repo }}.{{ ansible_hostname }}" |
47 |
| -# state: stopped |
48 |
| -# enabled: no |
49 |
| -# tags: |
50 |
| -# - uninstall |
| 45 | +- name: Check currently registered runners (RUN ONCE) |
| 46 | + uri: |
| 47 | + url: "https://api.github.com/repos/{{ github_account }}/{{ github_repo }}/actions/runners" |
| 48 | + user: "{{ github_account }}" |
| 49 | + password: "{{ access_token }}" |
| 50 | + method: GET |
| 51 | + status_code: 200 |
| 52 | + force_basic_auth: yes |
| 53 | + register: registered_runners |
| 54 | + run_once: yes |
| 55 | + tags: |
| 56 | + - install |
| 57 | + - uninstall |
51 | 58 |
|
52 |
| -# - name: Unregister runner |
53 |
| -# command: "{{ runner_dir }}/./config.sh remove --token {{ registration.json.token }} --unattended" |
54 |
| -# become_user: "{{ runner_user }}" |
55 |
| -# tags: |
56 |
| -# - uninstall |
| 59 | +- name: Check service facts |
| 60 | + service_facts: |
| 61 | + |
| 62 | +- name: Build service name |
| 63 | + set_fact: |
| 64 | + runner_service: "actions.runner.{{ github_account }}-{{ github_repo }}.{{ ansible_hostname }}" |
| 65 | + |
| 66 | +- name: Stop and disable GitHub Actions Runner service |
| 67 | + systemd: |
| 68 | + name: "actions.runner.{{ github_account }}-{{ github_repo }}.{{ ansible_hostname }}" |
| 69 | + state: stopped |
| 70 | + enabled: no |
| 71 | + when: runner_service in services |
| 72 | + tags: |
| 73 | + - uninstall |
| 74 | + |
| 75 | +- name: Unregister runner from the GitHub |
| 76 | + command: "{{ runner_dir }}/./config.sh remove --token {{ registration.json.token }} --unattended" |
| 77 | + become_user: "{{ runner_user }}" |
| 78 | + when: "'ansible_hostname' in '{{ registered_runners.json.name }}'" |
| 79 | + tags: |
| 80 | + - uninstall |
57 | 81 |
|
58 | 82 | - name: Register runner
|
59 | 83 | command: "{{ runner_dir }}/config.sh --url {{ github_server }}/{{ github_account }}/{{ github_repo }} --token {{ registration.json.token }} --unattended"
|
|
0 commit comments