Files
@ 7382c88e89fc
Branch filter:
Location: freifunk/Ansible-Configuration/gateway/initial_gw_setup.yml
7382c88e89fc
12.2 KiB
text/x-yaml
style: make initial-gw-setup conform MORE to the linter
Not perfect yet, but much better.
Issues right now lie with shell usage & permissions.
Not perfect yet, but much better.
Issues right now lie with shell usage & permissions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | ---
- name: Initial Gateway Setup
hosts: test
remote_user: root
become: true
become_method: ansible.builtin.sudo
vars:
batman: 2022.2
tasks:
- name: Install a list of packages
ansible.builtin.apt:
update_cache: true
pkg:
- git
- bridge-utils
- ntp
- dnsmasq
- iptables-persistent
- openvpn
- fastd
- build-essential
- pkg-config
- checkinstall
- libnl-3-dev
- libnl-genl-3-dev
- linux-headers-amd64
- dkms
- lsb-release
- ethtool
- python3
# Updating all packages to their latest version
- name: Update all packages to their latest version
ansible.builtin.apt:
update_cache: true
upgrade: "yes"
# Reboot and reconnect
- name: Reboot host and wait for it to restart
ansible.builtin.reboot:
msg: "Reboot initiated by Ansible"
connect_timeout: 5
reboot_timeout: 600
pre_reboot_delay: 0
post_reboot_delay: 30
test_command: whoami
# edit routing tables
- name: Add the routing table ports for freifunk
ansible.builtin.blockinfile:
path: /etc/iproute2/rt_tables
backup: true
block: |
# freifunk
33 lux
42 icvpn
100 vpn
# edit rsysctl config
- name: Add the freifunk settings to sysctl config
ansible.builtin.blockinfile:
path: /etc/sysctl.conf
backup: true
block: |
# Freifunk specific settings
net.ipv4.ip_forward=1
net.ipv4.icmp_errors_use_inbound_ifaddr=1
net.bridge.bridge-nf-call-arptables = 0
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.ipv6.conf.all.forwarding=1
net.ipv6.conf.all.autoconf = 1
net.ipv6.conf.default.autoconf = 0
net.ipv6.conf.eth0.autoconf = 1
net.ipv6.conf.all.accept_ra = 1
net.ipv6.conf.default.accept_ra = 0
net.ipv6.conf.eth0.accept_ra = 1
net.ipv4.conf.default.rp_filter = 2
# load kernel module
- name: Load kernel module
become: true
become_user: root
ansible.builtin.shell: modprobe br_netfilter
# edit the module list
- name: Add nf conntrack to modules
ansible.builtin.blockinfile:
path: /etc/modules
backup: true
block: |
nf_conntrack
# reload sysctl config
- name: Reload sysctl config
become: true
become_user: root
ansible.builtin.shell: sysctl -p /etc/sysctl.conf
# Reboot and reconnect
- name: Reboot host and wait for it to restart
ansible.builtin.reboot:
msg: "Reboot initiated by Ansible"
connect_timeout: 5
reboot_timeout: 600
pre_reboot_delay: 0
post_reboot_delay: 30
test_command: whoami
# create the Freifunk bridge interface file
# copy default interface file to remote host
- name: Copy interface file with owner and permissions
ansible.builtin.copy:
src: /home/fflux/Infrastructure-Intern/server_config/interface/freifunk
dest: /etc/network/interfaces.d/freifunk
owner: root
group: root
mode: '0644'
# create IPV4 Iptables rules
# copy default IPV4 iptables rules file to remote host
- name: Copy rulesv4 file with owner and permissions
ansible.builtin.copy:
src: /home/fflux/Infrastructure-Intern/server_config/iptables/rules.v4
dest: /etc/iptables/rules.v4
owner: root
group: root
mode: '0644'
# create dnsmasq file
# copy default dnsmasq file to remote host
- name: Copy dnsmasq file with owner and permissions
ansible.builtin.copy:
src: /home/fflux/Infrastructure-Intern/server_config/dnsmasq/fflux
dest: /etc/dnsmasq.d/fflux
owner: root
group: root
mode: '0644'
# Create directory fflux in fatsd
- name: Create the directory fflux in fastd if it does not exist
ansible.builtin.file:
path: /etc/fastd/fflux
state: directory
mode: '0755'
# create fastd config file
# copy default dnsmasq file to remote host
- name: Copy fastd config file with owner and permissions
ansible.builtin.copy:
src: /home/fflux/Infrastructure-Intern/server_config/fastd/fastd.conf
dest: /etc/fastd/fflux/fastd.conf
owner: root
group: root
mode: '0644'
# Create directory peers-gw in fatsd
- name: Create the directory peers-gw in fastd/fflux if it does not exist
ansible.builtin.file:
path: /etc/fastd/fflux/peers-gw
state: directory
mode: '0755'
# create fastd blacklist script
# copy fastd blacklist script to remote host
- name: Copy fastd blacklist script with owner and permissions
ansible.builtin.copy:
src: /home/fflux/Infrastructure-Intern/scripts/fastd-blacklist.sh
dest: /etc/fastd/fflux/fastd-blacklist.sh
owner: root
group: root
mode: '0755'
# change fasts autostart to all
# copy default fastd default file to remote host
- name: Copy fastd config file with owner and permissions
ansible.builtin.copy:
src: /home/fflux/Infrastructure-Intern/server_config/fastd/fastd
dest: /etc/default/fastd
owner: root
group: root
mode: '0644'
# Remove client directory from openvpn
- name: Remove client directory
ansible.builtin.file:
path: /etc/openvpn/client
state: absent
# Remove server from openvpn
- name: Remove server directory
ansible.builtin.file:
path: /etc/openvpn/server
state: absent
# create hideme config
# copy the default hidme config to remote host
- name: Copy hideme config with owner and permissions
ansible.builtin.copy:
src: /home/fflux/Infrastructure-Intern/server_config/openvpn/hideme.conf
dest: /etc/openvpn/hideme.conf
owner: root
group: root
mode: '0644'
# create hideme-up script
# copy hideme-up script to remote host
- name: Copy hideme-up script with owner and permissions
ansible.builtin.copy:
src: /home/fflux/Infrastructure-Intern/scripts/hideme-up
dest: /etc/openvpn/hideme-up
owner: root
group: root
mode: '0755'
- name: Copy hideme-down script with owner and permissions
ansible.builtin.copy:
src: /home/fflux/Infrastructure-Intern/scripts/hideme-down
dest: /etc/openvpn/hideme-down
owner: root
group: root
mode: '0755'
# create update resolv conf
# copy update-resolv.conf script to remote host
- name: Copy update-resolv.conf with owner and permissions
ansible.builtin.copy:
src: /home/fflux/Infrastructure-Intern/server_config/openvpn/update-resolv-conf
dest: /etc/openvpn/update-resolv-conf
owner: root
group: root
mode: '0755'
# Create for batman installation
- name: Create directory for batman installation
ansible.builtin.file:
path: /usr/src/batman-adv-{{ batman }}
state: directory
mode: '0755'
# Clone and check out batman repo
- name: Clone and check out batman git repo
ansible.builtin.git:
repo: 'https://git.open-mesh.org/batman-adv.git'
dest: /usr/src/batman-adv-{{ batman }}
version: v{{ batman }}
# create dkms conf
# copy dkms conf to remote host
- name: Copy dkms.conf with owner and permissions
ansible.builtin.copy:
src: /home/fflux/Infrastructure-Intern/server_config/dkms/dkms.conf
dest: /usr/src/batman-adv-{{ batman }}
owner: root
group: root
mode: '0644'
# create dkms install script
# copy dkms install script to remote host
- name: Copy dkms install script with owner and permissions
ansible.builtin.copy:
src: /home/fflux/Infrastructure-Intern/scripts/install_dkms.sh
dest: /usr/local/bin
owner: root
group: root
mode: '0744'
# create build batclt script
# copy build batctl script to remote host
- name: Copy build batctl script with owner and permissions
ansible.builtin.copy:
src: /home/fflux/Infrastructure-Intern/scripts/build_batctl.sh
dest: /usr/local/bin
owner: root
group: root
mode: '0744'
# Run batman scripts
- name: Run install_dkms.sh
ansible.builtin.command: bash /usr/local/bin/install_dkms.sh
- name: Run build_batctl.sh
ansible.builtin.command: /usr/local/bin/build_batctl.sh
# edit the module list
- name: Add batman-adv to modules
ansible.builtin.blockinfile:
path: /etc/modules
backup: true
block: |
nf_conntrack
batman-adv
- name: Creating a file with content
ansible.builtin.copy:
dest: "/etc/modules-load.d/freifunk.conf"
content: |
ebtables
batman_adv
# Reboot and reconnect
- name: Reboot host and wait for it to restart
ansible.builtin.reboot:
msg: "Reboot initiated by Ansible"
connect_timeout: 5
reboot_timeout: 600
pre_reboot_delay: 0
post_reboot_delay: 30
test_command: whoami
# create check gateway script
# copy check gateway script to remote host
- name: Copy check gateway script with owner and permissions
ansible.builtin.copy:
src: /home/fflux/Infrastructure-Intern/scripts/check_gateway.sh
dest: /usr/local/bin
owner: root
group: root
mode: '0755'
# create check vpn script
# copy check vpn script to remote host
- name: Copy check vpn script with owner and permissions
ansible.builtin.copy:
src: /home/fflux/Infrastructure-Intern/scripts/check_vpn.sh
dest: /usr/local/bin
owner: root
group: root
mode: '0755'
# Clone mesh-announce repo
- name: Clone mesh-announce git repo
ansible.builtin.git:
repo: 'https://github.com/ffnord/mesh-announce'
dest: /opt/mesh-announce
# TODO: Verify that there has been no update!
version: 40be9a18ee91fa058478bc04105cbd79fd70279e
# create respondd service
# copy respondd service script to remote host
- name: Copy respondd service script with owner and permissions
ansible.builtin.copy:
src: /home/fflux/Infrastructure-Intern/scripts/respondd.service
dest: /opt/mesh-announce/respondd.service
owner: root
group: root
mode: '0755'
# Create symlink for respondd service
- name: Create a symbolic link
ansible.builtin.file:
src: /opt/mesh-announce/respondd.service
dest: /etc/systemd/system/respondd.service
owner: root
group: root
state: link
force: true
# Stop respondd
- name: Stop systemd-resolved
ansible.builtin.service:
name: "systemd-resolved"
state: "stopped"
# create resolved conf
# copy resolved conf to remote host
- name: Copy resolved.conf with owner and permissions
ansible.builtin.copy:
src: /home/fflux/Infrastructure-Intern/server_config/systemd-resolved/resolved.conf
dest: /etc/systemd/resolved.conf
owner: root
group: root
mode: '0644'
# Create symlink for resolved.con
- name: Create a symbolic link
ansible.builtin.file:
src: /run/systemd/resolve/resolv.conf
dest: /etc/resolv.conf
owner: root
group: root
state: link
force: true
# Start respondd
- name: Start systemd-resolved
ansible.builtin.service:
name: "systemd-resolved"
state: "started"
# create default crontab
# copy default crontab to remote host
- name: Copy crontab with owner and permissions
ansible.builtin.copy:
src: /home/fflux/Infrastructure-Intern/server_config/crontab/crontab
dest: /etc/crontab
owner: root
group: root
mode: '0644'
# Reboot and reconnect
- name: Reboot host and wait for it to restart
ansible.builtin.reboot:
msg: "Reboot initiated by Ansible"
connect_timeout: 5
reboot_timeout: 600
pre_reboot_delay: 0
post_reboot_delay: 30
test_command: whoami
|