Netplan customization


Maybe someone knows the easiest way to customize network settings via maas after deployment? I need to remove information about pxe network. And make other simple changes in the netplan config file. I thought about curtin preseeds and late comands. But I don’t know how to use variables in preseeds. And I can’t made stateful preseed without variables because IP adresses will be different in each node.

Variables in preseeds look like this: {{new_ip_address}}. So you can, for example, make some python code in preseed where you assign ip to variable and then make configuration with that variable.
Below is example of what we using to get puppet fact “puppet_team” variable via python post request:

import operator
import re
import os
import requests
import subprocess

node_hostname = node.fqdn
node_distribution = node.get_distro_series()

puppet_team = “”
ipmi_ip_address = str(node.bmc.extract_ip_address(node.power_type, node.power_parameters)).strip()

team_request_data = {“event” : “created”, “model” : “team”, “data” : {“ipmi_ip” : ipmi_ip_address} }
team_req =“http://%s:8084” % node.boot_cluster_ip, json=team_request_data)
puppet_team = team_req.json().get(‘team’)


01_add_team_fact: [“curtin”, “in-target”, “–”, “sh”, “-c”, “echo team={{puppet_team}} >/opt/puppetlabs/facter/facts.d/team.txt”]
02_run_puppet: [“curtin”, “in-target”, “–”, “sh”, “-c”, “/opt/puppetlabs/bin/puppet agent -t --server server_name || true”]


One of the things you can do with MAAS is add a cloud-init file on top, which would allow you to do various customisations.

For example, in my simple environment I pass on this cloud-init file to my maas. You will see that I customise my netplan on top of MAAS provides, but you could potentially do more than that.

You can use this or another cloud-init file using the following method using the MAAS CLI. You can also add the cloud-init to the maas node at deployment in thr UI on newer version of MAAS, if that is the route you would like to take.

maas ${maas_profile} machine deploy ${system_id} user_data="$(base64 user-data.yaml)"

The command above assumes that you have the maas_profile and system_id already.

I didn’t know that I could use even python code. Also information about node.power_type, node.power_type and so on is new for me. Thank you very much.

Thank you for this solution. But as for me it is not very convenient to add additional cloud-init script every time during deployment. I want wrote one script add it once and forget about it)

@kiruka4, if you’d like, you can add a feature request (choose the category “Feature…” when posting) with some more details about what you’d like to see. no promises, but it will help your needs get into our system.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.