Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

systemd_network resource does not allow multiple addresses #137

Open
schrd opened this issue Aug 10, 2018 · 3 comments
Open

systemd_network resource does not allow multiple addresses #137

schrd opened this issue Aug 10, 2018 · 3 comments

Comments

@schrd
Copy link

schrd commented Aug 10, 2018

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
@nathwill
Copy link
Owner

thanks for the report @schrd :)

some variation of this comes up every once in a while and i'm still not super sure what a workable solution looks like... option_value is definitely designed to convert arrays into space-separated strings, because that's how systemd handles array-type arguments (e.g. Before=, After=, which take lists of units). for now, i think using the precursor property will let you inject an extra address field.

in the past, the way we've worked around the limitation has been to use drop-in resources or the precursor property when needing to provide the same directive more than once.

i'm open to any backwards-compatible suggestions!

@schrd
Copy link
Author

schrd commented Aug 13, 2018

@nathwill what do you think about using classes to differentiate between the two ways of handling arrays? See #138

@jklare
Copy link

jklare commented Sep 6, 2018

@schrd I also ran into this issue while trying to assign multiple vlans on one interface. After playing around a little with different solutions i went for the "ruby is anarchy" one and defined it like this:

systemd_network 'eth0' do
  match_name 'eth0'
  network_vlan "eth0.2\nVLAN = eth0.8"
end

IMHO this is ugly, but still better than defining a switchcase for each possible argument to differentiate between the different styles that are accepted by systemd configs. Maybe this should rather be fixed in systemd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants