2

Installing snap packages via Ansible on systems that are connected to internet is rather simple. EG:

  - name: Install microk8s
    become: yes
    snap:
      name: microk8s
      classic: yes
      channel: "{{ microk8s_version }}"

Now I would need to do the same on a set of nodes that are air-gapped (no direct connection to internet). I can do a 'snap download' for the required packages, and move them to the target machine(s). But then how to do this in Ansible? Is there any support for this? Or do I have to use the shell/command module ?

thx

Monger39
  • 109
  • 8

3 Answers3

1

I have not tested this, but this method works with other modules.

  - name: install microk8s, file on local disk
    become: yes
    snap:
      name: /path/to/file
Kevin C
  • 4,851
  • 8
  • 30
  • 64
  • Right, it is possible to [to install the .snap application in an offline computer](https://askubuntu.com/a/775622/774046). – U880D Jan 26 '21 at 07:38
  • thx @Kevin C. I managed to get it working. I will add the code in a separate answer – Monger39 Jan 26 '21 at 10:54
1

using the hint of @Kevin C I was able to solve the problem using the following playbook

  - name: copy microk8s snap to remote
    copy: 
      src: "{{ item }}"
      dest: "~/microk8s/"
      remote_src: no
    with_fileglob: 
      - "../files/microk8s/*"

  - name: snap ack the new package
    become: yes
    shell: |
       snap ack ~/microk8s/microk8s_1910.assert
       snap ack ~/microk8s/core_10583.assert

  - name: install microk8s, file on local disk
    become: yes
    snap:
      name: "~/microk8s/core_10583.snap"

  - name: install microk8s, file on local disk
    become: yes
    snap:
      name: "~/microk8s/microk8s_1910.snap"
      classic: yes

I hope this helps others also. Would be nice to see this documented.

Monger39
  • 109
  • 8
0

If you can get the packages onto the Ansible server, the following code will copy the file to the target(s). Something like the the following code should work.

  - name: copy files/local/microk8s.deb
    copy: 
      src: "files/local/microk8s.deb"
      dest: "~/microk8s.deb"
      remote_src: no

Where files/ is at the same level as the playbook.

P Burke
  • 1,630
  • 2
  • 17
  • 31
  • Thx. But that would still mean I need to do the 'install' through a 'shell: snap install microk8s.deb' and handle any issues around, right ? – Monger39 Jan 25 '21 at 15:18
  • Yes, you are correct. While there is an [Ansible snap module](https://docs.ansible.com/ansible/latest/collections/community/general/snap_module.html) it doesn't appear to have an option to install from a local file. So that would need to be a shell command. – P Burke Jan 25 '21 at 19:25