Skip to content

GitLab-runner role: prefix all internal variables with '__' #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion roles/gitlab_runner/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
ansible.builtin.service:
name: "gitlab-runner"
state: "restarted"
when: "not gitlab_runner_is_initial_dryrun"
when: "not __gitlab_runner_is_initial_dryrun"

...
30 changes: 16 additions & 14 deletions roles/gitlab_runner/tasks/configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
community.crypto.openssh_keypair: # noqa: args[module]
path: "{{ gitlab_runner_ssh_private_key_path }}"
type: "{{ gitlab_runner_ssh_key_type | default('ed25519') }}"
register: "gitlab_runner_ssh_keypair"
when: "not gitlab_runner_is_initial_dryrun" # skip if run for the first time in check mode
register: "__gitlab_runner_ssh_keypair"
when: "not __gitlab_runner_is_initial_dryrun" # skip if run for the first time in check mode

- name: "Download and install container-linux-config-transpiler"
ansible.builtin.get_url:
Expand All @@ -46,53 +46,55 @@
owner: "root"
group: "root"
mode: "0644"
register: "flatcar_config_task"
when: "not gitlab_runner_is_initial_dryrun" # skip if run for the first time in check mode
register: "__flatcar_config_task"
when: "not __gitlab_runner_is_initial_dryrun" # skip if run for the first time in check mode
notify:
- "Transpile the flatcar linux configuration"

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

# This block is required to prepare for possible updates of the transpiler
# tool resulting in a different result. Also this helps to fix any kind of
# manual manipulation.
- name: "Check if ignition.json is up-to-date"
when: "not flatcar_config_task.changed and ignition_exists.stat.exists" # noqa no-handler
when:
- "not __flatcar_config_task.changed"
- "__ignition_exists.stat.exists"
block:
- name: "Create temporary directory"
ansible.builtin.tempfile:
state: "directory"
suffix: "ignition"
register: "temp_directory"
register: "__temp_directory"
changed_when: false
check_mode: false

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

- name: "Stat temporary ignition.json file"
ansible.builtin.stat:
path: "{{ (temp_directory.path, 'ignition.json') | path_join }}"
register: "temp_ignition_stats"
path: "{{ (__temp_directory.path, 'ignition.json') | path_join }}"
register: "__temp_ignition_stats"
changed_when:
- "temp_ignition_stats.stat.checksum != ignition_exists.stat.checksum"
- "__temp_ignition_stats.stat.checksum != __ignition_exists.stat.checksum"
check_mode: false
notify:
- "Transpile the flatcar linux configuration"

always:
- name: "Remove temporary directory"
ansible.builtin.file:
path: "{{ temp_directory.path }}"
path: "{{ __temp_directory.path }}"
state: "absent"
changed_when: false
check_mode: false
16 changes: 8 additions & 8 deletions roles/gitlab_runner/tasks/docker-machine-init.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@
- name: "Check if docker-machine initialization is necessary"
ansible.builtin.stat:
path: "/root/.docker/machine/certs/ca.pem"
register: "docker_machine_config"
register: "__docker_machine_config"

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

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

always:
- name: "Remove the VM"
when: "not ansible_check_mode"
ansible.builtin.command: "docker-machine rm -y --force test"
register: "removal_cmd"
changed_when: "removal_cmd.rc == 0"
register: "__removal_cmd"
changed_when: "__removal_cmd.rc == 0"
failed_when: false
tags: "notest"
...
8 changes: 4 additions & 4 deletions roles/gitlab_runner/tasks/install.autoscaler-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
- name: "Check if fleeting-plugin-openstack is installed"
ansible.builtin.stat:
path: "/usr/local/bin/fleeting-plugin-openstack"
register: "_fleeting_plugin_openstack_stat"
register: "__fleeting_plugin_openstack_stat"

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

- name: "Download and install fleeting plugin"
when: "not _fleeting_plugin_openstack_stat.stat.exists or _fleeting_plugin_version_installed.stdout != gitlab_runner_autoscaler_binary_version"
when: "not __fleeting_plugin_openstack_stat.stat.exists or __fleeting_plugin_version_installed.stdout != gitlab_runner_autoscaler_binary_version"
block:
- name: "Create temporary directory"
ansible.builtin.tempfile:
Expand Down
4 changes: 2 additions & 2 deletions roles/gitlab_runner/tasks/install.debianlike.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
update_cache: true
allow_downgrade: true
when:
- "not gitlab_runner_is_initial_dryrun" # skip if run for the first time in check mode
- "not __gitlab_runner_is_initial_dryrun" # skip if run for the first time in check mode
- "gitlab_runner_version is version('17.7.0', 'ge') or gitlab_runner_version | length == 0"

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

- name: "Gather the package facts"
ansible.builtin.package_facts:
Expand Down
27 changes: 13 additions & 14 deletions roles/gitlab_runner/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@

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

- name: "Check if directory /etc/gitlab-runner already exists"
ansible.builtin.stat:
path: "/etc/gitlab-runner"
register: "gitlab_runner_dir"
register: "__gitlab_runner_dir"

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

- name: "Include docker-machine tasks"
ansible.builtin.include_tasks: "install.docker-machine.yml"
when: "gitlab_runner_install_docker_machine"
when: "__gitlab_runner_install_docker_machine"

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

- name: "Include autoscaler install tasks"
ansible.builtin.include_tasks: "install.autoscaler-plugin.yml"
when: "gitlab_runner_install_autoscaler"
when: "__gitlab_runner_install_autoscaler"

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

- name: "Initialize docker-machine"
ansible.builtin.include_tasks: "docker-machine-init.yml"
when: "gitlab_runner_install_docker_machine"
when: "__gitlab_runner_install_docker_machine"
no_log: true
loop: "{{ gitlab_runner_list }}"
loop_control:
Expand All @@ -50,10 +50,10 @@
- name: "Slurp ignition json"
ansible.builtin.slurp:
src: "/etc/gitlab-runner/ignition.json"
register: "ignition_json"
register: "__ignition_json"
when:
- "gitlab_runner_install_autoscaler"
- "not gitlab_runner_is_initial_dryrun"
- "__gitlab_runner_install_autoscaler"
- "not __gitlab_runner_is_initial_dryrun"

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

- name: "Start GitLab-Runner"
ansible.builtin.service:
name: "gitlab-runner"
state: "started"
when: "not gitlab_runner_is_initial_dryrun"

when: "not __gitlab_runner_is_initial_dryrun"

...
2 changes: 1 addition & 1 deletion roles/gitlab_runner/templates/butane-config.bu.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ passwd:
users:
- name: core
ssh_authorized_keys:
- {{ gitlab_runner_ssh_keypair.public_key }}
- {{ __gitlab_runner_ssh_keypair.public_key }}
storage:
files:
- path: /etc/resolv.conf
Expand Down
2 changes: 1 addition & 1 deletion roles/gitlab_runner/templates/config.toml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ sentry_dsn = "{{ gitlab_runner_sentry_dsn }}"
networks = [ { uuid = "{{ runner.autoscaler_network_id }}" } ]
security_groups = [ "{{ runner.autoscaler_security_group }}" ]
scheduler_hints = { group = "{{ runner.autoscaler_scheduler_hint }}" }
user_data = '{{ ignition_content | to_json }}'
user_data = '{{ __ignition_content | to_json }}'

[runners.autoscaler.connector_config]
username = "{{ runner.autoscaler_username }}"
Expand Down