aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ansible/roles/infra_check_requirements/tasks/main.yml16
-rw-r--r--ansible/roles/infra_create_network/tasks/create_xml.yml (renamed from ansible/roles/infra_create_network/tasks/create_xml.yaml)20
-rw-r--r--ansible/roles/infra_create_network/tasks/main.yml2
-rw-r--r--ansible/roles/infra_create_vms/tasks/configure_vm.yml4
-rw-r--r--ansible/roles/infra_create_vms/tasks/create_interfaces.yml10
-rw-r--r--ansible/roles/infra_create_vms/tasks/main.yml8
-rw-r--r--etc/infra/infra_deploy.yaml.sample6
7 files changed, 62 insertions, 4 deletions
diff --git a/ansible/roles/infra_check_requirements/tasks/main.yml b/ansible/roles/infra_check_requirements/tasks/main.yml
index 8d05bbdb7..a11bc56a1 100644
--- a/ansible/roles/infra_check_requirements/tasks/main.yml
+++ b/ansible/roles/infra_check_requirements/tasks/main.yml
@@ -34,6 +34,22 @@
msg: "Failed, not enough CPU, required: {{ vcpu_t }}, available {{ ansible_processor_vcpus }}"
when: ansible_processor_vcpus < vcpu_t|int
+- name: Define default network counter
+ set_fact:
+ num_default_network_detected: 0
+
+- name: Increment counter for every default network detected
+ set_fact:
+ num_default_network_detected: "{{ num_default_network_detected|int + 1 }}"
+ when:
+ - item.default_gateway is defined
+ - item.default_gateway == True
+ with_items: "{{infra_deploy_vars.networks}}"
+
+- name: Fail if more than 1 or 0 default networks
+ fail:
+ msg: "Failed, there must be 1 default network: {{ num_default_network_detected }} detected"
+ when: num_default_network_detected|int != 1
- name: Fail if not enough Disk space
set_fact:
diff --git a/ansible/roles/infra_create_network/tasks/create_xml.yaml b/ansible/roles/infra_create_network/tasks/create_xml.yml
index a01c7974a..1632e591c 100644
--- a/ansible/roles/infra_create_network/tasks/create_xml.yaml
+++ b/ansible/roles/infra_create_network/tasks/create_xml.yml
@@ -40,10 +40,30 @@
xpath: /network
add_children:
- name: "{{ item.name }}"
+ - forward:
+ mode: nat
- bridge
- ip
pretty_print: yes
+- name: Add new children nodes to "forward" node
+ xml:
+ path: "{{ xml_file }}"
+ xpath: /network/forward
+ add_children:
+ - nat
+ pretty_print: yes
+
+- name: Add new children nodes to "nat" node
+ xml:
+ path: "{{ xml_file }}"
+ xpath: /network/forward/nat
+ add_children:
+ - port:
+ start: "1024"
+ end: "65535"
+ pretty_print: yes
+
- name: Add "name" attribute to "bridge" node
xml:
path: "{{ xml_file }}"
diff --git a/ansible/roles/infra_create_network/tasks/main.yml b/ansible/roles/infra_create_network/tasks/main.yml
index eba4a3a49..025a775a1 100644
--- a/ansible/roles/infra_create_network/tasks/main.yml
+++ b/ansible/roles/infra_create_network/tasks/main.yml
@@ -18,5 +18,5 @@
name: infra_deploy_vars
- name: Create XML file
- include_tasks: create_xml.yaml
+ include_tasks: create_xml.yml
with_items: "{{ infra_deploy_vars.networks }}"
diff --git a/ansible/roles/infra_create_vms/tasks/configure_vm.yml b/ansible/roles/infra_create_vms/tasks/configure_vm.yml
index 5685e634f..7419fd565 100644
--- a/ansible/roles/infra_create_vms/tasks/configure_vm.yml
+++ b/ansible/roles/infra_create_vms/tasks/configure_vm.yml
@@ -305,7 +305,7 @@
- name: Populate network-config and add interface to xml file
include_tasks: create_interfaces.yml
- extra_vars: "{{ network_config, xml_file , slot_address, mac_address_counter }}"
+ extra_vars: "{{ network_config xml_file slot_address mac_address_counter }}"
loop_control:
loop_var: interface_item
with_items: "{{ node_item.interfaces }}"
@@ -326,7 +326,7 @@
shell: >
qemu-img convert -O qcow2 {{ node_item.image }} {{ image_dir+node_item.hostname+'.qcow2' }}
-- name: Copy and convert the ubuntu image
+- name: Resize image
shell: >
qemu-img resize {{ image_dir+node_item.hostname+'.qcow2' }} {{ node_item.disk }}M
diff --git a/ansible/roles/infra_create_vms/tasks/create_interfaces.yml b/ansible/roles/infra_create_vms/tasks/create_interfaces.yml
index 124421b56..34bfd1b71 100644
--- a/ansible/roles/infra_create_vms/tasks/create_interfaces.yml
+++ b/ansible/roles/infra_create_vms/tasks/create_interfaces.yml
@@ -24,6 +24,16 @@
addresses:
- {{ interface_item.ip }}/{{ interface_item.netmask }}
+- name: Add default gateway
+ blockinfile:
+ path: "{{ network_config }}"
+ insertafter: "{{ interface_item.ip }}"
+ marker: "MARKER"
+ block: |2
+ gateway4: {{ default_bridge.host_ip }}
+ when:
+ - default_bridge is defined
+ - default_bridge.name == interface_item.network
- name: Remove the marker introduced in network-data
lineinfile:
diff --git a/ansible/roles/infra_create_vms/tasks/main.yml b/ansible/roles/infra_create_vms/tasks/main.yml
index 62a023e7e..4d47f44ff 100644
--- a/ansible/roles/infra_create_vms/tasks/main.yml
+++ b/ansible/roles/infra_create_vms/tasks/main.yml
@@ -20,9 +20,15 @@
- set_fact:
mac_address_counter: 0
+- set_fact:
+ default_bridge: "{{ item }}"
+ when:
+ - item.default_gateway is defined
+ - item.default_gateway == True
+ with_items: "{{ infra_deploy_vars.networks }}"
+
- name: Create XML file
include_tasks: configure_vm.yml
- extra_vars: "{{ mac_address_counter }}"
loop_control:
loop_var: node_item
with_items: "{{ infra_deploy_vars.nodes }}"
diff --git a/etc/infra/infra_deploy.yaml.sample b/etc/infra/infra_deploy.yaml.sample
index bf07a01bc..8ed793622 100644
--- a/etc/infra/infra_deploy.yaml.sample
+++ b/etc/infra/infra_deploy.yaml.sample
@@ -31,5 +31,11 @@ nodes:
networks:
- name: management
+ default_gateway: True
host_ip: 192.168.1.1
netmask: 255.255.255.0
+
+ - name: traffic
+ default_gateway: False # This parameter is not mandatory, default value: False
+ host_ip: 192.20.1.1
+ netmask: 255.255.255.0