Skip to content

Commit ad3ab80

Browse files
committed
feat(reproducer): Remove hardcoded zuul user and /home/zuul paths
It was already technically possible to create a controller-0 vm with a non-zuul user. This commit enables configuring controller-0 with a non-zuul user by using controller-0's `ansible_ssh_user` from `hostvars` in place of hardcoded `'zuul'`. It is worth noting that we can't simply use vars like ansible_user_id or ansible_user_dir with tasks that are delgated to controller-0. If the host we are running the reproducer from has a different user from controller-0, these vars will try to use the user from the machine that is running the reproducer rather than controller-0's user. For example, let's say we are running the reproducer from a machine with the user 'exampleuser' and we have the user 'zuul' on controller-0. If we have some task that is delegated to controller-0 and tries to create some file in the controller-0 user's home directory, we can't simply do: ``` - name: Create some file delegate_to: controller-0 ansible.builtin.file: path: "{{ ansible_user_dir }}/some_file.txt" state: touch ``` `ansible_user_dir` resolves to `/home/exampleuser`. This path does not exist on controller-0, so this task would fail.
1 parent 8ca944b commit ad3ab80

File tree

13 files changed

+127
-151
lines changed

13 files changed

+127
-151
lines changed

roles/reproducer/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ None
66

77
## Parameters
88

9-
* `cifmw_reproducer_user`: (String) User used for reproducer role. Defaults to `zuul`
109
* `cifmw_reproducer_basedir`: (String) Base directory. Defaults to `cifmw_basedir`, which defaults to `~/ci-framework-data`.
10+
* `cifmw_reproducer_controller_user`: (String) User on controller-0. Defaults to `ansible_ssh_user` from controller-0's `hostvars` if available, otherwise defaults to `zuul`.
11+
* `cifmw_reproducer_controller_user_dir`: (String) Controller-0 user's home dir. Defaults to `/home/{{ cifmw_reproducer_controller_user }}`
12+
* `cifmw_reproducer_controller_basedir`: (String) Path to the `ci-framework-data` dir on controller-0. Defaults to `"{{ cifmw_reproducer_controller_user_dir }}/ci-framework-data"`
1113
* `cifmw_reproducer_compute_repos`: (List[mapping]) List of yum repository that must be deployed on the compute nodes during their creation. Defaults to `[]`.
1214
* `cifmw_reproducer_compute_set_repositories`: (Bool) Deploy repositories (rhos-release) on Compute nodes. Defaults to `true`.
1315
* `cifmw_reproducer_play_extravars`: (List[string]) List of extra-vars you want to pass down to the EDPM deployment playbooks. Defaults to `[]`.

roles/reproducer/defaults/main.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
# All variables intended for modification should be placed in this file.
1919
# All variables within this role should have a prefix of "cifmw_reproducer"
20-
cifmw_reproducer_user: "{{ ansible_user | default('zuul') }}"
20+
cifmw_reproducer_controller_user: "{{ hostvars['controller-0']['ansible_ssh_user'] | default('zuul') }}"
21+
cifmw_reproducer_controller_user_dir: "/home/{{ cifmw_reproducer_controller_user }}"
22+
cifmw_reproducer_controller_basedir: "{{ cifmw_reproducer_controller_user_dir }}/ci-framework-data"
2123
cifmw_reproducer_basedir: "{{ cifmw_basedir | default( ansible_user_dir ~ '/ci-framework-data') }}"
2224
cifmw_reproducer_src_dir: "{{ cifmw_ci_src_dir | default( ansible_user_dir ~ '/src') }}"
2325
cifmw_reproducer_kubecfg: "{{ cifmw_libvirt_manager_configuration.vms.crc.image_local_dir }}/kubeconfig"
@@ -40,13 +42,6 @@ cifmw_reproducer_supported_hypervisor_os:
4042
minimum_version: 9
4143
RedHat:
4244
minimum_version: 9.3
43-
cifmw_reproducer_controller_basedir: >-
44-
{{
45-
(
46-
'/home/zuul',
47-
'ci-framework-data',
48-
) | path_join
49-
}}
5045

5146
# Allow to disable validations - user toggle this at their
5247
# own risks!

roles/reproducer/tasks/ci_job.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,26 @@
2323
block:
2424
- name: Ensure directory exists
2525
ansible.builtin.file:
26-
path: "/home/zuul/{{ job_id }}-params"
26+
path: "{{ cifmw_reproducer_controller_user_dir }}/{{ job_id }}-params"
2727
mode: "0755"
2828
state: directory
29-
owner: "{{ cifmw_reproducer_user }}"
30-
group: "{{ cifmw_reproducer_user }}"
29+
owner: "{{ cifmw_reproducer_controller_user }}"
30+
group: "{{ cifmw_reproducer_controller_user }}"
3131

