From 6eb6e6a237375ec95ab1bcd540676675bd18df49 Mon Sep 17 00:00:00 2001 From: XaverStiensmeier Date: Sat, 14 Oct 2023 15:50:52 +0200 Subject: [PATCH] trying to figure out why route applying only works once. --- .../templates/slurm/worker_userdata.j2 | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/resources/playbook/roles/bibigrid/templates/slurm/worker_userdata.j2 b/resources/playbook/roles/bibigrid/templates/slurm/worker_userdata.j2 index e86fb1a7..7d90c261 100644 --- a/resources/playbook/roles/bibigrid/templates/slurm/worker_userdata.j2 +++ b/resources/playbook/roles/bibigrid/templates/slurm/worker_userdata.j2 @@ -1,12 +1,23 @@ #cloud-config {% set cloud_identifier = item.cloud_identifier %} -bootcmd: - - /usr/bin/ip route add 10.0.0.0/24 via {{ hostvars[item].private_v4 }} dev ens3 -{% for cluster_cidr in cluster_cidrs %} -{% if cluster_cidr.cloud_identifier != hostvars[item].cloud_identifier %} -{% for provider_cidr in cluster_cidr.provider_cidrs %} - - /usr/bin/ip route add {{ provider_cidr }} via {{ hostvars[item].private_v4 }} dev ens3 -{% endfor %} -{% endif %} -{% endfor %} \ No newline at end of file +# Create a shell script to apply routes +write_files: + - content: | + #!/bin/bash + echo Adding IP Routes + /usr/bin/ip route add 10.0.0.0/24 via {{ hostvars[item].private_v4 }} + {% for cluster_cidr in cluster_cidrs %} + {% if cluster_cidr.cloud_identifier != hostvars[item].cloud_identifier %} + {% for provider_cidr in cluster_cidr.provider_cidrs %} + /usr/bin/ip route add {{ provider_cidr }} via {{ hostvars[item].private_v4 }} + {% endfor %} + {% endif %} + {% endfor %} + echo "IP Routes Added" + path: /usr/local/bin/apply-routes.sh + permissions: '0755' + +# Execute the shell script +runcmd: + - /usr/local/bin/apply-routes.sh \ No newline at end of file