Skip to content

Instantly share code, notes, and snippets.

@mgagne
Last active October 1, 2015 23:01
Show Gist options
  • Save mgagne/4f0012b0804d8541e362 to your computer and use it in GitHub Desktop.
Save mgagne/4f0012b0804d8541e362 to your computer and use it in GitHub Desktop.
Optional synchronize
---
- name: "Deploy project"
hosts: all
gather_facts: false
vars:
artifacts:
- src: "./repository/"
dest: "/target/repository"
- src: "./manifests/"
dest: "/target/manifests"
- src: "./target/modules/"
dest: "/target/modules"
- src: "./hieradata/hieradata/"
dest: "/target/hieradata"
optional: True
tasks:
- name: Check artifacts existence
stat:
path: "{{ item.src }}"
with_items: artifacts
register: artifacts_stat
delegate_to: 127.0.0.1
- name: Synchronize artifacts
synchronize:
src: "{{ item.1.src }}"
dest: "{{ item.1.dest }}"
with_indexed_items: artifacts
when: >
not item.1.optional|default(False) or
artifacts_stat.results[item.0].stat.exists
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment