Autoinstall-generator - tool to help with creation of autoinstall files based on preseed

Greetings all!

We’ve done some work lately to make it a bit easier to transition from Debian Installer to Subiquity. Those of you using preseed files may be interested in the new tool autoinstall-generator, available now as a Snap.

This work is being released with basic functionality in place - we know more things can be done here, and wanted to release and collect feedback.

In particular, it is understood that the preseed format supports things such as partitioning and network handling in more complicated ways than autoinstall-generator supports today.

Usage:

usage: autoinstall-generator.py [-h] [-c] [-d] [-V] infile [outfile]

positional arguments:
  infile         Debian install preseed file, or a dash to read stdin
  outfile        Subiquity autoinstall yaml

optional arguments:
  -h, --help     show this help message and exit
  -c, --cloud    output in cloud-config format
  -d, --debug    include commented out debug output explaining the conversions
                 performed
  -V, --version  show version and exit

Examples:

autoinstall-generator my-preseed.txt my-autoinstall.yaml

This basic usage will convert the preseed file to the autoinstall format.

autoinstall-generator my-preseed.txt my-cloud-config.yaml --cloud

This usage will convert the preseed file to the cloud-config format with the autoinstall data contained within the autoinstall section. Depending on how the data will be loaded to the installer, it may be needed in autoinstall or in cloud-config formats.

autoinstall-generator my-preseed.txt my-autoinstall.yaml --debug

This usage adds debug information to the end of the yaml in the form of comments.

The debug output looks like this:

#   4:   Directive: d-i debian-installer/locale string en_US
#        Mapped to: locale: en_US

This represents a single-line directive that was recognized and mapped to an Autoinstall equivalent. The ‘4’ indicates that the directive was found on line 4 of the input.

#   7: Unsupported: d-i debian-installer/language string en

Other directives are known to be unsupported, and are marked as such.

#  52:   Directive: d-i netcfg/get_ipaddress string 192.168.1.42
#  53:         And: d-i netcfg/get_netmask string 255.255.255.0
#        Mapped to: network:
#                     ethernets:
#                       any:
#                         addresses:
#                         - 192.168.1.42/24
#                         match:
#                           name: en*
#                     version: 2

Some directives get combined into a single section, such as the two netcfg items above.

# 436:   Directive: pkg-a pkg-a/my-q boolean false                                                                                   
# 437:         And: pkg-b pkg-a/my-other-q boolean true                                                                              
#        Mapped to: debconf-selections: |                                                                                            
#                     pkg-a pkg-a/my-q boolean false                                                                                 
#                     pkg-b pkg-a/my-other-q boolean true                                                                            

It will also pass along directives believed to be out of scope for the installer to the debconf-selections section. Note that the above are just fake examples and not real debconf selections.

An introduction to the autoinstall format can be found at https://ubuntu.com/server/docs/install/autoinstall. See also the quickstart guide and the Autoinstall file format reference.

I look at this as a work in progress so please share your thoughts.

Github: https://github.com/canonical/autoinstall-generator

Bugs & Feature requests: feel free to discuss below, or report on launchpad.

4 Likes

Can you input a kickstart config and convert it as well?

No kickstart support at this point - it’s something we’ve considered though.

1 Like

Does this tool also create the autoinstall files without the need for a already created preseed file?

No, autoinstall-generator assumes you’re bringing in preseed files and converts them, it won’t create autoinstalls from scratch. What you’re talking is something we have a design for but haven’t scheduled yet called autoinstall-editor.

I appreciate the feedback @andrewm659.

2 Likes

I am trying to follow your documentation without success.
/snap/bin/autoinstall-generator uefi.seed eufi.yaml
usage: autoinstall-generator [-h] [-c] [-d] [-V] infile [outfile]
autoinstall-generator: error: argument outfile: can’t open ‘eufi.yaml’: [Errno 13] Permission denied: ‘eufi.yaml’
me@USFRYLNCN16MMKF:/media/me/disk2/local_repo/cubic$ /snap/bin/autoinstall-generator uefi.seed eufi.yaml --debug
usage: autoinstall-generator [-h] [-c] [-d] [-V] infile [outfile]
autoinstall-generator: error: argument outfile: can’t open ‘eufi.yaml’: [Errno 13] Permission denied: ‘eufi.yaml’
mer@USFRYLNCN16MMKF:/media/me/disk2/local_repo/cubic$ /snap/bin/autoinstall-generator uefi.seed eufi.yaml --cloud
usage: autoinstall-generator [-h] [-c] [-d] [-V] infile [outfile]
autoinstall-generator: error: argument outfile: can’t open ‘eufi.yaml’: [Errno 13] Permission denied: ‘eufi.yaml’

Any idea what is wrong?

Sounds like we need to tweak some permissions on the snap.
@mikefrygm - If you write your outfile to a different directory, does that work better?

I have tried two different directories and also with sudo. Same error.

yeah, for /media you want to add the removable-media plug (note though that this is not auto-connected and usually also not granted easily for auto-connecting by the snap reviewers so users would still have to run snap connect autoinstall-generator:removable-media to make use of it)

looking at the snap it has the home plug auto-connected … so all of the excuting users home dir as well as ~/snap/autoinstall-generator/current and~/snap/autoinstall-generator/common should be accessible by the tool (note that sudo will mess this setup up and you would need to point to /root)