3232
- name: Copy environment files to controller node
3333
tags:
3434
- bootstrap
3535
ansible.builtin.copy:
3636
src: "{{ _reproducer_basedir }}/parameters/"
37-
dest: "/home/zuul/{{ job_id }}-params"
37+
dest: "{{ cifmw_reproducer_controller_user_dir }}/{{ job_id }}-params"
3838
mode: "0644"
3939

4040
- name: Inject reproducer dedicated parameter file
4141
tags:
4242
- bootstrap
4343
ansible.builtin.template:
4444
src: "reproducer_params.yml.j2"
45-
dest: "/home/zuul/{{ job_id }}-params/reproducer_params.yml"
45+
dest: "{{ cifmw_reproducer_controller_user_dir }}/{{ job_id }}-params/reproducer_params.yml"
4646
mode: "0644"
4747

4848
- name: Generate CI job playbook
@@ -70,7 +70,7 @@
7070
tags:
7171
- bootstrap
7272
ansible.builtin.copy:
73-
dest: /home/zuul/zuul-network-data.yml
73+
dest: "{{ cifmw_reproducer_controller_user_dir }}/zuul-network-data.yml"
7474
content: "{{ {'job_network': ci_job_networking} | to_nice_yaml}}"
7575
mode: "0644"
7676

@@ -96,7 +96,7 @@
9696
items2dict
9797
}}
9898
ansible.builtin.copy:
99-
dest: "/home/zuul/ci-framework-data/artifacts/parameters/zuul-params.yml"
99+
dest: "{{ cifmw_reproducer_controller_basedir }}/artifacts/parameters/zuul-params.yml"
100100
content: "{{ {'zuul': zuul_params_filtered} | to_nice_yaml }}"
101101
mode: "0644"
102102

@@ -105,14 +105,14 @@
105105
- always
106106
ansible.builtin.include_tasks: rotate_log.yml
107107
loop:
108-
- "/home/zuul/ansible.log"
109-
- "/home/zuul/ansible-pre-ci.log"
110-
- "/home/zuul/ansible-{{ job_id }}.log"
111-
- "/home/zuul/ansible-content-provider-bootstrap.log"
108+
- "{{ cifmw_reproducer_controller_user_dir }}/ansible.log"
109+
- "{{ cifmw_reproducer_controller_user_dir }}/ansible-pre-ci.log"
110+
- "{{ cifmw_reproducer_controller_user_dir }}/ansible-{{ job_id }}.log"
111+
- "{{ cifmw_reproducer_controller_user_dir }}/ansible-content-provider-bootstrap.log"
112112

113113
- name: Generate and run scripts
114114
vars:
115-
_home: "/home/zuul"
115+
_home: "{{ cifmw_reproducer_controller_user_dir }}"
116116
run_directory: "{{ _cifmw_reproducer_framework_location }}"
117117
block:
118118
- name: Generate pre-ci-play script

roles/reproducer/tasks/configure_architecture.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
vars:
77
run_directory: "{{ _cifmw_reproducer_framework_location }}"
88
exports:
9-
ANSIBLE_LOG_PATH: "{{ ansible_user_dir }}/ci-framework-data/logs/ansible-deploy-architecture.log"
9+
ANSIBLE_LOG_PATH: "{{ cifmw_reproducer_controller_basedir }}/logs/ansible-deploy-architecture.log"
1010
default_extravars:
1111
- "@~/ci-framework-data/parameters/reproducer-variables.yml"
1212
- "@~/ci-framework-data/parameters/openshift-environment.yml"
1313
extravars: "{{ cifmw_reproducer_play_extravars }}"
1414
playbook: "deploy-edpm.yml"
1515
ansible.builtin.template:
16-
dest: "/home/zuul/deploy-architecture.sh"
16+
dest: "{{ cifmw_reproducer_controller_user_dir }}/deploy-architecture.sh"
1717
src: "script.sh.j2"
1818
mode: "0755"
19-
owner: "zuul"
20-
group: "zuul"
19+
owner: "{{ cifmw_reproducer_controller_user }}"
20+
group: "{{ cifmw_reproducer_controller_user }}"
2121

2222
- name: Rotate some logs
2323
tags:

