Skip to content

Commit 87acbaa

Browse files
authored
Merge pull request #466 from Normo/gitlab-runner-internal-vars
GitLab-runner role: prefix all internal variables with '__'
2 parents f4873e9 + c595ab9 commit 87acbaa

File tree

8 files changed

+46
-45
lines changed

8 files changed

+46
-45
lines changed

roles/gitlab_runner/handlers/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
ansible.builtin.service:
1414
name: "gitlab-runner"
1515
state: "restarted"
16-
when: "not gitlab_runner_is_initial_dryrun"
16+
when: "not __gitlab_runner_is_initial_dryrun"
1717

1818
...

roles/gitlab_runner/tasks/configuration.yml

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
community.crypto.openssh_keypair: # noqa: args[module]
3030
path: "{{ gitlab_runner_ssh_private_key_path }}"
3131
type: "{{ gitlab_runner_ssh_key_type | default('ed25519') }}"
32-
register: "gitlab_runner_ssh_keypair"
33-
when: "not gitlab_runner_is_initial_dryrun" # skip if run for the first time in check mode
32+
register: "__gitlab_runner_ssh_keypair"
33+
when: "not __gitlab_runner_is_initial_dryrun" # skip if run for the first time in check mode
3434

3535
- name: "Download and install container-linux-config-transpiler"
3636
ansible.builtin.get_url:
@@ -46,53 +46,55 @@
4646
owner: "root"
4747
group: "root"
4848
mode: "0644"
49-
register: "flatcar_config_task"
50-
when: "not gitlab_runner_is_initial_dryrun" # skip if run for the first time in check mode
49+
register: "__flatcar_config_task"
50+
when: "not __gitlab_runner_is_initial_dryrun" # skip if run for the first time in check mode
5151
notify:
5252
- "Transpile the flatcar linux configuration"
5353

5454
- name: "Check if ignition.json is available and create it in any case"
55-
when: "not flatcar_config_task.changed" # noqa no-handler
55+
when: "not __flatcar_config_task.changed" # noqa no-handler
5656
ansible.builtin.stat:
5757
path: "/etc/gitlab-runner/ignition.json"
58-
register: "ignition_exists"
59-
changed_when: "not ignition_exists.stat.exists"
58+
register: "__ignition_exists"
59+
changed_when: "not __ignition_exists.stat.exists"
6060
notify:
6161
- "Transpile the flatcar linux configuration"
6262

6363
# This block is required to prepare for possible updates of the transpiler
6464
# tool resulting in a different result. Also this helps to fix any kind of
6565
# manual manipulation.
6666
- name: "Check if ignition.json is up-to-date"
67-
when: "not flatcar_config_task.changed and ignition_exists.stat.exists" # noqa no-handler
67+
when:
68+
- "not __flatcar_config_task.changed"
69+
- "__ignition_exists.stat.exists"
6870
block:
6971
- name: "Create temporary directory"
7072
ansible.builtin.tempfile:
7173
state: "directory"
7274
suffix: "ignition"
73-
register: "temp_directory"
75+
register: "__temp_directory"
7476
changed_when: false
7577
check_mode: false
7678

7779
- name: "Dry-run of transpile the flatcar linux configuration"
78-
ansible.builtin.command: "butane -o {{ (temp_directory.path, 'ignition.json') | path_join }} /etc/gitlab-runner/butane-config.bu"
80+
ansible.builtin.command: "butane -o {{ (__temp_directory.path, 'ignition.json') | path_join }} /etc/gitlab-runner/butane-config.bu"
7981
changed_when: false
8082
check_mode: false
8183

8284
- name: "Stat temporary ignition.json file"
8385
ansible.builtin.stat:
84-
path: "{{ (temp_directory.path, 'ignition.json') | path_join }}"
85-
register: "temp_ignition_stats"
86+
path: "{{ (__temp_directory.path, 'ignition.json') | path_join }}"
87+
register: "__temp_ignition_stats"
8688
changed_when:
87-
- "temp_ignition_stats.stat.checksum != ignition_exists.stat.checksum"
89+
- "__temp_ignition_stats.stat.checksum != __ignition_exists.stat.checksum"
8890
check_mode: false
8991
notify:
9092
- "Transpile the flatcar linux configuration"
9193

9294
always:
9395
- name: "Remove temporary directory"
9496
ansible.builtin.file:
95-
path: "{{ temp_directory.path }}"
97+
path: "{{ __temp_directory.path }}"
9698
state: "absent"
9799
changed_when: false
98100
check_mode: false

