Restoring an ansible backup file

I’m trying to copy a file out with backup option which works fine. I’m pretty sure I am overlooking over something simple here. Any help is appreciated.

`

I'm trying to copy a file out with backup option which works fine. I'm
pretty sure I am overlooking over something simple here. Any help is
appreciated.

For starter you shouldn't use the developer list for user questions
https://docs.ansible.com/ansible/2.6/community/communication.html#mailing-list-information

---
- hosts: all
  become: true
  vars:
    push: false
    fallback: false
    jksfile: ''
  tasks:
   - name: "copy jks"
     copy:
       src: "/etc/ansible/mydir/install/repo/{{ jksfile }}"
       dest: "/mydir/opt/repo/{{ jksfile }}"
       owner: me
       group: me
       backup: yes
     when: push == "true"

If you check the return values for the copy module you'll see it return backup_file
https://docs.ansible.com/ansible/2.6/modules/copy_module.html#return-values

So add «register: result» then you'll have the filename in {{ result.backup_file }}, this might be easier.

   - name: "get backup file"
     find:
       paths: /mydir/opt/repo
       patterns: "*{{ ansible_date_time.date }}*"
     register: myfile

   - name: "restore file"
     copy:
       src: "{{myfile.files|map(attribute='path')|list}}"
       dest: "/mydir/opt/repo/{{ jksfile }}"
       owner: me
       group: me
       remote_src: yes
     when: fallback == "true"

src doesn't take a list so you need to choose one of the element in the list, to take the first you need
  src: "{{(myfile.files|map(attribute='path')|list)[0]}}"

But remember, you might have multiple backups on the same day and find will return them all so you never now which one is in the first element.