Skip to content

Commit 72ee61c

Browse files
basictheprogramguenhter
authored andcommitted
refactor(gitlab-runner): use ansible_facts dictionary syntax
Replace deprecated Ansible magic variables with explicit ansible_facts dictionary references throughout the role. This modernizes the code to align with current Ansible best practices and improves clarity by making fact sources explicit. * Replace all magic variable references with ansible_facts syntax * ansible_processor_vcpus → ansible_facts['processor_vcpus'] * ansible_os_family → ansible_facts['os_family'] * ansible_hostname → ansible_facts['hostname'] * ansible_distribution → ansible_facts['distribution'] * ansible_distribution_release → ansible_facts['distribution_release'] * Apply changes across defaults, handlers, tasks, and vars files * Improve YAML formatting in vars/Debian.yml * Remove extra blank line at top of file * Reformat gitlab_runner_remove_bash_logout to multi-line syntax * Fix indentation alignment in tasks/main-unix.yml when condition
1 parent 0a41606 commit 72ee61c

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed

defaults/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ gitlab_runner_config_file_location: "{{ gitlab_runner_config_file | dirname }}"
3131
gitlab_runner_executable: "{{ gitlab_runner_package_name }}"
3232

3333
# Maximum number of global jobs to run concurrently
34-
gitlab_runner_concurrent: "{{ ansible_processor_vcpus }}"
34+
gitlab_runner_concurrent: "{{ ansible_facts['processor_vcpus'] }}"
3535

3636
# Defines the interval length, in seconds, between the runner checking for new jobs.
3737
# The default value is 0. If set to 0 or lower, the default value of GitLab runner is used, which is 3.

handlers/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66
state: "{{ gitlab_runner_restart_state }}"
77
listen: restart_gitlab_runner
88
become: true
9-
when: ansible_os_family != 'Darwin' and ansible_os_family != 'Windows' and not gitlab_runner_container_install
9+
when: ansible_facts['os_family'] != 'Darwin' and ansible_facts['os_family'] != 'Windows' and not gitlab_runner_container_install
1010

1111
# macOS
1212
- name: Restart_gitlab_runner_macos
1313
ansible.builtin.command: "{{ gitlab_runner_executable }} restart"
1414
listen: restart_gitlab_runner_macos
1515
become: "{{ gitlab_runner_system_mode }}"
16-
when: ansible_os_family == 'Darwin' and gitlab_runner_macos_start_runner
16+
when: ansible_facts['os_family'] == 'Darwin' and gitlab_runner_macos_start_runner
1717

1818
- name: Restart_gitlab_runner_windows
1919
ansible.windows.win_command: "{{ gitlab_runner_executable }} restart"
2020
args:
2121
chdir: "{{ gitlab_runner_config_file_location }}"
2222
listen: restart_gitlab_runner_windows
23-
when: ansible_os_family == 'Windows' and gitlab_runner_windows_start_runner
23+
when: ansible_facts['os_family'] == 'Windows' and gitlab_runner_windows_start_runner
2424

2525
# Container
2626
- name: Restart_gitlab_runner_container

tasks/config-runner.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
vars:
2323
runn_name_prefix: "{{ conf_name_prefix }} runner[{{ (gitlab_runner_index | int) + 1 }}/{{ gitlab_runner_runners | length }}]:"
2424
when:
25-
- ('name = "'+gitlab_runner.name|default(ansible_hostname+'-'+gitlab_runner_index|string)+'"') in runner_config
25+
- ('name = "'+gitlab_runner.name|default(ansible_facts["hostname"]+'-'+gitlab_runner_index|string)+'"') in runner_config
2626
- gitlab_runner.state|default('present') == 'present'
2727
loop: "{{ gitlab_runner_runners }}"
2828
loop_control:
@@ -35,7 +35,7 @@
3535
path: "{{ temp_runner_config.path }}"
3636
state: absent
3737
when:
38-
- ('name = "'+gitlab_runner.name|default(ansible_hostname+'-'+gitlab_runner_index|string)+'"') in runner_config
38+
- ('name = "'+gitlab_runner.name|default(ansible_facts["hostname"]+'-'+gitlab_runner_index|string)+'"') in runner_config
3939
- gitlab_runner.state|default('present') == 'absent'
4040
loop: "{{ gitlab_runner_runners }}"
4141
loop_control:

tasks/main-unix.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
---
22
- name: Install GitLab Runner (Debian)
33
ansible.builtin.include_tasks: install-debian.yml
4-
when: ansible_os_family == 'Debian'
4+
when: ansible_facts['os_family'] == 'Debian'
55

