initial transfer
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
# network:wifi:connection
|
||||
|
||||
**Configure a WiFi client connection using NetworkManager**
|
||||
|
||||
## Purpose
|
||||
|
||||
This cube allows you to connect your target host (e.g., a Raspberry Pi or a laptop) to an existing WiFi network using `nmcli`.
|
||||
|
||||
## What This Cube Does
|
||||
|
||||
1. Ensures `network-manager` is installed and running
|
||||
2. Removes any existing connection with the same name to avoid conflicts
|
||||
3. Connects to the specified `SSID` using the provided `PASSWORD`
|
||||
4. Configures the connection to automatically connect on boot (optional)
|
||||
|
||||
## Configuration
|
||||
|
||||
| Variable | Type | Description | Required | Default |
|
||||
| :--- | :--- | :--- | :--- | :--- |
|
||||
| `SSID` | `string` | The WiFi network name | Yes | - |
|
||||
| `PASSWORD` | `string` | The WiFi password | Yes | - |
|
||||
| `AUTOCONNECT` | `boolean` | Automatically connect to this network | No | `true` |
|
||||
| `CONNECTION_NAME` | `string` | Name for the connection in NetworkManager | No | `SSID` |
|
||||
|
||||
## Dependencies
|
||||
|
||||
- `apt/essentials`: Basic system utilities.
|
||||
|
||||
## Usage
|
||||
|
||||
### Simple Connection
|
||||
|
||||
```bash
|
||||
nopy install network:wifi:connection --env SSID="MyHomeWiFi" --env PASSWORD="mysecurepassword"
|
||||
```
|
||||
|
||||
### Connection with Custom Name and No Autoconnect
|
||||
|
||||
```bash
|
||||
nopy install network:wifi:connection --env SSID="OfficeWiFi" --env PASSWORD="password123" --env CONNECTION_NAME="Work" --env AUTOCONNECT=false
|
||||
```
|
||||
|
||||
## Security Notes
|
||||
|
||||
- WiFi passwords will be stored in `/etc/NetworkManager/system-connections/` on the target host.
|
||||
- Passing passwords via `--env` may leave them in your local shell history.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
You can check the status of your WiFi connections on the target host with:
|
||||
```bash
|
||||
nmcli connection show
|
||||
nmcli device status
|
||||
```
|
||||
@@ -0,0 +1,43 @@
|
||||
from pyinfra import host
|
||||
from pyinfra.operations import apt, server, systemd
|
||||
|
||||
# [agnt://cogen/cogen/network-wifi-connection-2]{cartridge: "ansiblings/cubes", action: "generated", status: "generated"}
|
||||
|
||||
"""
|
||||
Deployment script for network:wifi:connection.
|
||||
Uses nmcli to configure a WiFi client connection.
|
||||
"""
|
||||
|
||||
SSID = host.data.SSID
|
||||
PASSWORD = host.data.PASSWORD
|
||||
AUTOCONNECT = "yes" if host.data.get('AUTOCONNECT', True) else "no"
|
||||
CONNECTION_NAME = host.data.get('CONNECTION_NAME', SSID)
|
||||
|
||||
# Install NetworkManager if not present
|
||||
apt.packages(
|
||||
name='Install NetworkManager',
|
||||
packages=['network-manager'],
|
||||
update=True,
|
||||
_sudo=True
|
||||
)
|
||||
|
||||
# Ensure NetworkManager is running
|
||||
systemd.service(
|
||||
name='Ensure NetworkManager is running',
|
||||
service='NetworkManager',
|
||||
running=True,
|
||||
enabled=True,
|
||||
_sudo=True
|
||||
)
|
||||
|
||||
# Add/Update the WiFi connection
|
||||
# We delete first to ensure a clean state with the new password/settings
|
||||
server.shell(
|
||||
name=f"Configure WiFi connection for {SSID}",
|
||||
commands=[
|
||||
f'nmcli connection delete "{CONNECTION_NAME}" || true',
|
||||
f'nmcli device wifi connect "{SSID}" password "{PASSWORD}" name "{CONNECTION_NAME}"',
|
||||
f'nmcli connection modify "{CONNECTION_NAME}" connection.autoconnect {AUTOCONNECT}',
|
||||
],
|
||||
_sudo=True
|
||||
)
|
||||
@@ -0,0 +1,19 @@
|
||||
import { z } from 'zod';
|
||||
import { cubes } from '@bitstack/nopy';
|
||||
|
||||
// [agnt://cogen/cogen/network-wifi-connection-1]{cartridge: "ansiblings/cubes", action: "generated", status: "generated"}
|
||||
|
||||
/**
|
||||
* Manifest for the network:wifi:connection cube.
|
||||
* Configures a WiFi client connection using NetworkManager (nmcli).
|
||||
*/
|
||||
export default cubes.Manifest({
|
||||
id: 'net:wifi:connection',
|
||||
name: 'network:wifi:connection - Connect to a WiFi network',
|
||||
schema: z.object({
|
||||
SSID: z.string().min(1).describe('The SSID of the WiFi network to connect to'),
|
||||
PASSWORD: z.string().min(8).describe('The password for the WiFi network'),
|
||||
AUTOCONNECT: z.boolean().default(true).describe('Whether to automatically connect to this network'),
|
||||
CONNECTION_NAME: z.string().optional().describe('Optional name for the connection (defaults to SSID)'),
|
||||
})
|
||||
});
|
||||
Reference in New Issue
Block a user