Initial commit
This commit is contained in:
62
ansible/roles/openwrt-common/tasks/main.yml
Normal file
62
ansible/roles/openwrt-common/tasks/main.yml
Normal file
@@ -0,0 +1,62 @@
|
||||
---
|
||||
- name: Gather OpenWrt facts
|
||||
setup:
|
||||
|
||||
- name: Check OpenWrt version
|
||||
shell: ". /etc/os-release && echo $VERSION"
|
||||
register: openwrt_version
|
||||
changed_when: false
|
||||
|
||||
- name: Display OpenWrt version
|
||||
debug:
|
||||
msg: "OpenWrt version: {{ openwrt_version.stdout }}"
|
||||
|
||||
- name: Update package lists
|
||||
shell: opkg update
|
||||
changed_when: false
|
||||
|
||||
- name: Check if packages are installed
|
||||
shell: opkg list-installed | grep -E "^(wireguard-tools|kmod-wireguard|kmod-vxlan|ip-full|tcpdump) " || true
|
||||
register: installed_packages
|
||||
changed_when: false
|
||||
|
||||
- name: Install required packages
|
||||
shell: opkg install {{ item }}
|
||||
loop:
|
||||
- wireguard-tools
|
||||
- kmod-wireguard
|
||||
- kmod-vxlan
|
||||
- ip-full
|
||||
- tcpdump
|
||||
when: item not in installed_packages.stdout
|
||||
register: package_install
|
||||
failed_when: package_install.rc != 0 and 'already installed' not in package_install.stderr
|
||||
|
||||
- name: Enable IP forwarding
|
||||
shell: |
|
||||
uci set network.@globals[0].ipv6_forwarding='1' 2>/dev/null || uci add network globals
|
||||
uci set network.@globals[0].ipv6_forwarding='1'
|
||||
uci commit network
|
||||
changed_when: true
|
||||
|
||||
- name: Configure sysctl settings
|
||||
blockinfile:
|
||||
path: /etc/sysctl.conf
|
||||
create: yes
|
||||
block: |
|
||||
net.ipv4.ip_forward=1
|
||||
net.ipv4.conf.all.rp_filter=0
|
||||
net.ipv4.conf.default.rp_filter=0
|
||||
net.bridge.bridge-nf-call-iptables=0
|
||||
net.bridge.bridge-nf-call-ip6tables=0
|
||||
marker: "# {mark} ANSIBLE MANAGED - Wireguard Lab"
|
||||
|
||||
- name: Apply sysctl settings
|
||||
shell: sysctl -p
|
||||
changed_when: false
|
||||
|
||||
- name: Create configuration backup
|
||||
shell: sysupgrade -b /tmp/backup-pre-wireguard-lab-$(date +%Y%m%d-%H%M%S).tar.gz
|
||||
args:
|
||||
creates: /tmp/backup-pre-wireguard-lab-*.tar.gz
|
||||
ignore_errors: yes
|
||||
Reference in New Issue
Block a user