user5149108
user5149108

Reputation:

Ansible copy module with items

I Just setup and ansible testing server and trying copy module to copy files over multiple hosts following a ssh service to be started. But its throwing error. please advise what wrong i am doing here..

---
- hosts: Dummy_host
  remote_user: root
  tasks:
      - name: Copying Files to Group of Hosts
        copy: src=/tmp/{{ item.sname }} dest=/tmp/WWW/{{ item.dname }}
        notify:
           - restart sshd
        with_items:
           - { sname: file1.txt, dname: nm1.txt }
           - { sname: file2.txt, dname: nm2.txt }
  handlers:
       - name: restart sshd
         service: name=sshd state=restarted

Below is the Error

root@test1# ansible-playbook  cp4.yml
ERROR! Syntax Error while loading YAML.


The error appears to have been in '/etc/ansible/Playbooks/cp4.yml': line 9, column 1, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

           - restart sshd
        with_items:
^ here

Upvotes: 6

Views: 27257

Answers (1)

hellodk
hellodk

Reputation: 426

Use the below format to do this correctly:

- name: Copy the binary files into /etc/init.d
  copy:
    src: "{{ item }}"
    dest: /etc/init.d
    owner: root
    group: root
    mode: 0755
  with_items:
    - consul
    - keymanager
    - vault
    - tarball.tar.gz

Upvotes: 17

Related Questions