diff --git a/roles/gitlab_runner/handlers/main.yml b/roles/gitlab_runner/handlers/main.yml index fbc2ad4..c1b044d 100644 --- a/roles/gitlab_runner/handlers/main.yml +++ b/roles/gitlab_runner/handlers/main.yml @@ -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" ... diff --git a/roles/gitlab_runner/tasks/configuration.yml b/roles/gitlab_runner/tasks/configuration.yml index 64d660f..a88ed69 100644 --- a/roles/gitlab_runner/tasks/configuration.yml +++ b/roles/gitlab_runner/tasks/configuration.yml @@ -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: @@ -46,17 +46,17 @@ 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" @@ -64,27 +64,29 @@ # 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" @@ -92,7 +94,7 @@ always: - name: "Remove temporary directory" ansible.builtin.file: - path: "{{ temp_directory.path }}" + path: "{{ __temp_directory.path }}" state: "absent" changed_when: false check_mode: false diff --git a/roles/gitlab_runner/tasks/docker-machine-init.yml b/roles/gitlab_runner/tasks/docker-machine-init.yml index 2f9cdcb..7ba3ca4 100644 --- a/roles/gitlab_runner/tasks/docker-machine-init.yml +++ b/roles/gitlab_runner/tasks/docker-machine-init.yml @@ -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" ... diff --git a/roles/gitlab_runner/tasks/install.autoscaler-plugin.yml b/roles/gitlab_runner/tasks/install.autoscaler-plugin.yml index bb107d8..ffc01a6 100644 --- a/roles/gitlab_runner/tasks/install.autoscaler-plugin.yml +++ b/roles/gitlab_runner/tasks/install.autoscaler-plugin.yml @@ -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: diff --git a/roles/gitlab_runner/tasks/install.debianlike.yml b/roles/gitlab_runner/tasks/install.debianlike.yml index 395ba80..4c68c94 100644 --- a/roles/gitlab_runner/tasks/install.debianlike.yml +++ b/roles/gitlab_runner/tasks/install.debianlike.yml @@ -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" @@ -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: diff --git a/roles/gitlab_runner/tasks/main.yml b/roles/gitlab_runner/tasks/main.yml index 2471ff3..9105819 100644 --- a/roles/gitlab_runner/tasks/main.yml +++ b/roles/gitlab_runner/tasks/main.yml @@ -9,21 +9,21 @@ - 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" @@ -31,7 +31,7 @@ - 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" @@ -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: @@ -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: @@ -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" ... diff --git a/roles/gitlab_runner/templates/butane-config.bu.j2 b/roles/gitlab_runner/templates/butane-config.bu.j2 index fe6a8cd..ee0e12d 100644 --- a/roles/gitlab_runner/templates/butane-config.bu.j2 +++ b/roles/gitlab_runner/templates/butane-config.bu.j2 @@ -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 diff --git a/roles/gitlab_runner/templates/config.toml.j2 b/roles/gitlab_runner/templates/config.toml.j2 index d49e4af..a46e36e 100644 --- a/roles/gitlab_runner/templates/config.toml.j2 +++ b/roles/gitlab_runner/templates/config.toml.j2 @@ -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 }}"