# Trying to copy a directories contents but not the other directories with in. Any help is appreciated

**URL:** <https://forum.ansible.com/t/trying-to-copy-a-directories-contents-but-not-the-other-directories-with-in-any-help-is-appreciated/22048>\
**Category:** Ansible Project\
**Created:** [July 19, 2016, 3:57pm UTC](https://forum.ansible.com/t/trying-to-copy-a-directories-contents-but-not-the-other-directories-with-in-any-help-is-appreciated/22048 "2016-07-19T15:57:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alan\_Harkleroad1](https://avatars.discourse-cdn.com/v4/letter/a/d6d6ee/32.png) [@Alan\_Harkleroad1](https://forum.ansible.com/u/Alan_Harkleroad1)\
**Post date:** [July 19, 2016, 3:57pm UTC](https://forum.ansible.com/t/trying-to-copy-a-directories-contents-but-not-the-other-directories-with-in-any-help-is-appreciated/22048/1 "2016-07-19T15:57:44Z")

</div>

I am currently trying to copy a directories contents to a new directory so we can do our SHA-384 and TLS upgrades to the system. When I have to copy the variable list results to the new folder is where I am confusing my self as to how that should look

My playbook likes like this.

---

<div class="post-metadata">

**Author:** ![rup](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@rup](https://forum.ansible.com/u/rup)\
**Post date:** [July 19, 2016, 6:26pm UTC](https://forum.ansible.com/t/trying-to-copy-a-directories-contents-but-not-the-other-directories-with-in-any-help-is-appreciated/22048/2 "2016-07-19T18:26:08Z")

</div>

Perhaps you can try something a bit simpler? Note, not tested…

- name: Copy cert files to backup  
shell: cp /var/certs/certbkup{\*.crt \*.cer \*.jks \*.p12} /var/certs/certbkup/

Kim

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 19, 2016, 6:39pm UTC](https://forum.ansible.com/t/trying-to-copy-a-directories-contents-but-not-the-other-directories-with-in-any-help-is-appreciated/22048/3 "2016-07-19T18:39:32Z")

</div>

You have several option:

- name: list directory specific contents  
&nbsp;&nbsp;&nbsp;shell: ls \*.crt \*.cer \*.jks \*.p12  
&nbsp;&nbsp;&nbsp;args:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chdir: /var/certs  
&nbsp;&nbsp;&nbsp;register: cert\_results

- name: copy list results to new folder  
&nbsp;&nbsp;&nbsp;command: cp {{item}} /var/certs/certbkup  
&nbsp;&nbsp;&nbsp;args:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chdir: /var/certs  
&nbsp;&nbsp;&nbsp;with\_items: cert\_results.stdout\_lines

or just do in in one go

- name: backup files  
&nbsp;&nbsp;&nbsp;shell: cp \*.crt \*.cer \*.jks \*.p12 /var/certs/certbkup  
&nbsp;&nbsp;&nbsp;args:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chdir: /var/certs

If you are copy all the files under /var/certs but not the directories I also think this would work (not tested).

- name: backup files  
&nbsp;&nbsp;&nbsp;synchronize:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src=/var/certs/  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest=/var/certs/certbkup/  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;recursive=no

---

<div class="post-metadata">

**Author:** ![Alan\_Harkleroad1](https://avatars.discourse-cdn.com/v4/letter/a/d6d6ee/32.png) [@Alan\_Harkleroad1](https://forum.ansible.com/u/Alan_Harkleroad1)\
**Post date:** [July 19, 2016, 7:28pm UTC](https://forum.ansible.com/t/trying-to-copy-a-directories-contents-but-not-the-other-directories-with-in-any-help-is-appreciated/22048/4 "2016-07-19T19:28:42Z")

</div>

Thank you for the responses. I will give all of them a test against my test baseline to see what happens. Appreciate the feedback. Still learning this and am enjoying tackling each new challenge on how to do a particular task and then refine the process.
