How to sync two directories on same host using Ansible? I am using the below playbook for mounting partitions on another EBS volumes while provisioning instance on AWS 

    ---
    - name: Mounting necessary partitions
      hosts: localhost
      become: yes
      become_user: root

      tasks:

        - name: Ansible formating partitions.
          command: "{{ item }}"
          loop:
            - mkswap -f {{ ebs_swap }}
            - mkfs.xfs -f {{ ebs_home }}
            - mkfs.xfs -f {{ ebs_var }}
            - mkfs.xfs -f {{ ebs_tmp }}
            - mkfs.xfs -f {{ ebs_app }}   
            - mv -f /home /home_old
            - mv -f /var /var_old    

        - name: Dispaly uuid &amp; store in variable
          command: blkid -s UUID -o value {{ ebs_swap }}
          register: uuid_swap

        - name: Dispaly uuid &amp; store in variable
          command: blkid -s UUID -o value {{ ebs_home }}
          register: uuid_home

        - name: Dispaly uuid &amp; store in variable
          command: blkid -s UUID -o value {{ ebs_var}}
          register: uuid_var

        - name: Dispaly uuid &amp; store in variable
          command: blkid -s UUID -o value {{ ebs_tmp }}
          register: uuid_tmp

        - name: Dispaly uuid &amp; store in variable
          command: blkid -s UUID -o value {{ ebs_app }}
          register: uuid_app

        - name: Creates directory
          file:
            path: "{{ item }}"
            state: directory
          with_items:
            - /home
            - /var
            - /tmp
            - /app

        - name: Add the below lines
          blockinfile:
            path: /etc/fstab
            state: present
            block: |
              UUID={{ uuid_swap.stdout }}   swap      swap defaults                         0   0
              UUID={{ uuid_home.stdout }}   /home     xfs  defaults,nodev                   0   0
              UUID={{ uuid_var.stdout }}    /var      xfs  defaults,noexec,nosuid,nodev     0   0
              UUID={{ uuid_tmp.stdout }}    /tmp      xfs  defaults,noexec,nosuid,nodev     0   0
              UUID={{ uuid_app.stdout }}    /app      xfs  defaults                         0   0

        - name: Mounting disks permanently
          command: "{{ item }}"
          loop:
            - swapon -a
            - mount -a

        - name: Copy multiple Directories
          copy:
            src: "{{ item.src }}"
            dest: "{{ item.dest }}"
            mode: "{{ item.mode }}"
          with_items:
             - { src: '/home_old/',dest: '/home/',mode: preserve}
             - { src: '/var_old/',dest: '/var/',mode: preserve}


I have tried multiple ways to copy the data back to newly mounted EBS volumes at task name
Copying /home data on new EBS.

I have tried using copy synchronization &amp; rsync modules. I know using cp is not recommended option but I can not see any other option related to syncing the data between to directories with preserving permissions.

But when I do it manually it works perfectly.

I am mounting these partitions on another EBS is just coz of CIS hardening steps includes it.

I have followed a couple of blogs already. such as 
1. one 2. two

Can anyone help in solving this? This is very urgent.


  ERROR: failed: [localhost] (item={u'dest': u'/var/', u'src': u'/var_old/'}) =&gt; {"ansible_loop_var": "item", "changed": false, "item": {"dest": "/var/", "src": "/var_old/"}, "msg": "could not find src=/run/acpid.socket, Could not find or access '/run/acpid.socket' on the Ansible Controller.\nIf you are using a module and expect the file to exist on the remote, see the remote_src option"}
The copy module copies a file from the local or remote machine to a location on the remote machine. 

In order to copy the file from the remote machine itself, set remote_src to yes.

- name: Copy multiple Directories
          copy:
            src: "{{ item.src }}"
            dest: "{{ item.dest }}"
            mode: "{{ item.mode }}"
            remote_src: yes
          with_items:
             - { src: '/home_old/',dest: '/home/',mode: preserve}
             - { src: '/var_old/',dest: '/var/',mode: preserve}