Snap installation of apps with curtin


#1

Hey guys!

I’m trying to install some applications with curtin via snap during installation phase. I get the follwing error:

error: cannot communicate with server: Post http://localhost/v2/snaps/lxd: dial unix /run/snapd.socket: connect: no such file or directory
curtin: Installation failed with exception: Unexpected error while running command.
Command: ['curtin', 'in-target', '--', 'snap', 'install', 'lxd', '--classic']
Exit code: 1
Reason: -
Stdout: error: cannot communicate with server: Post http://localhost/v2/snaps/lxd: dial unix /run/snapd.socket: connect: no such file or directory
        
Stderr: ''

Any idea what I am doing wrong? It seams that the snapd is not working. Starting it manually before the installation is getting ignored because of chroot.

late_commands:
[...]
  install_00: ["curtin", "in-target", "--", "snap", "install", "lxd", "--classic"]
  install_01: ["curtin", "in-target", "--", "snap", "install", "conjure-up", "--classic"]
  install_02: ["curtin", "in-target", "--", "snap", "install", "kubectl", "--classic"]

BR


#2

I would add a late_command before trying to install lxd that restarts snapd such as (you will need to convert to late_command):

$ systemctl restart snapd

I have had issues in the past with something similar and this seemed to fix the issue.


#3

Doesn’t work. If I put a systemctl restart snapd in front I’ll get the chroot error:

Running command ['unshare', '--fork', '--pid', '--', 'chroot', '/tmp/tmp8jcuz8xn/target', 'sh', '-c', 'systemctl restart snapd && snap install lxd --classic'] with allowed return codes [0] (capture=False) Running in chroot, ignoring request: restart error: cannot communicate with server: Post http://localhost/v2/snaps/lxd: dial unix /run/snapd.socket: connect: no such file or directory


#4

It won’t work because the target does not have snapd running. This is a bug report/feature request we have already made the curtin team to support…


#5

Hi,

Ryan from curtin team here. If you’d like to install a set of snaps in your target image, I suggest that you pass some cloud-config into the target.

https://cloudinit.readthedocs.io/en/latest/topics/modules.html#snap

On target first boot, cloud-init handles installing snaps after networking and snapd are up and running.


#6

Thank you andreserl and rasharper! Will have a look into it :slight_smile:


#7

Doesn’t work. Could someone tell me what I am doing wrong?
If I am getting this correct, I have to add a “snap” section inside the cloud-init file:

/etc/maas/preseeds/curtin_userdata_ubuntu_amd64_generic_bionic

It looks like the following:

#cloud-config
debconf_selections:
 maas: |
  {{for line in str(curtin_preseed).splitlines()}}
  {{line}}
  {{endfor}}

early_commands:
{{if third_party_drivers and driver}}
  [...]

late_commands:
  maas: [...]

snap:
  commands:
    00: snap install conjure-up
    
write_files:
  userconfig:
    [...]

But I don’t see anything inside the log file and conjure-up isn’t installed after deployment