HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

using copy module with wildcards

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
withwildcardsmoduleusingcopy

Problem

I need to copy a database backup file from a primary server to a standby server. Since I can't use synchronize, I was following this method:

  • copy a file from primary to the local ansible server,



  • copy the file from local ansible server to standby.



The name of backup files are different on every machine. For example:

TEST1.0.db2inst1.DBPART000.20190729162630.001
TEST3.0.db2inst1.DBPART000.20180729172631.002


The playbook I was using looked like this:

- hosts: primary
   remote_user: root
   tasks:
   - name: copy backup to local file
     fetch: src={{item}} dest=/data1/backup 
     with_fileglob: /data1/{{dbname}}.0.db2inst1.*
  tags: transfer

 - hosts: standby
   remote_user: root
   tasks:
   - name: copy backup to standby
     copy: src={{item}} dest=/data1 mode=0755 owner=db2inst1
     with_fileglob: /data1/backup/{{dbname}}.0.db2inst1.*
   tags: transfer


(The playbook is run with the command: ansible-playbook -i hostfile transfer.yml --extra-vars "dbname=TEST1")

However, this doesn't work; I get this output:

primary  : ok=1    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    
standby  : ok=1    changed=0    unreachable=0    failed=0    skipped=1    rescued=0


I think the name of files are problem. What should I do?

Solution

with_fileglog creates a loop with the fileglob lookup. As all other lookups it runs on the controller machine, not on the remote server.

Since I guess you don't already have those backup files on the controller in the path you referenced, your loop is empty.

As you have guessed, this approach will not work for your scenario. I suggest you have a look at the find module to create the list of files to fetch from your primary server.

Context

StackExchange DevOps Q#8748, answer score: 3

Revisions (0)

No revisions yet.