Skip to content

Commit 82a4b57

Browse files
committed
gitlab-runner: Add explicit become directives
Signed-off-by: Norman Ziegner <[email protected]>
1 parent 06fa457 commit 82a4b57

File tree

7 files changed

+27
-0
lines changed

7 files changed

+27
-0
lines changed

roles/gitlab_runner/handlers/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
---
77

88
- name: "Transpile the flatcar linux configuration"
9+
become: true
910
ansible.builtin.command: "butane -o /etc/gitlab-runner/ignition.json /etc/gitlab-runner/butane-config.bu"
1011
changed_when: true
1112

1213
- name: "Restart GitLab-Runner"
14+
become: true
1315
ansible.builtin.service:
1416
name: "gitlab-runner"
1517
state: "restarted"

roles/gitlab_runner/tasks/configuration.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- "gitlab_runner_ssh_private_key | default('') | length > 0"
1111
block:
1212
- name: "Place SSH public key on the host for communicating with Runners."
13+
become: true
1314
ansible.builtin.copy:
1415
src: "{{ gitlab_runner_ssh_public_key }}"
1516
dest: "{{ gitlab_runner_ssh_public_key_path }}"
@@ -18,6 +19,7 @@
1819
mode: "0644"
1920

2021
- name: "Place SSH private key on the host for communicating with Runners."
22+
become: true
2123
ansible.builtin.copy:
2224
src: "{{ gitlab_runner_ssh_private_key }}"
2325
dest: "{{ gitlab_runner_ssh_private_key_path }}"
@@ -26,20 +28,23 @@
2628
mode: "0600"
2729

2830
- name: "Create SSH key pair for communicating with Runners."
31+
become: true
2932
community.crypto.openssh_keypair: # noqa: args[module]
3033
path: "{{ gitlab_runner_ssh_private_key_path }}"
3134
type: "{{ gitlab_runner_ssh_key_type | default('ed25519') }}"
3235
register: "__gitlab_runner_ssh_keypair"
3336
when: "not __gitlab_runner_is_initial_dryrun" # skip if run for the first time in check mode
3437

3538
- name: "Download and install container-linux-config-transpiler"
39+
become: true
3640
ansible.builtin.get_url:
3741
url: "{{ gitlab_runner_transpiler_binary_url }}"
3842
dest: "/usr/local/bin/butane"
3943
mode: "0755"
4044
checksum: "{{ gitlab_runner_transpiler_binary_checksum }}"
4145

4246
- name: "Place the container linux configuration on the host"
47+
become: true
4348
ansible.builtin.template:
4449
src: "{{ gitlab_runner_butane_config_template }}"
4550
dest: "/etc/gitlab-runner/butane-config.bu"
@@ -52,6 +57,7 @@
5257
- "Transpile the flatcar linux configuration"
5358

5459
- name: "Check if ignition.json is available and create it in any case"
60+
become: true
5561
when: "not __flatcar_config_task.changed" # noqa no-handler
5662
ansible.builtin.stat:
5763
path: "/etc/gitlab-runner/ignition.json"
@@ -77,11 +83,13 @@
7783
check_mode: false
7884

7985
- name: "Dry-run of transpile the flatcar linux configuration"
86+
become: true
8087
ansible.builtin.command: "butane -o {{ (__temp_directory.path, 'ignition.json') | path_join }} /etc/gitlab-runner/butane-config.bu"
8188
changed_when: false
8289
check_mode: false
8390

8491
- name: "Stat temporary ignition.json file"
92+
become: true
8593
ansible.builtin.stat:
8694
path: "{{ (__temp_directory.path, 'ignition.json') | path_join }}"
8795
register: "__temp_ignition_stats"

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
---
77
- name: "Check if docker-machine initialization is necessary"
8+
become: true
89
ansible.builtin.stat:
910
path: "/root/.docker/machine/certs/ca.pem"
1011
register: "__docker_machine_config"
@@ -17,6 +18,7 @@
1718
__machine_options: "--{{ gitlab_runner.machine_options | join(' --') }}"
1819

1920
- name: "Create a VM once via docker-machine"
21+
become: true
2022
when: "not ansible_check_mode"
2123
ansible.builtin.command: "docker-machine create -d {{ gitlab_runner.machine_driver }} {{ __machine_options }} test"
2224
register: "__creation_cmd"
@@ -25,6 +27,7 @@
2527