roles/gitlab_runner/tasks/docker-machine-init.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@
77
- name: "Check if docker-machine initialization is necessary"
88
ansible.builtin.stat:
99
path: "/root/.docker/machine/certs/ca.pem"
10-
register: "docker_machine_config"
10+
register: "__docker_machine_config"
1111

1212
- name: "Initialize docker-machine once"
13-
when: "not docker_machine_config.stat.exists"
13+
when: "not __docker_machine_config.stat.exists"
1414
block:
1515
- name: "Extract machine options as command line parameters"
1616
ansible.builtin.set_fact:
17-
machine_options: "--{{ gitlab_runner.machine_options | join(' --') }}"
17+
__machine_options: "--{{ gitlab_runner.machine_options | join(' --') }}"
1818

1919
- name: "Create a VM once via docker-machine"
2020
when: "not ansible_check_mode"
21-
ansible.builtin.command: "docker-machine create -d {{ gitlab_runner.machine_driver }} {{ machine_options }} test"
22-
register: "creation_cmd"
23-
changed_when: "creation_cmd.rc == 0"
21+
ansible.builtin.command: "docker-machine create -d {{ gitlab_runner.machine_driver }} {{ __machine_options }} test"
22+
register: "__creation_cmd"
23+
changed_when: "__creation_cmd.rc == 0"
2424
tags: "notest"
2525

2626
always:
2727
- name: "Remove the VM"
2828
when: "not ansible_check_mode"
2929
ansible.builtin.command: "docker-machine rm -y --force test"
30-
register: "removal_cmd"
31-
changed_when: "removal_cmd.rc == 0"
30+
register: "__removal_cmd"
31+
changed_when: "__removal_cmd.rc == 0"
3232
failed_when: false
3333
tags: "notest"
3434
...

roles/gitlab_runner/tasks/install.autoscaler-plugin.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77
- name: "Check if fleeting-plugin-openstack is installed"
88
ansible.builtin.stat:
99
path: "/usr/local/bin/fleeting-plugin-openstack"
10-
register: "_fleeting_plugin_openstack_stat"
10+
register: "__fleeting_plugin_openstack_stat"
1111

1212
- name: "Check version of installed fleeting plugin"
13-
when: "_fleeting_plugin_openstack_stat.stat.exists"
13+
when: "__fleeting_plugin_openstack_stat.stat.exists"
1414
ansible.builtin.shell:
1515
cmd: |
1616
set -o pipefail
1717
strings /usr/local/bin/fleeting-plugin-openstack | grep -oP "(?<=fleeting-plugin-openstack.Version=)(\d+\.\d+\.\d+)" | head -n 1
1818
executable: "/bin/bash"
19-
register: "_fleeting_plugin_version_installed"
19+
register: "__fleeting_plugin_version_installed"
2020
changed_when: false
2121
check_mode: false
2222

2323
- name: "Download and install fleeting plugin"
24-
when: "not _fleeting_plugin_openstack_stat.stat.exists or _fleeting_plugin_version_installed.stdout != gitlab_runner_autoscaler_binary_version"
24+
when: "not __fleeting_plugin_openstack_stat.stat.exists or __fleeting_plugin_version_installed.stdout != gitlab_runner_autoscaler_binary_version"
2525
block:
2626
- name: "Create temporary directory"
2727
ansible.builtin.tempfile:

roles/gitlab_runner/tasks/install.debianlike.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
update_cache: true
4747
allow_downgrade: true
4848
when:
49-
- "not gitlab_runner_is_initial_dryrun" # skip if run for the first time in check mode
49+
- "not __gitlab_runner_is_initial_dryrun" # skip if run for the first time in check mode
5050
- "gitlab_runner_version is version('17.7.0', 'ge') or gitlab_runner_version | length == 0"
5151

5252
- name: "Install gitlab-runner with downgrade option"
@@ -55,7 +55,7 @@
5555
state: "present"
5656
update_cache: true
5757
allow_downgrade: true
58-
when: "not gitlab_runner_is_initial_dryrun" # skip if run for the first time in check mode
58+
when: "not __gitlab_runner_is_initial_dryrun" # skip if run for the first time in check mode
5959

6060
- name: "Gather the package facts"
6161
ansible.builtin.package_facts:

roles/gitlab_runner/tasks/main.yml

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,29 @@
99

1010
- name: "Set variable if autoscaling runner must be configured"
1111
ansible.builtin.set_fact:
12-
gitlab_runner_install_docker_machine: "{{ gitlab_runner_list | selectattr('executor', 'equalto', 'docker+machine') | list | length > 0 }}"
13-
gitlab_runner_install_autoscaler: "{{ gitlab_runner_list | selectattr('executor', 'equalto', 'docker-autoscaler') | list | length > 0 }}"
12+
__gitlab_runner_install_docker_machine: "{{ gitlab_runner_list | selectattr('executor', 'equalto', 'docker+machine') | list | length > 0 }}"
13+
__gitlab_runner_install_autoscaler: "{{ gitlab_runner_list | selectattr('executor', 'equalto', 'docker-autoscaler') | list | length > 0 }}"
1414

