syncronize module: ignoreif local source does not exist

20 views
Skip to first unread message

Robert Arnonym

unread,
Aug 15, 2015, 3:28:24 PM8/15/15
to Ansible Project
Hello

i have the following task:

- name: Copying webcontent
  synchronize: src=some/relative/path/{{ item }} dest=/some/absolute/path/{{ item }}
  with_items:
    - some
    - other

what i need:
"other" does not exist locally and thats ok. How can i check, if the items exist locally and skip the cycle if not?

Thx

Diep Pham

unread,
Aug 16, 2015, 3:00:25 AM8/16/15
to Ansible Project
Following codes should work.

---
- name: check file exists
  stat
:
    path
: some/relative/path/{{ item }}
  with_items
:
   
- some
   
- other
 
register: checks
- name: Copying webcontent
  synchronize
:

    src
: some/relative/path/{{ item }}
    dest
: /some/absolute/path/{{ item }}
 
when: item.stat.exists
  with_items
: "{{ checks.results }}"

Reply all
Reply to author
Forward
0 new messages