# In ansible how do cp -rp

**URL:** <https://forum.ansible.com/t/in-ansible-how-do-cp-rp/29939>\
**Category:** Ansible Project\
**Created:** [March 21, 2019, 5:00pm UTC](https://forum.ansible.com/t/in-ansible-how-do-cp-rp/29939 "2019-03-21T17:00:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryad9200000](https://avatars.discourse-cdn.com/v4/letter/r/f04885/32.png) [@ryad9200000](https://forum.ansible.com/u/ryad9200000)\
**Post date:** [March 21, 2019, 5:00pm UTC](https://forum.ansible.com/t/in-ansible-how-do-cp-rp/29939/1 "2019-03-21T17:00:28Z")

</div>

Hi all,

I want do this command line in ansible :

**cp -rp /home/user/file1 /home/user/directory2/file2**

I have find this module copy :

```auto
- name: example copying file with owner and permissions
  copy:
    src: /srv/myfiles/foo.conf
    dest: /etc/foo.conf
    owner: foo
    group: foo
    mode: 0644

```

```auto
this task works But this task not sauvegarde all caracteristic of file1 ( **date create** , etc ...) as linux command **"cp -rp /**** home/user/file1 /home/user/directory2/file2"**

```

```auto
Someone have an idea please ? 

```

```auto
Thanks community ansible !! ;)

```

```auto
Regards,

```

---

<div class="post-metadata">

**Author:** ![erichymowitz](https://avatars.discourse-cdn.com/v4/letter/e/9d8465/32.png) [@erichymowitz](https://forum.ansible.com/u/erichymowitz)\
**Post date:** [March 21, 2019, 5:37pm UTC](https://forum.ansible.com/t/in-ansible-how-do-cp-rp/29939/2 "2019-03-21T17:37:45Z")

</div>

Ansible has a “shell” and a “command” module, both of which allow you to pass arbitrary Unix commands to the remote host.

Also, the -r flag has no use on a single file.

–EbH

---

<div class="post-metadata">

**Author:** ![ryad9200000](https://avatars.discourse-cdn.com/v4/letter/r/f04885/32.png) [@ryad9200000](https://forum.ansible.com/u/ryad9200000)\
**Post date:** [March 22, 2019, 8:25am UTC](https://forum.ansible.com/t/in-ansible-how-do-cp-rp/29939/3 "2019-03-22T08:25:08Z")

</div>

Hi Eric,

Yes but the subject is -p since I’m mainly interested in keeping all the characteristics of the file …  
In addition, I know that there is shell and command in ansible but I want a “syntax” ansible. The objective with ansible it is to use its modules (example: service, get\_url, etc …) otherwise one does that shell and command and the problem and to regulate, that will return to make a script bash: /

Regards,

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [March 22, 2019, 8:55am UTC](https://forum.ansible.com/t/in-ansible-how-do-cp-rp/29939/4 "2019-03-22T08:55:04Z")

</div>

If your goal is to have two equal directories, then the synchronize  
module would make sense.

---

<div class="post-metadata">

**Author:** ![ryad9200000](https://avatars.discourse-cdn.com/v4/letter/r/f04885/32.png) [@ryad9200000](https://forum.ansible.com/u/ryad9200000)\
**Post date:** [March 22, 2019, 9:31am UTC](https://forum.ansible.com/t/in-ansible-how-do-cp-rp/29939/5 "2019-03-22T09:31:09Z")

</div>

Hi,

Ok thanks,

i will try synchronize module in ansible.

Thank you,

Regards,