1515
- name: "Check if directory /etc/gitlab-runner already exists"
1616
ansible.builtin.stat:
1717
path: "/etc/gitlab-runner"
18-
register: "gitlab_runner_dir"
18+
register: "__gitlab_runner_dir"
1919

2020
- name: "Determine if this is an initial dry-run"
2121
ansible.builtin.set_fact:
22-
gitlab_runner_is_initial_dryrun: "{{ ansible_check_mode and not gitlab_runner_dir.stat.exists }}"
22+
__gitlab_runner_is_initial_dryrun: "{{ ansible_check_mode and not __gitlab_runner_dir.stat.exists }}"
2323

2424
- name: "Include docker-machine tasks"
2525
ansible.builtin.include_tasks: "install.docker-machine.yml"
26-
when: "gitlab_runner_install_docker_machine"
26+
when: "__gitlab_runner_install_docker_machine"
2727

2828
- name: "Include installation tasks for Debian-like OS"
2929
ansible.builtin.include_tasks: "install.debianlike.yml"
3030
when: "ansible_os_family == 'Debian'"
3131

3232
- name: "Include autoscaler install tasks"
3333
ansible.builtin.include_tasks: "install.autoscaler-plugin.yml"
34-
when: "gitlab_runner_install_autoscaler"
34+
when: "__gitlab_runner_install_autoscaler"
3535

3636
- name: "Include tasks to configure the system"
3737
ansible.builtin.include_tasks: "configuration.yml"
@@ -41,7 +41,7 @@
4141

4242
- name: "Initialize docker-machine"
4343
ansible.builtin.include_tasks: "docker-machine-init.yml"
44-
when: "gitlab_runner_install_docker_machine"
44+
when: "__gitlab_runner_install_docker_machine"
4545
no_log: true
4646
loop: "{{ gitlab_runner_list }}"
4747
loop_control:
@@ -50,10 +50,10 @@
5050
- name: "Slurp ignition json"
5151
ansible.builtin.slurp:
5252
src: "/etc/gitlab-runner/ignition.json"
53-
register: "ignition_json"
53+
register: "__ignition_json"
5454
when:
55-
- "gitlab_runner_install_autoscaler"
56-
- "not gitlab_runner_is_initial_dryrun"
55+
- "__gitlab_runner_install_autoscaler"
56+
- "not __gitlab_runner_is_initial_dryrun"
5757

5858
- name: "Template config file"
5959
ansible.builtin.template:
@@ -65,14 +65,13 @@
6565
notify: "Restart GitLab-Runner"
6666
no_log: true
6767
vars:
68-
ignition_content: "{{ ignition_json['content'] | b64decode }}"
69-
when: "not gitlab_runner_is_initial_dryrun"
68+
__ignition_content: "{{ __ignition_json['content'] | b64decode }}"
69+
when: "not __gitlab_runner_is_initial_dryrun"
7070

7171
- name: "Start GitLab-Runner"
7272
ansible.builtin.service:
7373
name: "gitlab-runner"
7474
state: "started"
75-
when: "not gitlab_runner_is_initial_dryrun"
76-
75+
when: "not __gitlab_runner_is_initial_dryrun"
7776

7877
...

roles/gitlab_runner/templates/butane-config.bu.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ passwd:
1010
users:
1111
- name: core
1212
ssh_authorized_keys:
13-
- {{ gitlab_runner_ssh_keypair.public_key }}
13+
- {{ __gitlab_runner_ssh_keypair.public_key }}
1414
storage:
1515
files:
1616
- path: /etc/resolv.conf

roles/gitlab_runner/templates/config.toml.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ sentry_dsn = "{{ gitlab_runner_sentry_dsn }}"
114114
networks = [ { uuid = "{{ runner.autoscaler_network_id }}" } ]
115115
security_groups = [ "{{ runner.autoscaler_security_group }}" ]
116116
scheduler_hints = { group = "{{ runner.autoscaler_scheduler_hint }}" }
117-
user_data = '{{ ignition_content | to_json }}'
117+
user_data = '{{ __ignition_content | to_json }}'
118118

119119
[runners.autoscaler.connector_config]
120120
username = "{{ runner.autoscaler_username }}"

0 commit comments

Comments
 (0)