Skip to content

Commit 9e3bb08

Browse files
eduolivaressdatko
authored andcommitted
[test_operator] Allow to read files from remote hosts
Several tasks from the test_operator role only worked when the ansible playbook was run on localhost, because they used lookup file to read the file content. With this change, the file content is obtained with slurp, which allows to execute the playbook from a different host. OSPRH-20268
1 parent 8022f9e commit 9e3bb08

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

roles/test_operator/tasks/tempest-tests.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@
9292
- stage_vars_dict.cifmw_test_operator_tempest_ssh_key_secret_name is not defined
9393
- private_key_file.stat.exists
9494
block:
95+
- name: Slurp cifmw private key file
96+
ansible.builtin.slurp:
97+
path: "{{ cifmw_test_operator_controller_priv_key_file_path }}"
98+
register: private_key_file_content
99+
95100
- name: Ensure a secret for the cifmw private key file exists
96101
kubernetes.core.k8s:
97102
kubeconfig: "{{ cifmw_openshift_kubeconfig }}"
@@ -107,11 +112,8 @@
107112
name: "{{ cifmw_test_operator_controller_priv_key_secret_name }}"
108113
namespace: "{{ stage_vars_dict.cifmw_test_operator_namespace }}"
109114
data:
110-
ssh-privatekey: >-
111-
{{
112-
lookup('file', cifmw_test_operator_controller_priv_key_file_path, rstrip=False) |
113-
b64encode
114-
}}
115+
# b64decode not needed because the text has to be encoded
116+
ssh-privatekey: "{{ private_key_file_content.content }}"
115117

116118
- name: Add SSHKeySecretName section to Tempest CR
117119
ansible.builtin.set_fact:

roles/test_operator/tasks/tobiko-tests.yml

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,19 @@
2626
loop_control:
2727
loop_var: tobikoconf_section
2828

29+
- name: Slurp tobiko.conf
30+
ansible.builtin.slurp:
31+
path: "{{ cifmw_test_operator_artifacts_basedir }}/tobiko.conf"
32+
register: tobikoconf_content
33+
2934
- name: Add config section to tobiko CR
35+
vars:
36+
tobikoconf_content_decoded: "{{ tobikoconf_content.content | b64decode }}"
3037
ansible.builtin.set_fact:
3138
test_operator_cr: >-
3239
{{
3340
test_operator_cr |
34-
combine({'spec': {'config':
35-
lookup('file',
36-
cifmw_test_operator_artifacts_basedir + '/tobiko.conf')
37-
}}, recursive=true)
41+
combine({'spec': {'config': tobikoconf_content_decoded}}, recursive=true)
3842
}}
3943
4044
- name: Add ssh keys used for the VMs that tobiko creates to tobiko CR
@@ -51,22 +55,30 @@
5155
size: "{{ stage_vars_dict.cifmw_test_operator_tobiko_ssh_keysize }}"
5256
when: not check_ssh_key.stat.exists
5357

58+
- name: Slurp key files
59+
vars:
60+
keyfilename: "id_{{ stage_vars_dict.cifmw_test_operator_tobiko_ssh_keytype }}{{ '.pub' if item == 'public' else '' }}"
61+
ansible.builtin.slurp:
62+
path: "{{ cifmw_test_operator_artifacts_basedir }}/{{ keyfilename }}"
63+
register: key_file_content
64+
loop:
65+
- private
66+
- public
67+
5468
- name: Add private and public keys to tobiko CR
5569
vars:
5670
keyname: "{{ item }}Key"
57-
keyfilename: "id_{{ stage_vars_dict.cifmw_test_operator_tobiko_ssh_keytype }}{{ '.pub' if item == 'public' else '' }}"
5871
ansible.builtin.set_fact:
5972
test_operator_cr: >-
6073
{{
6174
test_operator_cr |
62-
combine({'spec': {keyname:
63-
lookup('file',
64-
cifmw_test_operator_artifacts_basedir + '/' + keyfilename)
65-
}}, recursive=true)
75+
combine({'spec': {keyname: key_file_content.results[idx].content | b64decode}}, recursive=true)
6676
}}
67-
with_items:
77+
loop:
6878
- private
6979
- public
80+
loop_control:
81+
index_var: idx
7082

7183
- name: Add preventCreate if it is defined
7284
ansible.builtin.set_fact:
@@ -88,6 +100,11 @@
88100
}}
89101
when: stage_vars_dict.cifmw_test_operator_tobiko_num_processes is not none
90102

103+
- name: Slurp kubeconfig file
104+
ansible.builtin.slurp:
105+
path: "{{ cifmw_openshift_kubeconfig }}"
106+
register: kubeconfig_file_content
107+
91108
- name: Ensure a secret for the kubeconfig file exists
92109
kubernetes.core.k8s:
93110
kubeconfig: "{{ cifmw_openshift_kubeconfig }}"
@@ -103,5 +120,6 @@
103120
name: "{{ stage_vars_dict.cifmw_test_operator_tobiko_kubeconfig_secret }}"
104121
namespace: "{{ stage_vars_dict.cifmw_test_operator_namespace }}"
105122
data:
106-
config: "{{ lookup('file', cifmw_openshift_kubeconfig) | b64encode }}"
123+
# b64decode not needed because the text has to be encoded
124+
config: "{{ kubeconfig_file_content.content }}"
107125
when: not cifmw_test_operator_dry_run | bool

0 commit comments

Comments
 (0)