network and serial complete
This commit is contained in:
@ -7,6 +7,6 @@ libvirt_packages:
|
||||
libvirt
|
||||
libvirt-python
|
||||
|
||||
default_network_services:
|
||||
Archlinux:
|
||||
NetworkManager
|
||||
hypervisor:
|
||||
storage: dir
|
||||
device: /dev/sda
|
8
ansible/roles/hypervisor_qcow/tasks/libvirt_dir.yaml
Normal file
8
ansible/roles/hypervisor_qcow/tasks/libvirt_dir.yaml
Normal file
@ -0,0 +1,8 @@
|
||||
---
|
||||
|
||||
- name: Format and mount the libvirt disk if it is not root
|
||||
when: hypervisor.device not in (ansible_mounts | json_query('[?mount == `/`].device'))
|
||||
ansible.builtin.include_tasks:
|
||||
file: libvirt_mount.yaml
|
||||
|
||||
|
@ -1,41 +1,5 @@
|
||||
---
|
||||
|
||||
- name: Clear systemd-networkd config directory
|
||||
ansible.builtin.file:
|
||||
path: "/etc/systemd/network/"
|
||||
state: "{{ item }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0755'
|
||||
with_items:
|
||||
- absent
|
||||
- directory
|
||||
|
||||
- name: Create systemd-networkd config files
|
||||
ansible.builtin.template:
|
||||
src: "{{ item.src }}"
|
||||
dest: /etc/systemd/network/"{{ item.name }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
loop: "{{ systemd_networkd_configs }}"
|
||||
|
||||
- name: Disable non-systemd networking services
|
||||
ansible.builtin.service:
|
||||
name: "{{ item }}"
|
||||
state: stopped
|
||||
enabled: false
|
||||
loop: "{{ default_network_services[ansible_os_family] }}"
|
||||
|
||||
- name: Enable systemd networking
|
||||
ansible.builtin.service:
|
||||
name: "{{ item }}"
|
||||
state: started
|
||||
enabled: true
|
||||
loop:
|
||||
- systemd-networkd
|
||||
- systemd-resolved
|
||||
|
||||
- name: Install libvirt packages (Arch)
|
||||
when: ansible_os_distribution == 'Archlinux'
|
||||
community.general.pacman:
|
||||
@ -74,3 +38,13 @@
|
||||
community.libvirt.virt_net:
|
||||
name: default
|
||||
state: absent
|
||||
|
||||
- name: Setup libvirt storage (qcow)
|
||||
when: hypervisor.storage == 'dir'
|
||||
ansible.builtin.include_tasks:
|
||||
file: libvirt_dir.yaml
|
||||
|
||||
- name: Setup libvirt storage (zfs)
|
||||
when: hypervisor.storage == 'zfs'
|
||||
ansible.builtin.include_tasks:
|
||||
file: libvirt_zfs.yaml
|
||||
|
5
ansible/roles/serial_out/defaults/main.yaml
Normal file
5
ansible/roles/serial_out/defaults/main.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
console_packages:
|
||||
Archlinux:
|
||||
- util-linux
|
||||
|
||||
console_device: ttyS0
|
6
ansible/roles/serial_out/handlers/main.yaml
Normal file
6
ansible/roles/serial_out/handlers/main.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
|
||||
- name: Run mkinitcpio
|
||||
ansible.builtin.command:
|
||||
cmd: mkinitcpio -p linux
|
||||
changed_when: true
|
27
ansible/roles/serial_out/tasks/main.yaml
Normal file
27
ansible/roles/serial_out/tasks/main.yaml
Normal file
@ -0,0 +1,27 @@
|
||||
---
|
||||
|
||||
# - name: Set serial output for boot loader
|
||||
|
||||
- name: Add command line option for mkinitcpio config
|
||||
when: ansible_distribution == 'Archlinux'
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/cmdline.d/console.conf
|
||||
content: "console={{ console_device }},115200"
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0664'
|
||||
notify:
|
||||
- Run mkinitcpio
|
||||
|
||||
- name: Install getty provider package (Archlinux)
|
||||
when: ansible_distribution == 'Archlinux'
|
||||
community.general.pacman:
|
||||
name: "{{ console_packages[ansible_os_family] }}"
|
||||
state: present
|
||||
update_cache: true
|
||||
|
||||
- name: Enable the serial-getty service
|
||||
ansible.builtin.service:
|
||||
name: serial-getty@{{ console_device }}.service
|
||||
enabled: true
|
||||
state: started
|
3
ansible/roles/systemd_networkd/defaults/main.yaml
Normal file
3
ansible/roles/systemd_networkd/defaults/main.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
default_network_services:
|
||||
Archlinux:
|
||||
NetworkManager
|
9
ansible/roles/systemd_networkd/handlers/main.yaml
Normal file
9
ansible/roles/systemd_networkd/handlers/main.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
- name: Restart systemd-networkd
|
||||
ansible.builtin.service:
|
||||
name: systemd-networkd.service
|
||||
state: restarted
|
||||
|
||||
- name: Restart systemd-resolved
|
||||
ansible.builtin.service:
|
||||
name: systemd-resolved.service
|
||||
state: restarted
|
39
ansible/roles/systemd_networkd/tasks/main.yaml
Normal file
39
ansible/roles/systemd_networkd/tasks/main.yaml
Normal file
@ -0,0 +1,39 @@
|
||||
---
|
||||
|
||||
- name: Clear systemd-networkd config directory
|
||||
ansible.builtin.file:
|
||||
path: "/etc/systemd/network/"
|
||||
state: "{{ item }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0755'
|
||||
with_items:
|
||||
- absent
|
||||
- directory
|
||||
|
||||
- name: Create systemd-networkd config files
|
||||
ansible.builtin.template:
|
||||
src: "{{ item.src }}"
|
||||
dest: /etc/systemd/network/"{{ item.name }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
loop: "{{ systemd_networkd_configs }}"
|
||||
notify:
|
||||
- Restart systemd-resolved
|
||||
- Restart systemd-networkd
|
||||
|
||||
- name: Disable non-systemd networking services
|
||||
ansible.builtin.service:
|
||||
name: "{{ item }}"
|
||||
state: stopped
|
||||
enabled: false
|
||||
loop: "{{ default_network_services[ansible_os_family] }}"
|
||||
|
||||
- name: Enable systemd networking
|
||||
ansible.builtin.service:
|
||||
name: "{{ item }}"
|
||||
enabled: true
|
||||
loop:
|
||||
- systemd-networkd
|
||||
- systemd-resolved
|
@ -0,0 +1,9 @@
|
||||
[NetDev]
|
||||
Name={{ item.name | regex_replace('^[0-9]*-', '') | regex_replace('\.netdev', '') }}
|
||||
Kind=bridge
|
||||
|
||||
[Bridge]
|
||||
DefaultPVID=none
|
||||
VLANFiltering={{ item.vlan_filtering | default(false)}}
|
||||
VLANProtocol=802.1q
|
||||
STP={{ item.stp | default(false) }}
|
15
ansible/roles/systemd_networkd/templates/bridge.network.j2
Normal file
15
ansible/roles/systemd_networkd/templates/bridge.network.j2
Normal file
@ -0,0 +1,15 @@
|
||||
[Match]
|
||||
Name={{ item.name | regex_replace('^[0-9]*-', '') | regex_replace('\.network', '') }}
|
||||
|
||||
[Link]
|
||||
ARP={{ item.arp | default(true) }}
|
||||
|
||||
[Network]
|
||||
DHCP={{ item.dhcp | default(true) }}
|
||||
LinkLocalAddressing=False
|
||||
LLDP={{ item.lldp | default(true) }}
|
||||
{% if item.vlans is defined -%}
|
||||
{% for vlan in item.vlans -%}
|
||||
VLAN={{ item.vlan }}
|
||||
{% endfor -%}
|
||||
{% endif -%}
|
@ -0,0 +1,8 @@
|
||||
[Match]
|
||||
PermanentMACAddress={{ item.mac_address }}
|
||||
|
||||
[Link]
|
||||
Name={{ item.name | regex_replace('^[0-9]*-', '') | regex_replace('\.link', '') }}
|
||||
MACAddressPolicy=permanent
|
||||
MACAddress={{ item.mac_address }}
|
||||
|
73
ansible/roles/systemd_networkd/templates/ethernet.network.j2
Normal file
73
ansible/roles/systemd_networkd/templates/ethernet.network.j2
Normal file
@ -0,0 +1,73 @@
|
||||
[Match]
|
||||
MACAddress={{ item.mac_address }}
|
||||
|
||||
[Link]
|
||||
ARP={{ item.arp | default(true) }}
|
||||
|
||||
[Network]
|
||||
DHCP={{ item.dhcp | default(true) }}
|
||||
LinkLocalAddressing=False
|
||||
LLDP={{ item.lldp | default(true) }}
|
||||
{% if item.nameserver is defined and item.nameserver.ipv4 is defined -%}
|
||||
{% for nameserver in item.nameserver.ipv4 -%}
|
||||
DNS={{ nameserver }}
|
||||
{% endfor -%}
|
||||
{% endif -%}
|
||||
{% if item.nameserver is defined and item.nameserver.ipv6 is defined -%}
|
||||
{% for nameserver in item.nameserver.ipv6 -%}
|
||||
DNS={{ nameserver }}
|
||||
{% endfor -%}
|
||||
{% endif -%}
|
||||
{% if item.bond is defined -%}
|
||||
Bond={{ item.bond }}
|
||||
{% endif -%}
|
||||
{% if item.bridge is defined -%}
|
||||
Bridge={{ item.bridge.name }}
|
||||
{% endif -%}
|
||||
{% if item.vlans is defined -%}
|
||||
{% for vlan in item.vlans -%}
|
||||
VLAN={{ vlan }}
|
||||
{% endfor -%}
|
||||
{% endif -%}
|
||||
|
||||
{% if item.address is defined %}
|
||||
[Address]
|
||||
{% if item.address.ipv4 is defined -%}
|
||||
{% for address in item.address.ipv4 -%}
|
||||
Address={{ address }}
|
||||
{% endfor -%}
|
||||
{% endif -%}
|
||||
{% if item.address.ipv6 is defined -%}
|
||||
{% for address in item.address.ipv6 -%}
|
||||
Address={{ address }}
|
||||
{% endfor -%}
|
||||
{% endif -%}
|
||||
{% endif -%}
|
||||
|
||||
{% if item.gateway is defined and item.gateway.ipv4 is defined %}
|
||||
[Route]
|
||||
Destination=0.0.0.0/0
|
||||
Gateway={{ item.gateway.ipv4 }}
|
||||
Scope=global
|
||||
Protocol=static
|
||||
Type=unicast
|
||||
{% endif -%}
|
||||
|
||||
{% if item.gateway is defined and item.gateway.ipv6 is defined %}
|
||||
[Route]
|
||||
Destination=::/0
|
||||
Gateway={{ item.gateway.ipv6 }}
|
||||
Protocol=static
|
||||
Type=unicast
|
||||
{% endif -%}
|
||||
|
||||
{% if item.bridge is defined and item.bridge.vlans is defined %}
|
||||
[BridgeVLANs]
|
||||
{% for vlan in item.bridge.vlans -%}
|
||||
VLAN={{ vlan }}
|
||||
{% endfor -%}
|
||||
{% if item.bridge.pvid is defined -%}
|
||||
PVID={{ item.bridge.pvid }}
|
||||
EgressUntagged={{ item.bridge.pvid }}
|
||||
{% endif -%}
|
||||
{% endif -%}
|
7
ansible/roles/systemd_networkd/templates/vlan.netdev.j2
Normal file
7
ansible/roles/systemd_networkd/templates/vlan.netdev.j2
Normal file
@ -0,0 +1,7 @@
|
||||
[NetDev]
|
||||
Name={{ item.name | regex_replace('^[0-9]*-', '') | regex_replace('\.netdev', '') }}
|
||||
Kind=vlan
|
||||
|
||||
[VLAN]
|
||||
Id={{ item.vlan_id }}
|
||||
Protocol=802.1q
|
51
ansible/roles/systemd_networkd/templates/vlan.network.j2
Normal file
51
ansible/roles/systemd_networkd/templates/vlan.network.j2
Normal file
@ -0,0 +1,51 @@
|
||||
[Match]
|
||||
Name={{ item.name | regex_replace('^[0-9]*-', '') | regex_replace('\.network', '') }}
|
||||
|
||||
[Link]
|
||||
ARP={{ item.arp | default(true) }}
|
||||
|
||||
[Network]
|
||||
DHCP={{ item.dhcp | default(true) }}
|
||||
LinkLocalAddressing=False
|
||||
LLDP={{ item.lldp | default(true) }}
|
||||
{% if item.nameserver is defined and item.nameserver.ipv4 is defined -%}
|
||||
{% for nameserver in item.nameserver.ipv4 -%}
|
||||
DNS={{ nameserver }}
|
||||
{% endfor -%}
|
||||
{% endif -%}
|
||||
{% if item.nameserver is defined and item.nameserver.ipv6 is defined -%}
|
||||
{% for nameserver in item.nameserver.ipv6 -%}
|
||||
DNS={{ nameserver }}
|
||||
{% endfor -%}
|
||||
{% endif -%}
|
||||
|
||||
{% if item.address is defined %}
|
||||
[Address]
|
||||
{% if item.address.ipv4 is defined -%}
|
||||
{% for address in item.address.ipv4 -%}
|
||||
Address={{ address }}
|
||||
{% endfor -%}
|
||||
{% endif -%}
|
||||
{% if item.address.ipv6 is defined -%}
|
||||
{% for address in item.address.ipv6 -%}
|
||||
Address={{ address }}
|
||||
{% endfor -%}
|
||||
{% endif -%}
|
||||
{% endif -%}
|
||||
|
||||
{% if item.gateway is defined and item.gateway.ipv4 is defined %}
|
||||
[Route]
|
||||
Destination=0.0.0.0/0
|
||||
Gateway={{ item.gateway.ipv4 }}
|
||||
Scope=global
|
||||
Protocol=static
|
||||
Type=unicast
|
||||
{% endif -%}
|
||||
|
||||
{% if item.gateway is defined and item.gateway.ipv6 is defined %}
|
||||
[Route]
|
||||
Destination=::/0
|
||||
Gateway={{ item.gateway.ipv6 }}
|
||||
Protocol=static
|
||||
Type=unicast
|
||||
{% endif -%}
|
Reference in New Issue
Block a user