Skip to content

Instantly share code, notes, and snippets.

@dcode
Created May 22, 2020 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dcode/9208a68e7478f218c182af0062172a11 to your computer and use it in GitHub Desktop.
Save dcode/9208a68e7478f218c182af0062172a11 to your computer and use it in GitHub Desktop.
Ansible playbook to pull docker images, write them to disk as tarballs, then optionally restore them to local container storage
---
- hosts: localhost
become: True
vars:
archive_path: /home/vagrant/containers
containers:
- name: quay.io/dcode/strelka_manager
tag: latest
id: 8b8321cf9c81
- name: quay.io/dcode/strelka_frontend
tag: latest
id: fadbf562a40c
- name: quay.io/dcode/strelka_backend
tag: latest
id: e0b21542811a
- name: quay.io/dcode/strelka_mmrpc
tag: latest
id: b349c7f21d96
tasks:
- name: Mirror from online
podman_image:
name: "{{ item.name }}"
tag: "{{ item.tag }}"
pull: True
tags:
- online
- mirror
loop: "{{ containers }}"
- name: Write to disk
command: >
skopeo copy
containers-storage:{{ item.name }}:{{ item.tag }}
docker-archive:{{ archive_path }}/{{ item.name | regex_replace('/', '+') }}__{{ item.tag }}__{{ item.id }}.tar
args:
creates: "{{ archive_path }}/{{ item.name | regex_replace('/', '+') }}__{{ item.tag }}__{{ item.id }}.tar"
tags:
- online
- mirror
loop: "{{ containers }}"
- name: Gather info for all images
podman_image_info:
name: "{{ item.id }}"
register: images
tags:
- offline
loop: "{{ containers }}"
- name: Populate from disk
command: >
skopeo copy
docker-archive:{{ archive_path }}/{{ item.item.name | regex_replace('/', '+') }}__{{ item.item.tag }}__{{ item.id }}.tar
containers-storage:{{ item.item.name }}:{{ item.item.tag }}
when: item.images | length == 0
tags:
- offline
- never
loop: "{{ images.results }}"
loop_control:
label: "{{ item.item.name }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment