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

29 views
Skip to first unread message

Alan Harkleroad

unread,
Jul 19, 2016, 11:57:44 AM7/19/16
to Ansible Project
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.

---
- hosts: some-server-name
  become: true
  become_method: sudo
  tasks:
 
  - name: Create backup directory on remote server/servers
    file: path=/var/certs/certbkup
          state=present
          owner=root
          group=some-group
          mode=744

  - name: list directory specific contents
    shell: ls *.crt *.cer *.jks *.p12 /var/certs
    register: cert_results

  - name: copy list results to new folder
    command: cp {{item}} /var/certs/certbkup
    with_items: cert_results.stdout_lines

rup

unread,
Jul 19, 2016, 2:26:08 PM7/19/16
to Ansible Project
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

Kai Stian Olstad

unread,
Jul 19, 2016, 2:40:04 PM7/19/16
to ansible...@googlegroups.com
You have several option:

- name: list directory specific contents
shell: ls *.crt *.cer *.jks *.p12
args:
chdir: /var/certs
register: cert_results

- name: copy list results to new folder
command: cp {{item}} /var/certs/certbkup
args:
chdir: /var/certs
with_items: cert_results.stdout_lines

or just do in in one go

- name: backup files
shell: cp *.crt *.cer *.jks *.p12 /var/certs/certbkup
args:
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
synchronize:
src=/var/certs/
dest=/var/certs/certbkup/
recursive=no

--
Kai Stian Olstad

Alan Harkleroad

unread,
Jul 19, 2016, 3:28:43 PM7/19/16
to Ansible Project
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.
Reply all
Reply to author
Forward
0 new messages