how could I install a snap package via Ansible on an air-gapped system

Viewed 422

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

3 Answers

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

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.

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.

Related