diff --git a/README.md b/README.md index 72f81554da56b4ba94739d586c49fdfb6f2cfc68..1ac4f7b4476b404e033947f854171b8b93023d36 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,10 @@ Flavors provide a quick way to choose hardware specs (like number of cpus and me | csirtmu.jumbo16x32 | 16 | 32768 | | csirtmu.jumbo16x64 | 16 | 65536 | +### Interface names and supported boxes + +The name of the correct network interface can be different for every box. The supported boxes are listed in the file name_mappings/interface.yml. If your box is not on the list, the most common "eth1" will be used. If you get an error during `$ vagrant up` about non-existing network interface, you can add the name of your box and the correct network interface to the list manually. + ### Implemented attribute types: - all simple vagrant attributes - flavors, memory, cpus diff --git a/generate.py b/generate.py index 99a9e96bfb462ba8d51d918182bc6eca18e4caae..40a61162254358eacef5ccd27b0875de11f34853 100644 --- a/generate.py +++ b/generate.py @@ -15,3 +15,4 @@ device_definitions = open_file(str(sys.argv[1])) generate_vagrantfile(device_definitions) generate_ansible_files(device_definitions) + diff --git a/modules/ansible_data_generator.py b/modules/ansible_data_generator.py index 1768e83241d8ab7f0af746b7df5386895474b7ee..e585ea17f7dc7a74cfd16e78adf35bad15d31592 100644 --- a/modules/ansible_data_generator.py +++ b/modules/ansible_data_generator.py @@ -1,3 +1,7 @@ +from modules.device_creator import open_file + +INTERFACE_FILE = "name_mapping/interface.yml" + def create_network_map(net_mappings, router_mappings): """ Creates a structure with network topology for Jinja2 template. """ @@ -18,7 +22,18 @@ def _find_router_ip(network_name, router_mappings): return router_mapping["ip"] -def create_host_map(net_mappings, router_mappings): +def _find_interface(host_name, hosts): + + for host in hosts: + if host["name"] == host_name: + interfaces = open_file(INTERFACE_FILE) + if host["base_box"] in interfaces: + return interfaces[host["base_box"]] + + return "eth1" + + +def create_host_map(net_mappings, router_mappings, host_list): """ Creates a structure with hosts and their primary routers ip """ hosts = [] @@ -29,5 +44,6 @@ def create_host_map(net_mappings, router_mappings): host["host_ip"] = net_mapping["ip"] host["router_ip"] = _find_router_ip( net_mapping["network"], router_mappings) + host["interface"] = _find_interface(net_mapping["host"], host_list) hosts.append(host) return hosts diff --git a/modules/file_generator.py b/modules/file_generator.py index e9567701aafc6c2a81adcbc801c87b5eb4312ec1..8e7d1f8c83e50fbd3b4066506c1d252d75a9766e 100644 --- a/modules/file_generator.py +++ b/modules/file_generator.py @@ -72,7 +72,7 @@ def _generate_playbook(): def _generate_device_configuration(definitions): """ Generates a playbook with basic device configutarion. """ - host_map = create_host_map(definitions["net_mappings"], definitions["router_mappings"]) + host_map = create_host_map(definitions["net_mappings"], definitions["router_mappings"], definitions["hosts"]) network = create_network_map( definitions["net_mappings"], definitions["router_mappings"]) @@ -90,7 +90,7 @@ def _generate_device_configuration(definitions): def _generate_hosts_role(definitions): """ Generates hosts role. """ - host_map = create_host_map(definitions["net_mappings"], definitions["router_mappings"]) + host_map = create_host_map(definitions["net_mappings"], definitions["router_mappings"], definitions["hosts"]) network = create_network_map( definitions["net_mappings"], definitions["router_mappings"]) @@ -109,7 +109,7 @@ def _generate_routers_role(definitions): print("Info: No router definition was found. Skipping router creation.") return - host_map = create_host_map(definitions["net_mappings"], definitions["router_mappings"]) + host_map = create_host_map(definitions["net_mappings"], definitions["router_mappings"], definitions["hosts"]) network = create_network_map( definitions["net_mappings"], definitions["router_mappings"]) diff --git a/name_mapping/interface.yml b/name_mapping/interface.yml new file mode 100644 index 0000000000000000000000000000000000000000..0664b7628f1a8a6feca47b92ca7863c77254cb4b --- /dev/null +++ b/name_mapping/interface.yml @@ -0,0 +1,3 @@ +kalilinux/rolling-light: eth1 +xubuntu-16.04-desktop-amd64: eth1 +ubuntu/xenial64: enp0s8 diff --git a/templates/device_configuration b/templates/device_configuration index cfc241ea6c69241593df1287f6031d0c9c3ee6c5..73a852fe23a6ad5db658fbe1de3a385b43a7718b 100644 --- a/templates/device_configuration +++ b/templates/device_configuration @@ -13,7 +13,7 @@ become: yes tasks: - name: Change default gateway - command: route add default gw {{ host.router_ip }} eth1 + command: route add default gw {{ host.router_ip }} {{ host.interface }} {% endfor %} - name: Configuring all routers diff --git a/test.yml b/test.yml index 69d11fc6c55a996caa2ebe3c819d38c298454472..c53b54d0e2ac286fe728197f90e4f7f631fb0322 100644 --- a/test.yml +++ b/test.yml @@ -1,12 +1,12 @@ name: small-sandbox hosts: - name: server - base_box: kalilinux/rolling-light + base_box: ubuntu/xenial64 flavor: csirtmu.tiny1x4 cpus: 2 - name: home - base_box: kalilinux/rolling-light + base_box: ubuntu/xenial64 boot_timeout: 1000 box_check_update: false