roles/reproducer/tasks/configure_cleanup.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@
4242
extravars: "{{ cifmw_reproducer_play_extravars }}"
4343
playbook: "clean_openstack_deployment.yaml"
4444
ansible.builtin.template:
45-
dest: "/home/zuul/cleanup-architecture.sh"
45+
dest: "{{ cifmw_reproducer_controller_user_dir }}/cleanup-architecture.sh"
4646
src: "script.sh.j2"
4747
mode: "0755"
48-
owner: "zuul"
49-
group: "zuul"
48+
owner: "{{ cifmw_reproducer_controller_user }}"
49+
group: "{{ cifmw_reproducer_controller_user }}"
5050

5151
- name: Rotate some logs
5252
tags:

roles/reproducer/tasks/configure_controller.yml

Lines changed: 37 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
11
---
2-
- name: Set facts related to the reproducer
3-
ansible.builtin.set_fact:
4-
_ctl_reproducer_basedir: >-
5-
{{
6-
(
7-
'/home/zuul',
8-
'ci-framework-data',
9-
) | path_join
10-
}}
11-
122
# The dynamic inventory sets the ansible_ssh_user to zuul once we get the proper
133
# ssh configuration accesses set.
144
- name: Configure controller-0
@@ -25,14 +15,10 @@
2515
cifmw_sushy_emulator_install_type: podman
2616
cifmw_sushy_emulator_hypervisor_address: >-
2717
{{ inventory_hostname }}.utility
28-
cifmw_sushy_emulator_basedir: "{{ _ctl_reproducer_basedir }}"
18+
cifmw_sushy_emulator_basedir: "{{ cifmw_reproducer_controller_basedir }}"
2919
cifmw_sushy_emulator_connection_name: "sushy.utility"
30-
cifmw_sushy_emulator_sshkey_path: >-
31-
{{
32-
[_ctl_reproducer_basedir, '../.ssh/sushy_emulator-key'] |
33-
path_join
34-
}}
35-
cifmw_podman_user_linger: "zuul"
20+
cifmw_sushy_emulator_sshkey_path: "{{ cifmw_reproducer_controller_user_dir }}/.ssh/sushy_emulator-key"
21+
cifmw_podman_user_linger: "{{ cifmw_reproducer_controller_user }}"
3622
cifmw_sushy_emulator_libvirt_user: >-
3723
{{
3824
hostvars[cifmw_sushy_emulator_hypervisor_target].ansible_user_id |
@@ -41,7 +27,7 @@
4127
block:
4228
- name: Ensure directories exist
4329
ansible.builtin.file:
44-
path: "{{ _ctl_reproducer_basedir }}/{{ item }}"
30+
path: "{{ cifmw_reproducer_controller_basedir }}/{{ item }}"
4531
state: directory
4632
mode: "0755"
4733
loop:
@@ -118,14 +104,14 @@
118104
- bootstrap
119105
ansible.builtin.shell:
120106
cmd: >-
121-
cat /home/zuul/reproducer-inventory/* >
122-
{{ _ctl_reproducer_basedir }}/artifacts/zuul_inventory.yml
107+
cat {{ cifmw_reproducer_controller_user_dir }}/reproducer-inventory/* >
108+
{{ cifmw_reproducer_controller_basedir }}/artifacts/zuul_inventory.yml
123109
124110
# You want to use the "name" parameter of the ansible.builtin.include_vars
125111
# call, such as:
126112
# - name: Load mac mapping
127113
# ansible.builtin.include_vars:
128-
# file: "{{ _ctl_reproducer_basedir }}/parameters/interfaces-info.yml"
114+
# file: "{{ cifmw_reproducer_controller_basedir }}/parameters/interfaces-info.yml"
129115
# name: my_fancy_name
130116
# Then you'll be able to access the mapping content via `my_fancy_name`.
131117
- name: Push the MAC mapping data
@@ -135,7 +121,7 @@
135121
- cifmw_libvirt_manager_mac_map is defined
136122
ansible.builtin.copy:
137123
mode: "0644"
138-
dest: "{{ _ctl_reproducer_basedir }}/parameters/interfaces-info.yml"
124+
dest: "{{ cifmw_reproducer_controller_basedir }}/parameters/interfaces-info.yml"
139125
content: "{{ cifmw_libvirt_manager_mac_map | to_nice_yaml }}"
140126

141127
- name: Inject other Hypervisor SSH keys
@@ -149,7 +135,7 @@
149135
default(hostvars[host]['inventory_hostname'])
150136
}}
151137
ansible.builtin.copy:
152-
dest: "/home/zuul/.ssh/ssh_{{ _ssh_host }}"
138+
dest: "{{ cifmw_reproducer_controller_user_dir }}/.ssh/ssh_{{ _ssh_host }}"
153139
content: "{{ _ssh_key }}"
154140
mode: "0600"
155141
loop: "{{ hostvars.keys() }}"
@@ -175,7 +161,7 @@
175161
ansible.builtin.blockinfile:
176162
create: true
177163
mode: "0600"
178-
path: "/home/zuul/.ssh/config"
164+
path: "{{ cifmw_reproducer_controller_user_dir }}/.ssh/config"
179165
marker: "## {mark} {{ _ssh_host }}"
180166
block: |-
181167
Host {{ _ssh_host }} {{ hostvars[host]['inventory_hostname'] }}
@@ -210,7 +196,7 @@
210196
ansible.builtin.blockinfile:
211197
create: true
212198
mode: "0600"
213-
path: "/home/zuul/.ssh/config"
199+
path: "{{ cifmw_reproducer_controller_user_dir }}/.ssh/config"
214200
marker: "## {mark} {{ host }}"
215201
block: |-
216202
Host {{ host }} {{ _hostname }} {{ _hostname }}.utility {{ hostvars[host].ansible_host }}
@@ -232,52 +218,52 @@
232218

233219
- name: Create kube directory
234220
ansible.builtin.file:
235-
path: "/home/zuul/.kube"
221+
path: "{{ cifmw_reproducer_controller_user_dir }}/.kube"
236222
state: directory
237-
owner: "{{ cifmw_reproducer_user }}"
238-
group: "{{ cifmw_reproducer_user }}"
223+
owner: "{{ cifmw_reproducer_controller_user }}"
224+
group: "{{ cifmw_reproducer_controller_user }}"
239225
mode: "0750"
240226

241227
- name: Inject kubeconfig content
242228
when:
243229
- _devscripts_kubeconfig.content is defined or
244230
_crc_kubeconfig.content is defined
245231
ansible.builtin.copy:
246-
dest: "/home/zuul/.kube/config"
232+
dest: "{{ cifmw_reproducer_controller_user_dir }}/.kube/config"
247233
content: >-
248234
{{
249235
(_use_ocp | bool) |
250236
ternary(_devscripts_kubeconfig.content, _crc_kubeconfig.content) |
251237
b64decode
252238
}}
253-
owner: "{{ cifmw_reproducer_user }}"
254-
group: "{{ cifmw_reproducer_user }}"
239+
owner: "{{ cifmw_reproducer_controller_user }}"
240+
group: "{{ cifmw_reproducer_controller_user }}"
255241
mode: "0640"
256242

257243
- name: Inject kubeadmin-password if exists
258244
when:
259245
- _devscripts_kubeadm.content is defined or
260246
_crc_kubeadm.content is defined
261247
ansible.builtin.copy:
262-
dest: "/home/zuul/.kube/kubeadmin-password"
248+
dest: "{{ cifmw_reproducer_controller_user_dir }}/.kube/kubeadmin-password"
263249
content: >-
264250
{{
265251
(_devscripts_kubeadm.content is defined) |
266252
ternary(_devscripts_kubeadm.content, _crc_kubeadm.content) |
267253
b64decode
268254
}}
269-
owner: "{{ cifmw_reproducer_user }}"
270-
group: "{{ cifmw_reproducer_user }}"
255+
owner: "{{ cifmw_reproducer_controller_user }}"
256+
group: "{{ cifmw_reproducer_controller_user }}"
271257
mode: "0600"
272258

273259
- name: Inject devscripts private key if set
274260
when:
275261
- _devscript_privkey.content is defined
276262
ansible.builtin.copy:
277-
dest: "{{ ansible_user_dir }}/.ssh/devscripts_key"
263+
dest: "{{ cifmw_reproducer_controller_user_dir }}/.ssh/devscripts_key"
278264
content: "{{ _devscript_privkey.content | b64decode }}"
279-
owner: "{{ cifmw_reproducer_user }}"
280-
group: "{{ cifmw_reproducer_user }}"
265+
owner: "{{ cifmw_reproducer_controller_user }}"
266+
group: "{{ cifmw_reproducer_controller_user }}"
281267
mode: "0400"
282268

283269
- name: Ensure /etc/ci/env is created
@@ -289,8 +275,8 @@
289275

290276
- name: Manage secrets on controller-0
291277
vars:
292-
cifmw_manage_secrets_basedir: "/home/zuul/ci-framework-data"
293-
cifmw_manage_secrets_owner: "{{ cifmw_reproducer_user }}"
278+
cifmw_manage_secrets_basedir: "{{ cifmw_reproducer_controller_basedir }}"
279+
cifmw_manage_secrets_owner: "{{ cifmw_reproducer_controller_user }}"
294280
block:
295281
- name: Initialize secret manager
296282
ansible.builtin.import_role:
@@ -362,7 +348,7 @@
362348
delegate_to: localhost
363349
ansible.posix.synchronize:
364350
src: "{{ cifmw_reproducer_src_dir }}/"
365-
dest: "zuul@{{ item }}:{{ cifmw_reproducer_src_dir }}"
351+
dest: "{{ cifmw_reproducer_controller_user }}@{{ item }}:{{ cifmw_reproducer_controller_user_dir }}/src"
366352
archive: true
367353
recursive: true
368354
loop: "{{ groups['controllers'] }}"
@@ -417,19 +403,19 @@
417403
}}
418404
ansible.builtin.copy:
419405
mode: "0644"
420-
dest: "/home/zuul/ci-framework-data/parameters/reproducer-variables.yml"
406+
dest: "{{ cifmw_reproducer_controller_basedir }}/parameters/reproducer-variables.yml"
421407
content: "{{ _filtered_vars | to_nice_yaml }}"
422408

423409
- name: Create reproducer-variables.yml symlink to old location
424410
ansible.builtin.file:
425-
dest: "/home/zuul/reproducer-variables.yml"
426-
src: "/home/zuul/ci-framework-data/parameters/reproducer-variables.yml"
411+
dest: "{{ cifmw_reproducer_controller_user_dir }}/reproducer-variables.yml"
412+
src: "{{ cifmw_reproducer_controller_basedir }}/parameters/reproducer-variables.yml"
427413
state: link
428414

429415
- name: Inject local environment parameters
430416
ansible.builtin.copy:
431417
mode: "0644"
432-
dest: "/home/zuul/ci-framework-data/parameters/openshift-environment.yml"
418+
dest: "{{ cifmw_reproducer_controller_basedir }}/parameters/openshift-environment.yml"
433419
content: |-
434420
{% raw %}
435421
---
@@ -450,14 +436,14 @@
450436
451437
- name: Create openshift-environment.yml symlink to old location
452438
ansible.builtin.file:
453-
dest: "/home/zuul/openshift-environment.yml"
454-
src: "/home/zuul/ci-framework-data/parameters/openshift-environment.yml"
439+
dest: "{{ cifmw_reproducer_controller_user_dir }}/openshift-environment.yml"
440+
src: "{{ cifmw_reproducer_controller_basedir }}/parameters/openshift-environment.yml"
455441
state: link
456442

457443
- name: Get interfaces-info content
458444
register: _nic_info
459445
ansible.builtin.slurp:
460-
src: "{{ _ctl_reproducer_basedir }}/parameters/interfaces-info.yml"
446+
src: "{{ cifmw_reproducer_controller_basedir }}/parameters/interfaces-info.yml"
461447

462448
# We detected OCP cluster may have some downtime even after it's supposed
463449
# to be started.
@@ -484,7 +470,7 @@
484470
{{ _nic_info.content | b64decode | from_yaml }}
485471
cifmw_networking_mapper_network_name: >-
486472
{{ _cifmw_libvirt_manager_layout.vms.controller.nets.1 }}
487-
cifmw_networking_mapper_basedir: "/home/zuul/ci-framework-data"
473+
cifmw_networking_mapper_basedir: "{{ cifmw_reproducer_controller_basedir }}"
488474
ansible.builtin.import_role:
489475
name: networking_mapper
490476

@@ -494,11 +480,11 @@
494480
block:
495481
- name: Inject CRC ssh key
496482
ansible.builtin.copy:
497-
dest: "/home/zuul/.ssh/crc_key"
483+
dest: "{{ cifmw_reproducer_controller_user_dir }}/.ssh/crc_key"
498484
content: "{{ crc_priv_key['content'] | b64decode }}"
499485
mode: "0400"
500-
owner: "{{ cifmw_reproducer_user }}"
501-
group: "{{ cifmw_reproducer_user }}"
486+
owner: "{{ cifmw_reproducer_controller_user }}"
487+
group: "{{ cifmw_reproducer_controller_user }}"
502488

503489
- name: Ensure we have all dependencies installed
504490
ansible.builtin.async_status:

0 commit comments

Comments
 (0)