Preseed template ubuntu 20 for netplan

Problem:
Hi,

Due to a missing preseed template for ubuntu 20 in order to create a netplan network config-file, I started to build one myself.

I have a working template, but for bridges I could see that “bridge.subnet6” could not be used in the template:

Code in the template:

<%- bridge_subnet6 = bridge.subnet6 -%>
<%- bridge_dhcp = bridge_subnet6.nil? ? false : bridge_subnet.dhcp_boot_mode? -%>

However, this can be used without any problem for other types of interfaces like bond, vlan and remaining managed.interfaces.

Is this effectively something missing in the product?

Anyway, currently I have something working (not the best way of coding due to missing knowledge of erb, and for now only for ipv4 config), see example-result conform the netplan-syntaxes, and tested on a ubuntu 20 system (installed manually):

Please let me know to who or where I can share my template as it might be usefull for others and/or the community.

Expected outcome:

Foreman and Proxy versions:
Foreman 3.0.1
Katello 4.2.1

Foreman and Proxy plugin versions:

Distribution and version:

Other relevant data:

In the error it says bridge_dhcp6 but in this code I don’t see it. Does it perhaps happen elsewhere? Perhaps you intended bridge_dhcp6 = ... instead of bridge_dhcp = ...?

It would be awesome if you could share the entire template, ideally as a pull request upstream so all users can benefit from it.

1 Like

@ekohl ,

OMG, I over looked this one, thanks for pointing this out to me.
Using the correct variable-name makes a difefrence.

Before sharing/uploading the template I’m going to try making the code shorter by using a snippet in order to use it for repeating code as function, and add also the code for ipv6.

Another question:
I was looking for a way to check whether there is a simple way to find out if interfaces of a certain type (bonds, bridges or vlans) are defined.

When I try to use for example:

<%- if !@host.bond_interfaces.nil? -%>
or
<%- if !@host.bond_interfaces.blank? -%>

It returns true, even when there are no interfaces in it when using it in a loop <%- @host.bond_interfaces.each do | bond | -%>.

I guess this is because @host.bond_interfaces contains “#Nic::Base::ActiveRecord_AssociationRelation:0x000055c377edb8a0

So I need a method to check if it contains identifiers in order to perform the code in the loop.

For now I’ve done it with a workaround, but the code would be better If it could be checked on defined identifiers in it.

I’ll keep you informed when I’m ready to pull the template(s).

I suspect you can use if @host.bond_interfaces.any?

@ekohl ,

if @host.bond_interfaces.any? does not work as well, so I leave it with the workaround I have used.

Repeating code is now part of a snipped which also includes the necessary code for ipv6.

According to Bug #30748: Foreman doesn't support Netplan on Ubuntu - Foreman there is already a change, more specific Revision 177adee7 - Fixes #30748 - On Ubuntu 18.04+ use /etc/netplan - Foreman.

This ticket has the state closed, however, I’m afraid that it does not take bond options, and perhaps other things, into account.

Should I create a new ticket in which I upstream my snippet-templates?

Yes, that’s the correct step. Once an issue is shipped in a release, we don’t modify it anymore and create a new issue.

You can link the issues as a Related issue. That feels very appropriate here and it’d be good to use here.

@ekohl ,
OK, will do the nesessary actions tomorrow.

2 Likes

For how to install ubuntu 20.04.3 live-server with cloud-init and the necessary templates/partition table see: