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

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.

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

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

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.