Snap (Ubuntu package management)

Snap package search
https://snapcraft.io/store

Install

sudo apt install -y snapd

CLI

snap find
snap install
snap info <snap name>
 
# Update packages
snap refresh --list

Configure proxy

sudo mkdir -p /etc/systemd/system/snapd.service.d/
echo -e '[Service]\nEnvironment="http_proxy=http://proxy.example.com:3128/"' | sudo tee /etc/systemd/system/snapd.service.d/http-proxy.conf
echo -e '[Service]\nEnvironment="https_proxy=http://proxy.example.com:3128/"' | sudo tee /etc/systemd/system/snapd.service.d/https-proxy.conf
sudo systemctl daemon-reload
sudo systemctl restart snapd
 
# debug proxy
systemctl show snapd | grep proxy
 
###############################3
# proxy test (broken?)
# cat /etc/environment
http_proxy="http://BENUTZER:PASSWORD@proxy.hostname.de:8080/"
https_proxy="http://BENUTZER:PASSWORD@proxy.hostname.de:8080/"
 
sudo systemctl edit snapd.service
[Service]
EnvironmentFile=/etc/environment
 
sudo systemctl daemon-reload
sudo systemctl restart snapd.service

Configure proxy (Ansible)

---
- hosts: localhost
  tasks:
    - name: Configure snap proxy
      become: yes
      ini_file:
        path: /etc/systemd/system/snapd.service.d/http-proxy.conf
        section: Service
        option: Environment
        value: '"http_proxy=http://proxy.example.com:8080"'
        mode: 0644
        create: yes
      notify: restart snapd
 
  handlers:
    - name: restart snapd
      systemd:
        name: snapd
        state: restarted
        daemon_reload: yes

Cleanup old versions

sudo snap set system refresh.retain=2
 
LANG=C snap list --all | awk '/disabled/{print $1, $3}'
snap remove code --revision=34

Install applications

# Visual Studio Code
sudo snap install code --classic
 
# Spotify
sudo snap install spotify
 
# (Micro)Kubernetes
snap install microk8s --classic

Uninstall

systemctl disable snapd.service
umount  /snap
apt purge -y snapd

Ansible module
https://docs.ansible.com/ansible/latest/modules/snap_module.html

Links
https://snapcraft.io/
https://wiki.ubuntuusers.de/snap/