2628
always:
2729
- name: "Remove the VM"
30+
become: true
2831
when: "not ansible_check_mode"
2932
ansible.builtin.command: "docker-machine rm -y --force test"
3033
register: "__removal_cmd"

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
changed_when: false
3232

3333
- name: "Download fleeting-plugin-openstack"
34+
become: true
3435
ansible.builtin.get_url:
3536
url: "{{ gitlab_runner_autoscaler_plugin_url }}"
3637
dest: "{{ (__tempdir_fleeting_plugin.path, 'fleeting-plugin-openstack.tar.gz') | path_join }}"
@@ -41,6 +42,7 @@
4142
check_mode: false
4243

4344
- name: "Extract fleeting-plugin-openstack binary"
45+
become: true
4446
ansible.builtin.unarchive:
4547
src: "{{ (__tempdir_fleeting_plugin.path, 'fleeting-plugin-openstack.tar.gz') | path_join }}"
4648
dest: "/usr/local/bin/"
@@ -61,6 +63,7 @@
6163
changed_when: false
6264

6365
- name: "Place clouds.yaml template"
66+
become: true
6467
ansible.builtin.template:
6568
src: "clouds.yaml.j2"
6669
dest: "/etc/gitlab-runner/clouds.yaml"

roles/gitlab_runner/tasks/install.debianlike.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
---
77

88
- name: "Install GitLab-Runner dependencies"
9+
become: true
910
ansible.builtin.apt:
1011
pkg:
1112
- "debian-archive-keyring"
@@ -20,6 +21,7 @@
2021

2122
block:
2223
- name: "Add packages repository packages.gitlab.com/runner/gitlab-runner"
24+
become: true
2325
ansible.builtin.deb822_repository:
2426
name: "gitlab-runner"
2527
types: "deb"
@@ -31,6 +33,7 @@
3133
enabled: true
3234

3335
- name: "Use APT pinning for Debian os"
36+
become: true
3437
ansible.builtin.template:
3538
src: "pin-gitlab-runner.pref.j2"
3639
dest: "/etc/apt/preferences.d/pin-gitlab-runner.pref"
@@ -40,6 +43,7 @@
4043
when: "ansible_facts.distribution == 'Debian'"
4144

4245
- name: "Install gitlab-runner-helper-images with downgrade option"
46+
become: true
4347
ansible.builtin.apt:
4448
name: "{{ gitlab_runner_helper_images_package_name }}"
4549
state: "present"
@@ -50,6 +54,7 @@
5054
- "gitlab_runner_version is version('17.7.0', 'ge') or gitlab_runner_version | length == 0"
5155

5256
- name: "Install gitlab-runner with downgrade option"
57+
become: true
5358
ansible.builtin.apt:
5459
name: "{{ gitlab_runner_package_name }}"
5560
state: "present"
@@ -69,12 +74,14 @@
6974
block:
7075

7176
- name: "Install gitlab-runner-helper-images from a .deb file"
77+
become: true
7278
ansible.builtin.apt:
7379
deb: "{{ gitlab_runner_helper_images_deb_file }}"
7480
allow_downgrade: true
7581
when: "gitlab_runner_version is version('17.7.0', 'ge') or gitlab_runner_version | length == 0"
7682

7783
- name: "Install gitlab-runner from a .deb file"
84+
become: true
7885
ansible.builtin.apt:
7986
deb: "{{ gitlab_runner_deb_file }}"
8087
allow_downgrade: true

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
---
77
- name: "Download and install docker-machine binary"
8+
become: true
89
ansible.builtin.get_url:
910
url: "{{ gitlab_runner_docker_machine_binary_url }}"
1011
dest: "/usr/local/bin/docker-machine"

roles/gitlab_runner/tasks/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
loop_var: "gitlab_runner"
4949

5050
- name: "Slurp ignition json"
51+
become: true
5152
ansible.builtin.slurp:
5253
src: "/etc/gitlab-runner/ignition.json"
5354
register: "__ignition_json"
@@ -56,6 +57,7 @@
5657
- "not __gitlab_runner_is_initial_dryrun"
5758

5859
- name: "Template config file"
60+
become: true
5961
ansible.builtin.template:
6062
src: "config.toml.j2"
6163
dest: "{{ gitlab_runner_config_path }}"
@@ -69,6 +71,7 @@
6971
when: "not __gitlab_runner_is_initial_dryrun"
7072

7173
- name: "Start GitLab-Runner"
74+
become: true
7275
ansible.builtin.service:
7376
name: "gitlab-runner"
7477
state: "started"

0 commit comments

Comments
 (0)