Skip to content

Commit

Permalink
Merge pull request #92 from redhatci/assisted-nat-network-mode
Browse files Browse the repository at this point in the history
Assisted | Add support to NATted networks
  • Loading branch information
ramperher authored Jan 22, 2024
2 parents d9a286e + d2bca13 commit f2fe3b9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions roles/create_vms/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ virt_packages:
images_dir: /var/lib/libvirt/images/

is_on_rhel9: "{{ (ansible_distribution_major_version == '9' and ansible_distribution == 'RedHat') | bool }}"

# allowed modes: 'bridge', 'nat', using 'bridge' as default
create_vms_network_mode: bridge
10 changes: 10 additions & 0 deletions roles/create_vms/tasks/prepare_network.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
- name: Setup network
become: true
block:
- name: Check if the selected network mode is allowed
vars:
allowed_vm_network_modes:
- bridge
- nat
assert:
that:
- create_vms_network_mode in allowed_vm_network_modes
fail_msg: "{{ create_vms_network_mode }} is not a supported network mode"

- name: define network
community.libvirt.virt_net:
name: "{{ network_name }}"
Expand Down
13 changes: 13 additions & 0 deletions roles/create_vms/templates/network.xml.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
<network>
<name>{{ network_name }}</name>
<uuid>{{ net_uuid | default(99999999 | random | to_uuid) }}</uuid>

{% if create_vms_network_mode == 'bridge' %}

<forward mode='bridge'/>
<bridge name='{{ vm_bridge_name }}'/>

{% elif create_vms_network_mode == 'nat' %}

<forward mode='nat'/>
<bridge name='{{ vm_bridge_name }}' stp='on' delay='0'/>
<ip address="{{ machine_network_cidr | ansible.utils.ipaddr('next_usable') }}" />
<dns enable="no"/>

{% endif %}

</network>
3 changes: 3 additions & 0 deletions roles/process_nmstate/templates/nmstate.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ dns-resolver:
interfaces:
{% for interface in network_config.interfaces %}
- name: {{ interface.name }}
{% if interface.mac is defined %}
mac-address: {{ interface.mac }}
{% endif %}
state: {{ interface.state | default('up') }}
type: {{ interface.type | default('ethernet') }}
{% if interface.addresses.ipv4 is defined %}
Expand Down

0 comments on commit f2fe3b9

Please sign in to comment.