Changeset - a9ca3f5ae102
[Not reviewed]
master
0 2 0
x - 3 days ago 2025-08-24 15:15:44
xbr@c3l.lu
add: interactive debugging packages
2 files changed with 3 insertions and 0 deletions:
0 comments (0 inline, 0 general)
gateway/initial_gw_setup.yml
Show inline comments
 
---
 
- name: Initial Gateway Setup
 
  hosts: initial-gateway
 
  become: true
 
  become_method: ansible.builtin.sudo
 

	
 
  tasks:
 
    # Update packages
 
    - name: Update all packages to their latest version
 
      ansible.builtin.apt:
 
        update_cache: true
 
        upgrade: "yes"
 
      tags: update
 
    - name: Install a list of packages
 
      ansible.builtin.apt:
 
        update_cache: true
 
        pkg:
 
          - git
 
          - bridge-utils
 
          - batctl
 
          - ntpsec
 
          - dnsmasq
 
          - iptables-persistent
 
          - openvpn
 
          - fastd
 
          - build-essential
 
          - pkg-config
 
          - checkinstall
 
          - libnl-3-dev
 
          - libnl-genl-3-dev
 
          - linux-headers-amd64
 
          - systemd-resolved # We current use it later, but we don't really need it
 
          - dkms
 
          - lsb-release
 
          - ethtool
 
          - python3
 
          - wget # for fastd-blacklist
 
          - tcpdump # for debugging
 
      tags: update
 

	
 
    # fix systemd-resolved's default config
 
    - name: Stop systemd-resolved
 
      ansible.builtin.service:
 
        name: "systemd-resolved"
 
        state: "stopped"
 
      tags: config
 
    - name: Copy resolved.conf
 
      ansible.builtin.copy:
 
        src: "{{ server_config_dir }}/systemd-resolved/resolved.conf"
 
        dest: /etc/systemd/resolved.conf
 
        owner: root
 
        group: root
 
        mode: "0644"
 
      tags: config
 
    - name: Remove immutable attribute on resolv.conf
 
      ansible.builtin.file:
 
        dest: /etc/resolv.conf
 
        attributes: '-i'
 
      become: true
 
      tags: config
 
    - name: Create a symbolic link for resolv.conf, replacing the initial resolv.conf
 
      ansible.builtin.file:
 
        src: /run/systemd/resolve/resolv.conf
 
        dest: /etc/resolv.conf
 
        owner: root
 
        group: root
 
        state: link
 
        attributes: '-i'
 
        force: true
 
      become: true
 
      tags: config
 
    - name: Start systemd-resolved
 
      ansible.builtin.service:
 
        name: "systemd-resolved"
 
        state: "started"
 
        enabled: "true"
 
      tags: config
 

	
 
    - name: Ensure /etc/iproute2 exists
 
      ansible.builtin.file:
 
        path: /etc/iproute2
 
        state: directory
 
        mode: '0755'
 
      tags: config
 
    - name: Copy routing table if non-existing
 
      ansible.builtin.copy:
 
        remote_src: true
 
        src: /usr/share/iproute2/rt_tables
 
        dest: /etc/iproute2/rt_tables
 
        force: false
 
      tags: config
 
    - name: Add the routing table for freifunk
 
      ansible.builtin.blockinfile:
 
        path: /etc/iproute2/rt_tables
 
        backup: true
 
        block: |
 
          # freifunk
 
          33      lux
 
          42      icvpn
 
          100     vpn
 
      tags: config
 

	
 
    # Modules
 
    - name: Load `br_netfilter` kernel module
 
      community.general.modprobe:
 
        name: "br_netfilter"
 
        persistent: "present"
 
        state: "present"
 
    - name: Add `nf_conntrack` to modules
 
      community.general.modprobe:
 
        name: "nf_conntrack"
 
        state: "present"
 
        persistent: "present"
 
      tags: config
 

	
 
    # Sysctl
 
    - name: Add the freifunk settings to sysctl config
 
      ansible.builtin.blockinfile:
 
        path: /etc/sysctl.d/80-fflux.conf
 
        create: 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
 
      tags: config
 
    - name: Reload sysctl config
 
      ansible.builtin.shell: sysctl --system
 
      tags: config
 

	
 
    # Basic networking
 
    - name: Setup network interfaces (bridge + bat0)
 
      ansible.builtin.template:
 
        src: "{{ server_config_dir }}/interface/freifunk.j2"
 
        dest: /etc/network/interfaces.d/freifunk
 
        owner: root
 
        group: root
 
        mode: "0644"
 
      tags: config
 
    - name: Pull up new interfaces
 
      ansible.builtin.command: /usr/sbin/ifup -a
 
      tags: config
 
    - name: Copy iptables rulesv4
 
      ansible.builtin.copy:
 
        src: "{{ server_config_dir }}/iptables/rules.v4"
 
        dest: /etc/iptables/rules.v4
 
        owner: root
 
        group: root
 
        mode: "0644"
 
      tags: config
 
    - name: Restart iptables-persistent
 
      ansible.builtin.service:
 
        name: "netfilter-persistent"
 
        state: "restarted"
 
        enabled: true
 
      tags: config
 
    - name: Setup dnsmasq config w/ IPv4 ranges
 
      ansible.builtin.template:
 
        src: "{{ server_config_dir }}/dnsmasq/fflux.j2"
 
        dest: /etc/dnsmasq.d/fflux
 
        owner: root
 
        group: root
 
        mode: "0644"
 
      tags: config
 

	
 
    # fastd
 
    - name: Make sure fastd is disabled and stopped
 
      ansible.builtin.service:
 
        name: "fastd"
 
        state: "stopped"
 
        enabled: false
 
      tags: config
 
    - name: Create the fflux dir inside of fastd
 
      ansible.builtin.file:
 
        path: /etc/fastd/fflux
 
        state: directory
 
        mode: "0755"
 
      tags: config
 
    - name: Setup fastd (fflux) config w/ MAC address
 
      ansible.builtin.template:
 
        src: "{{ server_config_dir }}/fastd/fastd.conf.j2"
 
        dest: /etc/fastd/fflux/fastd.conf
 
        owner: root
 
        group: root
 
        mode: "0644"
 
      tags: config
 
    - name: Create peers-gw directory in fastd/fflux
 
      ansible.builtin.file:
 
        path: /etc/fastd/fflux/peers-gw
 
        state: directory
 
        mode: "0755"
 
      tags: config
 
    - name: List all peers but ourselves
 
      ansible.builtin.find:
 
        path: "{{ server_config_dir }}/fastd/peers-gw/"
 
        excludes: "{{ inventory_hostname }}"
 
      delegate_to: localhost
 
      become: false
 
      register: peers_to_copy
 
      tags: config
 
    - name: Copy fastd peers
 
      ansible.builtin.copy:
 
        src: "{{ item.path }}"
 
        dest: /etc/fastd/fflux/peers-gw/
 
        owner: root
 
        mode: "0644"
 
      with_items: "{{ peers_to_copy.files }}"
 
      tags: config
 
    - name: Copy fastd blacklist script
 
      ansible.builtin.copy:
 
        src: "{{ server_scripts_dir }}/fastd-blacklist.sh"
 
        dest: /etc/fastd/fflux/fastd-blacklist.sh
 
        owner: root
 
        group: root
 
        mode: "0755"
 
      tags: config
