Skip to content

Commit 16fae85

Browse files
Merge pull request #40 from kononovn/vm_ipv6
added ipv6 support to deploy-vm-bastion-libvirt.yml playbook
2 parents 68d49a2 + 3a01d6c commit 16fae85

File tree

1 file changed

+42
-12
lines changed

1 file changed

+42
-12
lines changed

playbooks/infra/deploy-vm-bastion-libvirt.yml

+42-12
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,44 @@
8989
vm_name: "{{ hostvars['bastion'].vm_name }}"
9090
vm_disk_name: "{{ vm_name }}_main.qcow2"
9191
libvirtd_disk_path: /var/lib/libvirt/images
92-
vm_net_config:
93-
network:
94-
version: 2
95-
ethernets:
96-
"{{ hostvars['bastion'].vm_external_interface }}":
97-
match:
98-
name: "{{ hostvars['bastion'].vm_external_interface }}"
99-
addresses:
100-
- "{{ hostvars['bastion'].ansible_host }}/{{ hostvars['bastion'].net_prefix }}"
101-
gateway4: "{{ hostvars['bastion'].gateway }}"
102-
nameservers:
103-
addresses: ["{{ hostvars['bastion'].dns }}"]
10492
tasks:
10593

94+
- name: Render network configuration
95+
ansible.builtin.set_fact:
96+
vm_net_config:
97+
network:
98+
version: 2
99+
ethernets:
100+
external-connection:
101+
match:
102+
name: "{{ hostvars['bastion'].vm_external_interface }}"
103+
addresses:
104+
- "{{ hostvars['bastion'].ansible_host }}/{{ hostvars['bastion'].net_prefix }}"
105+
gateway4: "{{ hostvars['bastion'].gateway }}"
106+
gateway6: "{{ hostvars['bastion'].gateway6 | default(omit) }}"
107+
dhcp4: false
108+
nameservers:
109+
addresses: ["{{ hostvars['bastion'].dns }}"]
110+
111+
- name: Append IPv6 to vm_net_config
112+
when: hostvars['bastion'].ipv6 is defined
113+
ansible.builtin.set_fact:
114+
vm_net_config: >-
115+
{{
116+
vm_net_config | combine(
117+
{
118+
'network': {
119+
'ethernets': {
120+
'external-connection': {
121+
'addresses': (vm_net_config.network.ethernets['external-connection'].addresses + [hostvars['bastion'].ipv6])
122+
}
123+
}
124+
}
125+
},
126+
recursive=True
127+
)
128+
}}
129+
106130
- name: Gather VM qcow image
107131
ansible.builtin.get_url:
108132
url: "{{ vm_qcow_url }}"
@@ -240,6 +264,11 @@
240264
name: "{{ hostname }}"
241265
become: true
242266

267+
- name: Rename external connection
268+
become: true
269+
ansible.builtin.command: nmcli connection modify "System external-connection" connection.id external
270+
changed_when: false
271+
243272
- name: Ensure epel repo present
244273
ansible.builtin.dnf:
245274
name: "https://dl.fedoraproject.org/pub/epel/epel-release-latest-{{ ansible_distribution_major_version }}.noarch.rpm"
@@ -255,5 +284,6 @@
255284
- firewalld
256285
- podman
257286
- tmux
287+
- java
258288
state: present
259289
become: true

0 commit comments

Comments
 (0)