I have a Ubuntu 18.04 host which is running virtual machines, docker containers, and now LXC containers.
That machines has a network card, eno1
, a br0
bridge that uses eno1
, and lxdbr0
which is the default LXD bridge config.
I’m using Ansible to create new containers, and I’d like to be able to give those containers a static IP address.
If I do:
devices:
eth0:
name: eth0
nictype: macvlan
parent: br0
type: nic
ipv4.address: 192.168.1.10
Then lxc ls
shows that the container has no IP.
If I put ipv4.address: auto
, then the container gets a 192.168.1.xxx IP in my DHCP range and I can ping it from another host, but the IP is dynamic.
I also tried creating a profile with
user.user-data: |
# cloud-config
package-upgrade: true
packages:
- python-minimal
timezone: Etc/UTC
network:
version: 2
ethernets:
eth0:
dhcp4: false
and then create the container with
user.user-data: |
# cloud-config
network:
version: 2
ethernets:
eth0:
dhcp4: false
addresses: [192.168.1.10/24]
I hoped it would merge the profile’s cloud-init and the manually supplied one. But no, no luck.
How do I make this work? Is there a way without modifying the lxdbr0
config or the dnsmasq config file?