drew1kun.rpi_network

Ansible Role: rpi_network

This role does the following:

  • Configures wireless adapters (both built-in and external USB) to have consistent names (like wlan0, wlan1) based on their MAC addresses.
  • Sets up wireless adapters to receive an IP address from DHCP.
  • Configures wired ethernet adapters to obtain an IP address from DHCP.
  • Assigns an additional static IP address to wired ethernet adapters.
  • Sets the default IP route through the specified default gateway.

Requirements

  • This role requires Ansible to gather system facts.

You must use one of these operating systems (or their derivatives):

  • Debian | Raspberry Pi OS | Raspbian | Minibian
    • jessie
    • stretch
    • bullseye

Role Variables

Variable Description Default
rpi_network_LAN Wired LAN interface eth0
rpi_network_WLAN Wireless LAN interface wlan0
rpi_network_LAN_ip Static IP address for the LAN interface 192.168.3.2
rpi_network_LAN_netmask Subnet mask for the LAN interface 255.255.255.0
rpi_network_LAN_gw Default Gateway IP address for the LAN interface 192.168.3.1
rpi_network_wireless Configure wireless connections using wpa_supplicant true
rpi_network_wpa_supplicant_conf Path to the wpa_supplicant configuration file /etc/wpa_supplicant/wpa_supplicant.conf
rpi_network_wifi_APs List of wireless Access Points to configure in wpa_supplicant See defaults/main.yml for details.

Important! If rpi_network_wireless is set to true, you must update the vault_rpi_network_wifi_APs variable because it contains sensitive information for your wireless networks, like WPA passphrase and ESSID.

It is strongly advised to use ansible-vault for encrypting this information.

Before running any playbook that uses this role, add this to your ansible.cfg file:

[defaults]
vault_password_file = .vault.key

Dependencies

  • None

Example Playbook

- hosts: rpi_3
  gather_facts: yes

  vars_files:
  - vars/vault.yml  # Use ansible-vault for sensitive info

  roles:
  - role: drew1kun.rpi_network
    rpi_network_LAN_ip: 10.0.0.1
    rpi_network_LAN_netmask: 255.255.255.0
    rpi_network_LAN_gw: 10.0.0.254
    rpi_network_wifi_APs:
    - id_str: home
      hidden: no
      essid: "{{ vault_rpi_bootstrap__rpi_network_wifi_APs[0].essid }}"
      passphrase: "{{ vault_rpi_bootstrap__rpi_network_wifi_APs[0].passphrase }}"
      priority: 10
    when: ansible_os_family == 'Debian'

vars/vault.yml:

vault_rpi_bootstrap__rpi_network_wifi_APs:
- essid: YourSensitiveESSID
  passphrase: YourSecureWPA_Passphrase

License MIT License

Author Information Andrew Shagayev | Email

Informazioni sul progetto

Ansible role for Raspberry Pi basic network configuration.

Installa
ansible-galaxy install drew1kun.rpi_network
Licenza
mit
Download
81
Proprietario