I currently have a config file that looks like this:
- type: physical
- type: static
- type: nameserver
- name: ansible
sudo: ALL=(ALL) NOPASSWD:ALL
and I’m spinning up an instance like this:
lxc launch ubuntu:jammy my-test --profile default < ./config.yml
If I wanted to specify a different ip address though, how would I specify in the launch command without going in and editing the config file?
You can change each config easily using
lxc config set command, for example:
lxc config set instance-name boot.autostart false
And then you can check changes using this command:
lxc config show instance-name
For the IP address, if you want to assign static IP, you can use these commands:
lxc network attach lxdbr0 instance-name eth0 eth0
lxc config device set instance-name eth0 ipv4.address 10.99.10.42
Your config file is using a
macvlan NIC, which is connected to an external network parent
As such LXD cannot provide static DHCP allocations, and thus cannot control the IP the instance is given.
Instead you have passed cloud-init config to the instance, so it will self-configure its own static IP settings when cloud-init runs inside it at first start.
However if you want to change that IP without editing the config file then you will need to use some sort of templating system and pass that config file through a pre-processor step before passing it to
lxc launch command.
This could be as simple as using something like
awk to find and replace a placeholder in the file.