2 echo "----------> Copy ssh public keys to csit lab"
4 # shellcheck disable=SC1090
5 source "$WORKSPACE/.venv-openstack/bin/activate"
7 function copy-ssh-keys-to-slave() {
9 for j in $(seq 1 $RETRIES); do
10 # shellcheck disable=SC2092
11 if `ssh-copy-id -i /home/jenkins/.ssh/id_rsa.pub "jenkins@${i}" > /dev/null 2>&1`; then
12 ssh "jenkins@${i}" 'echo "$(facter ipaddress_eth0) $(/bin/hostname)" | sudo tee -a /etc/hosts'
13 echo "Successfully copied public keys to slave ${i}"
15 elif [ "$j" -eq $RETRIES ]; then
16 echo "SSH not responding on ${i} after $RETIRES tries. Giving up."
19 echo "SSH not responding on ${i}. Retrying in 10 seconds..."
23 # ping test to see if connectivity is available
24 if ping -c1 "${i}" &> /dev/null; then
25 echo "Ping to ${i} successful."
27 echo "Ping to ${i} failed."
32 # Print the Stack outputs parameters so that we can identify which IPs belong
34 openstack stack show -c outputs "$STACK_NAME"
36 # shellcheck disable=SC2006
37 ADDR=(`openstack stack show -f json -c outputs "$STACK_NAME" | \
39 select(.output_key | match("^vm_[0-9]+_ips\$")) | \
40 .output_value | .[]'`)
42 for i in "${ADDR[@]}"; do
43 ( copy-ssh-keys-to-slave ) &
44 # Store PID of process
48 # Detect when a process failed to copy ssh keys and fail build
51 echo "Process $p successfully copied ssh keys."
53 echo "Process $p failed to copy ssh keys."
57 echo "Copying ssh keys complete."