Skip to content

Commit

Permalink
hetzner-vlan: initial role WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
saltydk committed Feb 7, 2024
1 parent 332b476 commit 3459fd4
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/adv_settings.yml
/backup_config.yml
/backup_excludes_list.txt
/hetzner_nfs.yml
/hetzner_vlan.yml
/localhost.yml
/providers.yml
/rclone.conf
Expand Down
4 changes: 4 additions & 0 deletions defaults/hetzner_vlan.yml.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
hetzner_vlan:
client_number: 2
vlan_id: 4000
File renamed without changes.
10 changes: 10 additions & 0 deletions roles/hetzner_vlan/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
##########################################################################
# Title: Saltbox: Hetzner VLAN | Default Variables #
# Author(s): salty #
# URL: https://github.com/saltyorg/Saltbox #
# -- #
##########################################################################
# GNU General Public License v3.0 #
##########################################################################
---
hetzner_vlan_netplan_apply: true
26 changes: 26 additions & 0 deletions roles/hetzner_vlan/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#########################################################################
# Title: Saltbox: Hetzner VLAN Role #
# Author(s): salty #
# URL: https://github.com/saltyorg/Saltbox #
# -- #
#########################################################################
# GNU General Public License v3.0 #
#########################################################################
---
- name: Setup Netplan VLAN
ansible.builtin.shell: |
yyq e -i '.network.vlans += {"{{ ansible_default_ipv4.interface }}.{{ hetzner_vlan.vlan_id }}": {"id": {{ hetzner_vlan.vlan_id }}, "link": "{{ ansible_default_ipv4.interface }}", "mtu": 1400, "addresses": ["192.168.100.{{ hetzner_vlan.client_number }}/24"]}}' /etc/netplan/01-netcfg.yaml
when: ('hetzner-vlan-deploy' in ansible_run_tags)

- name: Remove Netplan VLAN
ansible.builtin.shell: |
yyq e -i 'del(.network.vlans)' /etc/netplan/01-netcfg.yaml
when: ('hetzner-vlan-remove' in ansible_run_tags)

- name: Apply Netplan changes
ansible.builtin.shell: netplan apply
when: hetzner_vlan_netplan_apply

- name: Remove VLAN link
ansible.builtin.shell: ip link delete {{ ansible_default_ipv4.interface }}.{{ hetzner_vlan.vlan_id }}
when: ('hetzner-vlan-remove' in ansible_run_tags) and hetzner_vlan_netplan_apply
2 changes: 1 addition & 1 deletion roles/settings/tasks/subtasks/start.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
- "adv_settings.yml"
- "backup_config.yml"
- "providers.yml"
- "hetzner_nfs.yml"
- "hetzner_vlan.yml"
traefik3_migration: "{{ true if (rclone.remotes is undefined) else false }}"

- name: Start | Initialize vars with empty lists
Expand Down
3 changes: 2 additions & 1 deletion saltbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- ['adv_settings.yml', 'defaults/adv_settings.yml.default']
- ['backup_config.yml', 'defaults/backup_config.yml.default']
- ['providers.yml', 'defaults/providers.yml.default']
- ['hetzner_vlan.yml', 'defaults/hetzner_vlan.yml.default']
roles:
- { role: settings, tags: ['settings'] }
- { role: pre_tasks, tags: ['always', 'pre-tasks'] }
Expand Down Expand Up @@ -100,7 +101,7 @@
- { role: yyq, tags: ['yyq'] }
# Apps End
- { role: custom, tags: ['custom'] }
- { role: hetzner_nfs, tags: ['hetzner-nfs-server', 'hetzner-nfs-server-uninstall', 'hetzner-nfs-client-mount', 'hetzner-nfs-client-unmount'] }
- { role: hetzner_vlan, tags: ['hetzner-vlan-deploy', 'hetzner-vlan-remove'] }
- { role: permissions, tags: ['fix-permissions'] }
- { role: plex_auth_token, tags: ['plex-auth-token'] }
- { role: plex_extra_tasks, tags: ['plex-extra-tasks'] }
Expand Down

0 comments on commit 3459fd4

Please sign in to comment.