cd host_vars for i in cluster-master01 cluster-master02 cluster-master03 cluster-worker01 cluster-worker02 cluster-worker03 cluster-worker04 cluster-worker05 cluster-worker06 do sed -i "s#^wg_secret_key.*#wg_secret_key: $(wg genkey)#" ${i}.yaml pubkey=$(cat ${i}.yaml | yq .wg_secret_key | sed 's/"//g' | wg pubkey) sed -i "s#^wg_public_key.*#wg_public_key: ${pubkey}#" ${i}.yaml done