Skip to content

Instantly share code, notes, and snippets.

@joshuaconner
Last active August 29, 2015 14:00
Show Gist options
  • Save joshuaconner/11104630 to your computer and use it in GitHub Desktop.
Save joshuaconner/11104630 to your computer and use it in GitHub Desktop.
docker_image hack
- name: Ensure an image has been built
hosts: main
vars:
image: joshuaconner/someimage
tag: sometag
tasks:
- name: Check if image has already been built using some fancy grep
shell: if [ -z "$(docker images | grep '{{ image }}[[:blank:]]*{{ tag }}')" ]; then echo image not built; else echo image built; fi
register: cmd_docker_images_grepped
changed_when: cmd_docker_images_grepped.stdout != 'image built'
- name: Ensure Docker image has been built
command: docker pull {{ image }}:{{ tag }}
when: cmd_docker_images_grepped.changed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment