On 1/20/21 4:31 PM, Nithin Subbaraj wrote:
> Hi Team,
> 
> I am trying to create an ansible script which excludes a particular directory 
> and its contents
> and should zip the files under other directories but getting the below error
> 
> TASK [archive the files] fatal: : FAILED! => {"msg": "'dict object' has no 
> attribute 'files'"}
> 

Only the find module would add "files" to the registered value- The command 
module
doesn't do that.

Regards
         Racke

> my script
> 
> ##################################
> ---
> - hosts: all
>   tasks:
>    - name: exclude an intermediate directory
>      find:
>         paths: /home/nsubbaraj/toplevel
>         recurse: true
>         excludes: foo
>      register: result
>    - debug:
>         msg: "{{ result.files|map(attribute='path')|list }}"
>    - name: exclude an intermediate directory with find command
>      command: >-
>        find toplevel -name foo -prune -o -type f -mtime +7  -print
>      register: results
>    - debug:
>        msg: "{{ result.stdout_lines }}"
>    - name: archive the files
>      become: yes
>      archive:
>       remove: yes
>       path: "{{ item.path }}"
>       dest: "{{ item.path }}-{{ansible_date_time.date.replace('-','')}}.gz"
>       format: zip
>      with_items: "{{ results.files }}"
> 
> #############################################
> 
> 
> PLAY [all]
> **********************************************************************************************************************************************************************************
> 
> TASK [Gathering Facts]
> **********************************************************************************************************************************************************************
> ok: [qc1udataoas01]
> 
> TASK [exclude an intermediate directory]
> ****************************************************************************************************************************************************
> ok: [qc1udataoas01]
> 
> TASK [debug]
> ********************************************************************************************************************************************************************************
>  {
>     "msg": [
>         "/home/nsubbaraj/toplevel/foo/testfile1.txt",
>         "/home/nsubbaraj/toplevel/bar/testfile2.txt",
>         "/home/nsubbaraj/toplevel/bar/testfile1",
>         "/home/nsubbaraj/toplevel/bar/testfile3.gz"
>     ]
> }
> 
> TASK [exclude an intermediate directory with find command]
> **********************************************************************************************************************************
> 
> 
> TASK [debug]
> ********************************************************************************************************************************************************************************
>  => {
>     "msg": [
>         "toplevel/bar/testfile1",
>         "toplevel/bar/testfile3.gz"
>     ]
> }
> 
> TASK [archive the files]
> ********************************************************************************************************************************************************************
> fatal:  FAILED! => {"msg": "'dict object' has no attribute 'files'"}
> 
> PLAY RECAP
> **********************************************************************************************************************************************************************************
>              : ok=5    changed=1    unreachable=0    failed=1    skipped=0    
> rescued=0    ignored=0
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to
> [email protected] 
> <mailto:[email protected]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/952bd8fe-5d09-4eb5-a48c-8ff85b0d22a0n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/952bd8fe-5d09-4eb5-a48c-8ff85b0d22a0n%40googlegroups.com?utm_medium=email&utm_source=footer>.


-- 
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/ad5c9791-4e52-278f-2b67-f1f8d4faeedb%40linuxia.de.

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to