From a822bec0258f39b9626a2a2d659ed0a00414e9f8 Mon Sep 17 00:00:00 2001
From: Attila Farkas <394097@mail.muni.cz>
Date: Mon, 12 Oct 2020 17:21:02 +0200
Subject: [PATCH] Divide provisioning to separate devices in Vagrantfile

---
 modules/vagrant_generator.py |  4 ++--
 templates/vagrantfile        | 24 ++++++++++++++----------
 2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/modules/vagrant_generator.py b/modules/vagrant_generator.py
index 12f1fb0..2d9805e 100644
--- a/modules/vagrant_generator.py
+++ b/modules/vagrant_generator.py
@@ -240,6 +240,7 @@ def _build_vagrant_definitions(input_definitions, flags):
         device["type"] = "router"
         device["name"] = router["name"]
         device["commands"] = _create_commands(router)
+        device["commands"].extend(_call_provisioner(input_definitions, flags))
         vagrant_definitions.append(device)
 
     for host in input_definitions["hosts"]:
@@ -247,12 +248,11 @@ def _build_vagrant_definitions(input_definitions, flags):
         device["type"] = "host"
         device["name"] = host["name"]
         device["commands"] = _create_commands(host)
+        device["commands"].extend(_call_provisioner(input_definitions, flags))
         vagrant_definitions.append(device)
 
     _add_all_networks(vagrant_definitions, input_definitions, flags)
 
-    vagrant_definitions.extend(_call_provisioner(input_definitions, flags))
-
     return vagrant_definitions
 
 
diff --git a/templates/vagrantfile b/templates/vagrantfile
index 664f569..ea7a09f 100644
--- a/templates/vagrantfile
+++ b/templates/vagrantfile
@@ -26,8 +26,8 @@
 {# Macro for provision items #}
 {% macro provision(item, namespace) %}
   # {{ item.note }}
-  {{ namespace }}.vm.provision :{{ item.provisioner }} do |provisioner|
-{{ layer2(item.commands, "provisioner") }}
+    {{ namespace }}.vm.provision :{{ item.provisioner }} do |provisioner|
+{{ layer3(item.commands, "provisioner") }}
 {% endmacro -%}
 
 {# Macro for string items #}
@@ -63,12 +63,12 @@
   {{ namespace }}.{{ item.command }} = {
   {% for key, value in item.dictionary.items() %}
     {% if loop.last %}
-      {{ key }}: {{ value }}
+        {{ key }}: {{ value }}
     {% else %}
-      {{ key }}: {{ value }},
+        {{ key }}: {{ value }},
     {% endif %}
   {% endfor %}
-    }
+      }
 {% endmacro -%}
 
 {# Macro for dictionaries #}
@@ -76,12 +76,12 @@
   {{ namespace }}.groups = {
   {% for key, value in item.groups.items() %}
     {% if loop.last %}
-      "{{ key }}" => {{ value }}
+        "{{ key }}" => {{ value }}
     {% else %}
-      "{{ key }}" => {{ value }},
+        "{{ key }}" => {{ value }},
     {% endif %}
   {% endfor %}
-    }
+      }
 {% endmacro -%}
 
 {# Macro for network items #}
@@ -102,8 +102,6 @@
 {{ router(item, namespace) }}
 {% elif item.type == "host" %}
 {{ host(item, namespace) }}
-{% elif item.type == "provision" %}
-{{ provision(item, namespace) }}
 {% endif %}
 {% endfor %}
 end
@@ -128,6 +126,8 @@ end
   {{ dictionary(item, namespace) -}}
 {% elif item.type == "groups" %}
   {{ groups(item, namespace) -}}
+{% elif item.type == "provision" %}
+  {{ provision(item, namespace) }}
 {% endif %}
 {% endfor %}
   end
@@ -142,6 +142,10 @@ end
     {{ boolean(item, namespace) -}}
 {% elif item.type == "integer" %}
     {{ integer(item, namespace) -}}
+{% elif item.type == "dictionary" %}
+    {{ dictionary(item, namespace) -}}
+{% elif item.type == "groups" %}
+    {{ groups(item, namespace) -}}
 {% endif %}
 {% endfor %}
     end
-- 
GitLab