66
- name: Install GitLab Runner (RedHat)
77
ansible.builtin.include_tasks: install-redhat.yml
8-
when: ansible_os_family == 'RedHat'
8+
when: ansible_facts['os_family'] == 'RedHat'
99

1010
- name: Install GitLab Runner (macOS)
1111
ansible.builtin.include_tasks: install-macos.yml
12-
when: ansible_os_family == 'Darwin'
12+
when: ansible_facts['os_family'] == 'Darwin'
1313

1414
- name: Install GitLab Runner (Arch)
1515
ansible.builtin.include_tasks: install-arch.yml
16-
when: ansible_os_family == 'Archlinux'
16+
when: ansible_facts['os_family'] == 'Archlinux'
1717

1818
- name: (Unix) Delete runners which were removed in GitLab
1919
ansible.builtin.command: "{{ gitlab_runner_executable }} verify --delete"
@@ -28,7 +28,7 @@
2828
- name: (Unix) Register GitLab Runner
2929
ansible.builtin.include_tasks: register-runner.yml
3030
vars:
31-
actual_gitlab_runner_name: "{{ gitlab_runner.name | default(ansible_hostname + '-' + gitlab_runner_index | string) }}"
31+
actual_gitlab_runner_name: "{{ gitlab_runner.name | default(ansible_facts['hostname'] + '-' + gitlab_runner_index | string) }}"
3232
when: gitlab_runner.token is defined or gitlab_runner_registration_token | string | length > 0
3333
loop: "{{ gitlab_runner_runners }}"
3434
loop_control:
@@ -43,7 +43,7 @@
4343
- name: Set global options (macOS/Debian/RedHat)
4444
ansible.builtin.import_tasks: global-setup.yml
4545
when: gitlab_runner_config_update_mode == 'by_config_toml' or
46-
gitlab_runner_config_update_mode == 'by_registering'
46+
gitlab_runner_config_update_mode == 'by_registering'
4747

4848
- name: (Unix) Configure GitLab Runner
4949
ansible.builtin.include_tasks: config-runners.yml

tasks/main.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
vars:
55
possible_files:
66
files:
7-
- "{{ ansible_distribution }}.yml"
8-
- "{{ ansible_os_family }}.yml"
7+
- "{{ ansible_facts['distribution'] }}.yml"
8+
- "{{ ansible_facts['os_family'] }}.yml"
99
- default.yml
1010
paths:
1111
- vars
1212

1313
- name: Validate GitLab Runner configurations
1414
ansible.builtin.include_tasks: validate-runner-config.yml
1515
vars:
16-
actual_gitlab_runner_name: "{{ gitlab_runner.name | default(ansible_hostname + '-' + gitlab_runner_index | string) }}"
16+
actual_gitlab_runner_name: "{{ gitlab_runner.name | default(ansible_facts['hostname'] + '-' + gitlab_runner_index | string) }}"
1717
loop: "{{ gitlab_runner_runners }}"
1818
loop_control:
1919
label: "{{ actual_gitlab_runner_name }}"
@@ -30,10 +30,10 @@
3030
vars:
3131
gitlab_install_target_platform: unix
3232
ansible.builtin.include_tasks: main-unix.yml
33-
when: ansible_os_family != 'Windows' and not gitlab_runner_container_install
33+
when: ansible_facts['os_family'] != 'Windows' and not gitlab_runner_container_install
3434

3535
- name: Install GitLab Runner (Windows)
3636
vars:
3737
gitlab_install_target_platform: windows
3838
ansible.builtin.include_tasks: main-windows.yml
39-
when: ansible_os_family == 'Windows' and not gitlab_runner_container_install
39+
when: ansible_facts['os_family'] == 'Windows' and not gitlab_runner_container_install

vars/Debian.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
32
gitlab_runner_executable: /usr/bin/{{ gitlab_runner_package_name }}
43

54
gitlab_runner_runtime_owner: gitlab-runner
@@ -17,5 +16,6 @@ gitlab_runner_remove_bash_logout_releases:
1716
- jammy
1817
- noble
1918

20-
gitlab_runner_remove_bash_logout:
21-
"{{ ansible_distribution_release in gitlab_runner_remove_bash_logout_releases | default(false) }}"
19+
gitlab_runner_remove_bash_logout: >-
20+
{{ ansible_facts['distribution_release']
21+
in gitlab_runner_remove_bash_logout_releases | default(false) }}

0 commit comments

Comments
 (0)