2 Likes

@ogra - thanks for the tips on plugs, I need to look into that more. Though it sounds like removable-media is a more esoteric plug and I might not want to if the user still has to take manual steps.

@mikefrygm - would you try writing our output file to $HOME?

1 Like

I have moved my uefi.seed to $HOMEDIR. My command is /snap/bin/autoinstall-generator uefi.seed uefi.yaml

Output:
> Traceback (most recent call last):
> File “/snap/autoinstall-generator/64/usr/bin/autoinstall-generator”, line 56, in
> sys.exit(main())
> File “/snap/autoinstall-generator/64/usr/bin/autoinstall-generator”, line 47, in main
> out = convert_file(infile, args)
> File “/snap/autoinstall-generator/64/lib/python3.6/site-packages/autoinstall_generator/merging.py”, line 212, in convert_file
> validate_yaml(result_dict)
> File “/snap/autoinstall-generator/64/lib/python3.6/site-packages/autoinstall_generator/merging.py”, line 167, in validate_yaml
> jsonschema.validate(tree, schema)
> File “/snap/autoinstall-generator/64/usr/lib/python3/dist-packages/jsonschema/validators.py”, line 541, in validate
> cls(schema, *args, **kwargs).validate(instance)
> File “/snap/autoinstall-generator/64/usr/lib/python3/dist-packages/jsonschema/validators.py”, line 130, in validate
> raise error
> jsonschema.exceptions.ValidationError: ‘hostname’ is a required property
>
> Failed validating ‘required’ in schema[‘properties’][‘identity’]:
> {‘additionalProperties’: False,
> ‘properties’: {‘hostname’: {‘type’: ‘string’},
> ‘password’: {‘type’: ‘string’},
> ‘realname’: {‘type’: ‘string’},
> ‘username’: {‘type’: ‘string’}},
> ‘required’: [‘username’, ‘hostname’, ‘password’],
> ‘type’: ‘object’}
>
> On instance[‘identity’]:
> {‘password’: ‘$6$jm5wpqj7$47TOjpgCmeYWMHZmpI2esB7PxHCPYu.UD05lNW9N1s7SZD4WcM6EO0ybE0isYa11rbpS7B7OUlXUFAd5GaiwC/’,
> ‘realname’: ‘General Motors’,
> ‘username’: ‘gmuser’}

Well that error is not terribly helpful!

Your example is complaining that the ‘identity’ field is missing a value for ‘hostname’ in the resulting autoinstall data. But it doesn’t show the autoinstall data to really know this.

I’ve pushed a fix to the beta channel. You can pick that up with the command

snap refresh --beta autoinstall-generator

With this fixed version it should give you some better data. And the above crash is now softened to a warning that should look like:

# Warning: resulting autoinstall is missing required data
# 'hostname' is a required property
1 Like

Using beta:
I get:
autoinstall-generator preseed-dhcp.cfg preseed-dhcp.yaml --debug

Warning: resulting autoinstall is missing required data

‘password’ is a required property

but my preseed contains:
d-i passwd/root-login boolean true
d-i passwd/root-password password xxxxxxx
d-i passwd/root-password-again password xxxxxxxx
d-i passwd/user-fullname string MyUser
d-i passwd/username string myuser
d-i passwd/user-password password xxxxxxxxx
d-i passwd/user-password-again password xxxxxxxxxx
d-i user-setup/allow-password-weak boolean true

what password is being looked for ?

autoinstall-generator preseed.txt auto_install.yaml
Traceback (most recent call last):
File “/snap/autoinstall-generator/104/usr/bin/autoinstall-generator”, line 56, in
sys.exit(main())
File “/snap/autoinstall-generator/104/usr/bin/autoinstall-generator”, line 47, in main
out = convert_file(infile, args)
File “/snap/autoinstall-generator/104/lib/python3.6/site-packages/autoinstall_generator/merging.py”, line 217, in convert_file
directives.append(convert(fullDirective, startIdx + 1))
File “/snap/autoinstall-generator/104/lib/python3.6/site-packages/autoinstall_generator/convert.py”, line 280, in convert
return dispatch(line, pkg, key, value, linenumber)
File “/snap/autoinstall-generator/104/lib/python3.6/site-packages/autoinstall_generator/convert.py”, line 251, in dispatch
return debconf_fragment(value, line, linenumber)
File “/snap/autoinstall-generator/104/lib/python3.6/site-packages/autoinstall_generator/convert.py”, line 163, in debconf_fragment
key = f’{chunks[0]} {chunks[1]}’
IndexError: list index out of range

I’m going to comment/reply on this one to contribute!
The required password is looking for is this:

d-i passwd/user-password-crypted password [crypt(3) hash]

I haven’t tried it but you can probably get a hash for your password here (others can correct me if I’m wrong):
https://www.onlinewebtoolkit.com/crypt-hash-generator

use that password instead of your plaintext password, ensure that d-i line is added to your seed file and run the converter again.

Unfortunately this tool doesn’t seem to understand most of my preseed file. There are 103 lines showing as “Unsupported”. Is there a place to file a bug report for this application? Can I submit a sample preseed file for debugging?

Based on the lack of response I would recommend avoiding this tool.