Answers: <p><code>with_fileglog</code> creates a loop with the <a href="https://docs.ansible.com/ansible/latest/plugins/lookup/fileglob.html" rel="nofollow noreferrer"><code>fileglob</code> lookup</a>. As all other <a href="https://docs.ansible.com/ansible/latest/user_guide/playbooks_lookups.html" rel="nofollow noreferrer">lookups</a> it runs on the controller machine, not on the remote server.</p>
  
  <p>Since I guess you don't already have those backup files on the controller in the path you referenced, your loop is empty.</p>
  
  <p>As you have guessed, this approach will not work for your scenario. I suggest you have a look at the <a href="https://docs.ansible.com/ansible/latest/modules/find_module.html" rel="nofollow noreferrer"><code>find</code> module</a> to create the list of files to fetch from your primary server.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-08-08T19:02:03.190Z
Answers: 2019-08-08T19:02:03.190Z
Answers: Zeitounator
Answers: <p>any <code>with_*</code> is actully a local lookup.</p>
  
  <p>So as Zeitounator mentioned, you're going to need to use something like the <code>find</code> module to fetch the files you want.</p>
  
  <p>so I imagine that something like this would work:</p>
  
  <pre><code>- hosts: primary
    remote_user: root
    tasks:
      - name: gather list of files to fetch
        find:
          paths: "/data1/"
          recurse: no
          patterns: "{{ dbname }}.0.db2inst1.*"
          use_regex: no
        regisrer: db_backup_src
      - name: fetch backups to local disk
         fetch:
           src: "{{ item['path'] }}"
           dest: /data1/backup/
           flat: yes
        loop: "{{ db_backuo_src['files'] }}"
  
  - 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.*"
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2019-09-02T20:12:23.063Z
Answers: 2019-09-02T20:12:23.063Z
Answers: hvindin
Body: <p>I need to copy a database backup file from a primary server to a standby server. Since I can't use <code>synchronize</code>, I was following this method:</p>
  <ol>
  <li>copy a file from primary to the local ansible server,</li>
  <li>copy the file from local ansible server to standby.</li>
  </ol>
  <p>The name of backup files are different on every machine. For example:</p>
  <pre><code>TEST1.0.db2inst1.DBPART000.20190729162630.001
  TEST3.0.db2inst1.DBPART000.20180729172631.002  
  </code></pre>
  <p>The playbook I was using looked like this:</p>
  <pre><code> - 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  
  </code></pre>
  <p>(The playbook is run with the command: <code>ansible-playbook -i hostfile transfer.yml --extra-vars &quot;dbname=TEST1&quot;</code>)</p>
  <p>However, this doesn't work; I get this output:</p>
  <pre><code>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    
  </code></pre>
  <p>I think the name of files are problem. What should I do?</p>
  
Comments: CC BY-SA 4.0
Comments: 2019-07-30T07:27:43.583Z
Comments: The fact that the tasks are skipped means that your loop (ie, with_fileglob) is passing an empty list. Perhaps that hint may help?
Comments: Bruce Becker
Comments: CC BY-SA 4.0
Comments: 2019-07-31T12:06:38.707Z
Comments: Can you show more of the Ansible output so we can see what the tasks are doing?
Comments: Bruce Becker
Comments: CC BY-SA 4.0
Comments: 2019-07-31T14:07:41.600Z
Comments: @BruceBecker i will update my question as soon as i get access to my pc. thank you for reply.
Comments: BlackCrystal
Tags: <ansible><linux><centos>
Title: using copy module with wildcards
UserDisplayName: BlackCrystal
ThreadText: # using copy module with wildcards
  
  (Asked by: username_0 on 2019-07-30)
  
  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:
  
  1. copy a file from primary to the local ansible server,
  2. 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?
  
  **Tags:** ansible, linux, centos
  
  > **Comments:**
  > **username_1**: The fact that the tasks are skipped means that your loop (ie, with_fileglob) is passing an empty list. Perhaps that hint may help?  
  > **username_1**: Can you show more of the Ansible output so we can see what the tasks are doing?  
  > **username_0**: @username_1 i will update my question as soon as i get access to my pc. thank you for reply.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2019-08-08. Score: 3
  
  `with_fileglog` creates a loop with the [`fileglob` lookup](https://docs.ansible.com/ansible/latest/plugins/lookup/fileglob.html). As all other [lookups](https://docs.ansible.com/ansible/latest/user_guide/playbooks_lookups.html) 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](https://docs.ansible.com/ansible/latest/modules/find_module.html) to create the list of files to fetch from your primary server.
  
  
  ---
  
  ### Answer by username_3 on 2019-09-02. Score: 2
  
  any `with_*` is actully a local lookup.
  
  So as username_2 mentioned, you're going to need to use something like the `find` module to fetch the files you want.
  
  so I imagine that something like this would work:
  
  ```
  - hosts: primary
    remote_user: root
    tasks:
      - name: gather list of files to fetch
        find:
          paths: "/data1/"
          recurse: no
          patterns: "{{ dbname }}.0.db2inst1.*"
          use_regex: no
        regisrer: db_backup_src
      - name: fetch backups to local disk
         fetch:
           src: "{{ item['path'] }}"
           dest: /data1/backup/
           flat: yes
        loop: "{{ db_backuo_src['files'] }}"
  
  - 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.*"
  
  ```
  
  
  ---
  
  