Skip to content

systemd_network resource does not allow multiple addresses #137

@schrd

Description

@schrd

A network unit file can specify multiple static addresses for an interface. Even mixing of IPv4 and IPv6 addresses is possible. A working example would look like

[Match]
Name = en* eth*

[Network]
DHCP = no
Address = 192.168.121.4/24
Address = 192.168.121.2/24

If I specify a systemd_network resource such as

systemd_network 'static' do
  match_name 'en* eth*'
  network_address ['192.168.121.4/24', '192.168.121.2/24']
end

produces an invalid file which systemd-networkd rejects:

[Match]
Name = en* eth*

[Network]
DHCP = no
Address = 192.168.121.4/24 192.168.121.2/24

To me it looks like SystemdCookbook::Mixin::PropertyHashConversion::InstanceMethods#option_value is causing the issue.

The systemd_unit resource correctly converts arrays to multiple entries:

u = systemd_unit 'test.service' do
  content({
    Unit: {
      Description: ['Foo', 'bar']
    }
  })
end

file "/tmp/test.ini" do
  content u.to_ini
end

produces

[Unit]
Description = Foo
Description = bar

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions