How to Override Values From the Config File?

I currently have a config file that looks like this:

    nictype: macvlan
    parent: enp3s0
    type: nic
config: |
    version: 1
      - type: physical
        name: eth0
          - type: static
            ipv4: true
            ipv6: true
            control: auto
      - type: nameserver
  cloud-init.user-data: |
      - name: ansible
          - pub_key
        shell: /bin/bash
        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

Your config file is using a macvlan NIC, which is connected to an external network parent enp3s0.
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.

1 Like