How to Install Spotify snap on RedHat-like systems with Ansible?

I’m going to show you a live Playbook with some simple Ansible code. I’m Luca Berton and welcome to today’s episode of Ansible Pilot.

Ansible installs Spotify snap on RedHat-like systems

  • community.general.snap
  • Manages snaps

Today we are going to talk about the Ansible module snap. The full name is community.general.snap, it’s part of community.general modules maintained by the Ansible Community. The purpose of the snap module is to Manage snaps in the target system.

Parameters

  • name string - snap name
  • state string - present/absent
  • channel string - “stable”
  • classic boolean - no/yes

Let me summarize the parameters of snap module. The only required is “name”, where you specify the snap name to install or remove. The parameter “state” specifies if you would like to perform the install action (“present” option) or the remove action (“absent” option). The parameter “channel” specifies which channel to use, default the “stable” channel. The parameter “classic” allows the confinement allows a snap to have the same level of access to the system as “classic” packages.

Join 50+ hours of courses in our exclusive community

Playbook

code

---
- name: snap module Playbook
  hosts: all
  become: true
  gather_facts: false
  tasks:
    - name: snapd present
      ansible.builtin.yum:
        name:
          - snapd
          - fuse
          - squashfs-tools
          - squashfuse
          - kernel-modules
        state: present
    - name: symlink /snap
      ansible.builtin.file:
        src: "/var/lib/snapd/snap"
        dest: "/snap"
        state: link
    - name: load squashfs module
      community.general.modprobe:
        name: "squashfs"
        state: present
    - name: install Spotify via snap
      community.general.snap:
        name: spotify
        state: present

execution

ansible-pilot $ ansible-playbook -i virtualmachines/fedora35/inventory container/snap_redhat.yml
PLAY [snap module Playbook] ***************************************************************************
TASK [snapd present] ******************************************************************************
changed: [fedora.example.com]
TASK [symlink /snap] ******************************************************************************
ok: [fedora.example.com]
TASK [load squashfs module] ***********************************************************************
changed: [fedora.example.com]
TASK [install Spotify via snap] *******************************************************************
changed: [fedora.example.com]
PLAY RECAP ****************************************************************************************
fedora.example.com         : ok=4    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
ansible-pilot $

idempotency

ansible-pilot $ ansible-playbook -i virtualmachines/fedora35/inventory container/snap_redhat.yml
PLAY [snap module Playbook] ***************************************************************************
TASK [snapd present] ******************************************************************************
ok: [fedora.example.com]
TASK [symlink /snap] ******************************************************************************
ok: [fedora.example.com]
TASK [load squashfs module] ***********************************************************************
ok: [fedora.example.com]
TASK [install Spotify via snap] *******************************************************************
ok: [fedora.example.com]
PLAY RECAP ****************************************************************************************
fedora.example.com         : ok=4    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
ansible-pilot $

before execution

ansible-pilot $ ssh [email protected]
[devops@fedora ~]$ cat /etc/os-release 
NAME="Fedora Linux"
VERSION="35 (Cloud Edition)"
ID=fedora
VERSION_ID=35
VERSION_CODENAME=""
PLATFORM_ID="platform:f35"
PRETTY_NAME="Fedora Linux 35 (Cloud Edition)"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora:35"
HOME_URL="https://fedoraproject.org/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f35/system-administrators-guide/"
SUPPORT_URL="https://ask.fedoraproject.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=35
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=35
PRIVACY_POLICY_URL="https://fedoraproject.org/wiki/Legal:PrivacyPolicy"
VARIANT="Cloud Edition"
VARIANT_ID=cloud
[devops@fedora ~]$ snap list
-bash: snap: command not found
[devops@fedora ~]$ dnf list snapd
Last metadata expiration check: 0:22:10 ago on Fri 04 Mar 2022 05:16:58 AM UTC.
Available Packages
snapd.x86_64                                 2.54.3-1.fc35                                  updates
[devops@fedora ~]$ exit
logout
Connection to fedora.example.com closed.
ansible-pilot $

after execution

ansible-pilot $ ssh [email protected]
[devops@fedora ~]$ dnf list snapd
Last metadata expiration check: 0:27:34 ago on Fri 04 Mar 2022 05:16:58 AM UTC.
Installed Packages
snapd.x86_64                                 2.54.3-1.fc35                                 @updates
[devops@fedora ~]$ lsmod | grep squashfs
squashfs               69632  6
[devops@fedora ~]$ ls -al /snap/
total 4
drwxr-xr-x. 1 root root 126 Mar  4 10:43 .
drwxr-xr-x. 1 root root 234 Mar  4 10:43 ..
drwxr-xr-x. 1 root root  16 Mar  4 10:41 bare
drwxr-xr-x. 1 root root  14 Mar  4 10:42 bin
drwxr-xr-x. 1 root root  22 Mar  4 10:41 core18
drwxr-xr-x. 1 root root  20 Mar  4 10:43 gnome-3-28-1804
drwxr-xr-x. 1 root root  22 Mar  4 10:42 gtk-common-themes
-r--r--r--. 1 root root 590 Mar  4 10:40 README
drwxr-xr-x. 1 root root  24 Mar  4 10:40 snapd
drwxr-xr-x. 1 root root  18 Mar  4 10:42 spotify
[devops@fedora ~]$ snap list
Name               Version                     Rev    Tracking       Publisher   Notes
bare               1.0                         5      latest/stable  canonical✓  base
core18             20211215                    2284   latest/stable  canonical✓  base
gnome-3-28-1804    3.28.0-19-g98f9e67.98f9e67  161    latest/stable  canonical✓  -
gtk-common-themes  0.1-59-g7bca6ae             1519   latest/stable  canonical✓  -
snapd              2.54.3                      14978  latest/stable  canonical✓  snapd
spotify            1.1.80.699.gc3dac750        58     latest/stable  spotify✓    -
[devops@fedora ~]$

code with ❤️ in GitHub

Conclusion

Now you know how to Install Spotify snap in RedHat-like systems with Ansible. Subscribe to the YouTube channel, Medium, and Website, X (formerly Twitter) to not miss the next episode of the Ansible Pilot.

Academy

Learn the Ansible automation technology with some real-life examples in my Udemy 300+ Lessons Video Course.

BUY the Complete Udemy 300+ Lessons Video Course

My book Ansible By Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps

BUY the Complete PDF BOOK to easily Copy and Paste the 250+ Ansible code

Want to keep this project going? Please donate

Patreon Buy me a Pizza