initial_server_setup/initial_setup.yml
Show inline comments
 
---
 
- name: Initial Server Setup
 
  hosts: initial
 
  become: true
 

	
 
  vars_files:
 
    - ../user_vars.yml
 
  vars:
 
    password: Welcome1234
 
    ansible_managed: "This file is managed by Ansible. Do not modify."
 

	
 
  tasks:
 
    - name: Update + Upgrade packages
 
      ansible.builtin.apt:
 
        upgrade: true
 
        update_cache: true
 
      tags: basic
 

	
 
    - name: Install some basic packages
 
      ansible.builtin.apt:
 
        pkg:
 
          - sudo
 
          - git
 
          - vim
 
          - python3
 
          - python3-pip
 
          - tmux
 
          - man-db
 
      tags: basic
 

	
 
    # Change Hostname
 
    - name: "Update Hostnames"
 
      ansible.builtin.hostname:
 
        name: "{{ inventory_hostname }}"
 
      tags: hostname
 

	
 
    # Update /etc/hosts
 
    - name: Make sure an IPV4 entry in /etc/hosts exists
 
      ansible.builtin.lineinfile:
 
        path: /etc/hosts
 
        regexp: "^{{ ansible_default_ipv4.address }}"
 
        line: "{{ ansible_default_ipv4.address }} {{ inventory_hostname }} {{ inventory_hostname }}.freifunk.lu"
 
        state: present
 
      tags: network,hostname,dns
 
    - name: Make sure an IPV6 entry in /etc/hosts exists
 
      ansible.builtin.lineinfile:
 
        path: /etc/hosts
 
        regexp: "^{{ ansible_default_ipv6.address }}"
 
        line: "{{ ansible_default_ipv6.address }} {{ inventory_hostname }} {{ inventory_hostname }}.freifunk.lu"
 
        state: present
 
      tags: network,hostname,dns
 

	
 
    # SSH security improvements (EmptyPass, PassAuth, RootLogin)
 
    - name: Disable SSH Password Auth
 
      ansible.builtin.copy:
 
        dest: /etc/ssh/sshd_config.d/disable_password_auth.conf
 
        owner: root
 
        mode: u=rw,g=r,o=r
 
        content: |
 
          # {{ ansible_managed }}
 
          PasswordAuthentication no
 
      tags: network,ssh
 
      register: pass_auth
 
    - name: Remove SSH Password Auth from sshd_config
 
      ansible.builtin.lineinfile:
 
        path: /etc/ssh/sshd_config
 
        regex: "^PasswordAuthentication"
 
        line: "# PasswordAuthentication No"
 
      tags: network,ssh
 
      register: pass_auth_sshd
 
    - name: Disable SSH Empty Password
 
      ansible.builtin.copy:
 
        dest: /etc/ssh/sshd_config.d/disable_empty_password.conf
 
        owner: root
 
        mode: u=rw,g=r,o=r
 
        content: |
 
          # {{ ansible_managed }}
 
          PermitEmptyPasswords no
 
      tags: network,ssh
 
      register: empty_pass
 
    - name: Remove SSH Empty Password from sshd_config
 
      ansible.builtin.lineinfile:
 
        path: /etc/ssh/sshd_config
 
        regex: "^PermitEmptyPasswords"
 
        line: "# PermitEmptyPasswords No"
 
      tags: network,ssh
 
      register: empty_pass_sshd
 
    - name: Disable SSH Root Login
 
      ansible.builtin.copy:
 
        dest: /etc/ssh/sshd_config.d/disable_root_login.conf
 
        owner: root
 
        mode: u=rw,g=r,o=r
 
        content: |
 
          # {{ ansible_managed }}
 
          PermitRootLogin no
 
      tags: network,ssh
 
      register: root_login
 
    - name: Remove SSH Root Login from sshd_config
 
      ansible.builtin.lineinfile:
 
        path: /etc/ssh/sshd_config
 
        regex: "^PermitRootLogin"
 
        line: "# PermitRootLogin No"
 
      tags: network,ssh
 
      register: root_login_sshd
 
    - name: Reload SSHD
 
      ansible.builtin.service:
 
        name: "sshd"
 
        state: "reloaded"
 
      tags: network,ssh
 
      when: pass_auth.changed or pass_auth_sshd.changed or empty_pass.changed or empty_pass_sshd.changed or root_login.changed or root_login_sshd.changed
 

	
 
    # Create Freifunk Users
 
    - name: Create member users
 
      ansible.builtin.user:
 
        name: "{{ item.username }}"
 
        password: "{{ password | password_hash('sha512') }}"
 
        update_password: "on_create"
 
        groups:
 
          - sudo
 
        append: true
 
        shell: /bin/bash
 
        state: present
 
      loop: "{{ users_member }}"
 
      tags: users
 
    - name: Create system users (no password)
 
      ansible.builtin.user:
 
        name: "{{ item.username }}"
 
        groups:
 
          - sudo
 
        append: true
 
        shell: /bin/bash
 
        state: present
 
      loop: "{{ users_system }}"
 
      tags: users
 
    - name: Change shell for root to bash
 
      ansible.builtin.user:
 
        name: "root"
 
        shell: /bin/bash
 
      tags: users
 
    - name: Add color etc. into root bashrc
 
      ansible.builtin.blockinfile:
 
        marker: "# {mark} ANSIBLE MANAGED BLOCK / Enhanced root bashrc"
 
        block: "{{ lookup('ansible.builtin.file', '{{ server_config_dir }}/bashrc_root_config') }}"
 
        path: /root/.bashrc
 
      tags: users
 

	
 

	
 
    - name: Add SSH key for users from vars
 
      ansible.posix.authorized_key:
 
        user: "{{ item.username }}"
 
        state: present
 
        key: "{{ lookup('file', item.key_path) }}"
 
      tags: users
 
      loop: "{{ users_member | union(users_system) }}"
 

	
 
    - name: Allow for password-less sudo
 
      # Not done via community.general.sudoders because it does not support
 
      # sudo-ing into users without a passsword.
 
      ansible.builtin.copy:
 
        dest: /etc/sudoers.d/passwordless-sudo
 
        content: '%sudo   ALL=(ALL:ALL) NOPASSWD: ALL'
 
        owner: root
 
        group: root
 
        mode: '0440'
 
      tags: users
0 comments (0 inline, 0 general)