0

ansible version 1.9.1

cat files.yml

tasks:
  - name: stat files
    stat: path=~/{{ item }}
    register: {{ item }}.stat
    with_items:
      - foo.zip
      - bar.zip

  - name: copy files
    copy: src=~/{{ item }} dest=/tmp/{{ item }}
    register: {{ item }}.result
    when: {{ item }}.stat.stat.exists == False
    with_items:
      - foo.zip
      - bar.zip

- name: unzip files
  shell: cd /tmp/ && unzip -o {{ item }}
  when: {{ item }}.result|changed == True
  with_items:
    - foo.zip
    - bar.zip

ERROR: Syntax Error while loading YAML script

If so, how?

1 Answer 1

1

The preferred way would be to use synchronize module. From ansible documentation ( http://docs.ansible.com/ansible/synchronize_module.html#synopsis )

This is a wrapper around rsync. Of course you could just use the command action to call rsync yourself, but you also have to add a fair number of boilerplate options and host facts. You still may need to call rsync directly via command or shell depending on your use case. The synchronize action is meant to do common things with rsync easily. It does not provide access to the full power of rsync, but does make most invocations easier to follow.

Here is an example:

- name: Sync files
  synchronize: src=some/relative/path dest=/some/absolute/path
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.