| Crates.io | lxcmgt |
| lib.rs | lxcmgt |
| version | 0.3.0 |
| created_at | 2025-12-08 14:23:11.716634+00 |
| updated_at | 2025-12-09 01:13:50.438561+00 |
| description | A command-line tool for automating the setup and configuration of LXD containers |
| homepage | |
| repository | https://github.com/JeanMaximilienCadic/lxcmgt |
| max_upload_size | |
| id | 1973604 |
| size | 55,734 |
A command-line tool for automating the setup and configuration of LXD containers with cloud-init, static IP assignment, environment variables, and SSH key management.
.env filesgit clone https://github.com/JeanMaximilienCadic/lxcmgt
cd lxcmgt
cargo build --release
The binary will be available at target/release/lxcmgt.
cargo install --path .
lxcmgt
# or
lxcmgt --help
# Show the embedded default profile YAML configuration
lxcmgt show-config
# Restart LXD network daemon and flush iptables
lxcmgt restart-network
This command will:
Note: This command requires root/sudo privileges.
# Resolve a DNS record to its IP address
lxcmgt resolve yoii-dev.alterdns.com
This command uses getent hosts to resolve the hostname and extracts the IP address.
# Build container with default settings (requires lxd/.env file)
lxcmgt build --env-file lxd/.env
# Build container using an existing LXD profile (skips env file validation)
lxcmgt build --from-config my-existing-profile
# Custom project and container
lxcmgt build \
--project myproject \
--container mycontainer \
--env-file lxd/.env
# Custom bridge network
lxcmgt build \
--bridge mybridge \
--env-file lxd/.env
# Custom IP address
lxcmgt build \
--container-ip 10.2.0.100 \
--env-file lxd/.env
# Custom container image
lxcmgt build \
--image ubuntu:22.04 \
--env-file lxd/.env
# Use custom profile YAML file
lxcmgt build --profile-yaml /path/to/custom.yaml
# Use existing LXD profile (skips env file and profile YAML validation)
lxcmgt build --from-config my-existing-profile
lxcmgt build \
--project myproject \
--container mycontainer \
--container-ip 10.2.0.100 \
--bridge lxdbr1 \
--image ubuntu:24.04 \
--env-file /path/to/.env \
--profile-yaml /path/to/profile.yaml
| Argument | Environment Variable | Default | Description |
|---|---|---|---|
--project |
PROJECT |
default |
LXD project name |
--container |
CONTAINER |
default-dev |
Container name |
--container-ip |
CONTAINER_IP |
10.2.0.2 |
Container IP address |
--bridge |
BRIDGE |
lxdbr0 |
Network bridge name |
--image |
IMAGE |
ubuntu:24.04 |
Container image (e.g., ubuntu:24.04, ubuntu:22.04) |
--profile-yaml |
PROFILE_YAML |
(none) | Path to custom profile YAML file |
--env-file |
ENV_FILE |
lxd/.env |
Path to environment variables file |
--from-config |
FROM_CONFIG |
(none) | Existing LXD profile name to reuse |
| Command | Description |
|---|---|
build |
Build and configure the LXD container |
show-config |
Display the default embedded profile YAML configuration |
restart-network |
Restart LXD network daemon and flush iptables |
resolve <hostname> |
Resolve DNS record to IP address |
All command-line arguments can be set via environment variables:
export PROJECT=myproject
export CONTAINER=mycontainer
export CONTAINER_IP=10.2.0.100
export BRIDGE=lxdbr1
export IMAGE=ubuntu:24.04
export ENV_FILE=/path/to/.env
export PROFILE_YAML=/path/to/profile.yaml
export FROM_CONFIG=my-existing-profile
lxcmgt build
You can reuse an existing LXD profile that's already configured in your LXD instance. This skips the env file and profile YAML validation.
Usage:
# Use an existing profile named "my-profile"
lxcmgt build --from-config my-profile
# The profile must exist in the specified project
lxcmgt build --project myproject --from-config my-profile
When using --from-config, the tool will:
The environment file (.env) should contain KEY=VALUE pairs:
# lxd/.env
DATABASE_URL=postgresql://localhost/mydb
API_KEY=secret-key-123
DEBUG=true
When using the default embedded profile, the tool uses a pre-configured YAML template that includes:
foo user)You can provide a custom profile YAML file using --profile-yaml:
lxcmgt build --profile-yaml /path/to/custom-profile.yaml
Place SSH public keys in lxd/authorized_keys (one per line). The tool will automatically install them for the foo user.
When using the default embedded profile (--profile-yaml not specified):
--env-file argument is REQUIREDKEY=VALUE pairsWhen using a custom profile YAML (--profile-yaml specified):
--env-file argument is optionalWhen using --from-config:
--env-file and --profile-yaml validation are skippedThe build command performs the following steps:
The restart-network command performs the following steps:
# Create lxd/.env file
cat > lxd/.env << EOF
DATABASE_URL=postgresql://localhost/mydb
API_KEY=my-secret-key
EOF
# Build container
lxcmgt build --env-file lxd/.env
lxcmgt build \
--project production \
--container app-server \
--container-ip 10.2.0.50 \
--env-file lxd/.env
lxcmgt build \
--profile-yaml /path/to/my-profile.yaml \
--container mycontainer
# Use an existing LXD profile that's already configured
lxcmgt build \
--project production \
--container app-server \
--container-ip 10.2.0.50 \
--from-config my-existing-profile
# Use a different Ubuntu version
lxcmgt build \
--image ubuntu:22.04 \
--env-file lxd/.env
# Use a different base image
lxcmgt build \
--image alpine:latest \
--env-file lxd/.env
# Display the embedded default profile YAML
lxcmgt show-config > lxd/default-profile.yaml
# Restart LXD network daemon and flush iptables
# Useful when experiencing network issues or after iptables changes
sudo lxcmgt restart-network
# Resolve a DNS record to get its IP address
lxcmgt resolve yoii-dev.alterdns.com
# Output: 192.168.1.100 (example IP)
If you see an error about the environment file not being found:
❌ Error: Environment file not found at "lxd/.env"
Solution: Either:
lxd/.env file with your environment variables, orlxcmgt build --env-file /path/to/.env, orlxcmgt build --profile-yaml /path/to/profile.yamlThe tool automatically deletes existing containers before creating new ones. If you encounter issues, manually delete the container first:
lxc delete <container-name> --force --project <project-name>
Ensure you have appropriate LXD permissions:
# Add your user to the lxd group
sudo usermod -aG lxd $USER
# Log out and log back in
cargo build
cargo test
cargo run -- build --env-file lxd/.env