Answers: <p>You are registering the output of the <code>copy</code> module in the <code>result</code> variable. When the copy module runs in a loop, it returns a <code>results</code> key that contains each item of the loop.</p>
  <p>The copy module does not have a <code>files</code> return value. The return values are <a href="https://docs.ansible.com/ansible/latest/collections/ansible/builtin/copy_module.html#return-values" rel="nofollow noreferrer">listed here</a>. What you want to use is the <code>dest</code> value.  The <code>dest</code> value is where you copied the file using the <code>copy</code> module, that will become your <code>src</code> value for the <code>unarchive</code> module.</p>
  <p>You can adjust your playbook to use those variables like this:</p>
  <pre class="lang-yaml prettyprint-override"><code>
  - name: find and archive
    hosts: localhost
    tasks:
      - name: find the file
        copy:
          src: &quot;{{ item }}&quot;
          dest: &quot;/home/ec2-user/bb&quot;
          remote_src: yes
        with_fileglob:
          - &quot;/home/ec2-user/aa/Data*&quot;
        register: result
      - name: show the result file path
        debug:
          msg: &quot;{{ item.dest }}&quot;
        loop: &quot;{{ result.results }}&quot;
      - name: extract file
        unarchive:
          src: &quot;{{ item.dest }}&quot;
          dest: /home/ec2-user/cc/
        loop: &quot;{{ result.results }}&quot;
  
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2021-10-28T14:26:45.227Z
Answers: 2021-10-28T14:26:45.227Z
Answers: swysocki
Body: <p>I tried below ansible tasks  with copy and unarchive modules and facing error</p>
  <pre><code>- name: find and archive
    hosts: localhost
    tasks:
      - name: find the file
        copy:
          src: &quot;{{ item }}&quot;
          dest: &quot;/home/ec2-user/bb&quot;
          remote_src: yes
        with_fileglob:
          - &quot;/home/ec2-user/aa/Data*&quot;
        register: result
      - name: show the result file path
        debug:
          msg: &quot;{{ item.path }}&quot;
        loop: &quot;{{ result.files }}&quot;
      - name: extract file
        unarchive:
          src: &quot;{{ item.path }}&quot;
          dest: /home/ec2-user/cc/
        loop: &quot;{{ result.files }}&quot;
  </code></pre>
  <p>the error is:</p>
  <pre><code>fatal: [localhost]: FAILED! =&gt; {&quot;msg&quot;: &quot;'dict object' has no attribute 'files'&quot;}
  </code></pre>
  
Tags: <ansible>
Title: Copy and unarchive Ansible Module
UserDisplayName: vtr
ThreadText: # Copy and unarchive Ansible Module
  
  (Asked by: username_0 on 2021-10-22)
  
  I tried below ansible tasks with copy and unarchive modules and facing error
  
  ```
  - name: find and archive
    hosts: localhost
    tasks:
      - name: find the file
        copy:
          src: "{{ item }}"
          dest: "/home/ec2-user/bb"
          remote_src: yes
        with_fileglob:
          - "/home/ec2-user/aa/Data*"
        register: result
      - name: show the result file path
        debug:
          msg: "{{ item.path }}"
        loop: "{{ result.files }}"
      - name: extract file
        unarchive:
          src: "{{ item.path }}"
          dest: /home/ec2-user/cc/
        loop: "{{ result.files }}"
  
  ```
  
  the error is:
  
  ```
  fatal: [localhost]: FAILED! => {"msg": "'dict object' has no attribute 'files'"}
  
  ```
  
  **Tags:** ansible
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-10-28. Score: 1
  
  You are registering the output of the `copy` module in the `result` variable. When the copy module runs in a loop, it returns a `results` key that contains each item of the loop.
  
  The copy module does not have a `files` return value. The return values are [listed here](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/copy_module.html#return-values). What you want to use is the `dest` value. The `dest` value is where you copied the file using the `copy` module, that will become your `src` value for the `unarchive` module.
  
  You can adjust your playbook to use those variables like this:
  
  ```yaml
  
  - name: find and archive
    hosts: localhost
    tasks:
      - name: find the file
        copy:
          src: "{{ item }}"
          dest: "/home/ec2-user/bb"
          remote_src: yes
        with_fileglob:
          - "/home/ec2-user/aa/Data*"
        register: result
      - name: show the result file path
        debug:
          msg: "{{ item.dest }}"
        loop: "{{ result.results }}"
      - name: extract file
        unarchive:
          src: "{{ item.dest }}"
          dest: /home/ec2-user/cc/
        loop: "{{ result.results }}"
  
  ```
  
  
  ---
  
  