IP prefix variable in host interfaces array to use for netplan configuration

Problem: Trying to adapt preseed_networking_setup to configure netplan

Expected outcome: New variable for use similar to <%= host_subnet.mask %> to use or a method to convert it to a prefix. I can see here (https://projects.theforeman.org/projects/foreman/wiki/TemplateWriting) IPv6 has a field like this (for obvious reasons).

Foreman and Proxy versions: 1.21.0

Foreman and Proxy plugin versions: 1.21.0

Neplan uses prefixes instead of netmasks in the configuration file. An example below.

network:
    version: 2
    ethernets:
      enp0s3:
        addresses: [192.168.0.140/24]
        gateway4: 192.168.0.1
        nameservers:
          addresses: [8.8.8.8,8.8.4.4]
1 Like

Before you go too deep writing a custom template, you may want to take a look at https://github.com/theforeman/community-templates/pull/545 which aims to do the same and has had some review already.

3 Likes

Yep, it’s <%= host_subnet.cidr %>.

1 Like

@alexandrud I’m also in desperate need of a working Netplan configuration for Ubuntu 18.04. I wrote a new template and submitted a PR at https://github.com/theforeman/community-templates/pull/568 . Feel free to give it a try.