Thanks, Brian
That works.
On Wednesday, September 18, 2019 at 2:31:17 PM UTC-4, R-JRI wrote:
>
> Hi,
>
> I created a simple yml file to get file or files from a remote host to
> local host:
> $ cat fetch.yml
> ---
> - hosts: serverA
>
> tasks:
> - name: find the files
> find:
> paths: /usr/local/apps/log
> patterns: AppsAdmin.*.ALLAPPS.20190828*
> use_regex: True
> register: Apps_files
>
> - debug:
> var: Apps_files.files.path
>
> - name:
> fetch:
> src: "{{ item }}"
> dest: /APPADMIN/ansible/nonprod/DR_test/
> with_items: "{{ Apps_files.files.path }}"
>
> The variable 'Apps_files.files.path' is getting from the output of debug.
>
> Here is the output when ran it.
>
> [appadmin@serverB][/APPADMIN/ansible/nonprod/DR_test]$ ansible-playbook
> fetch.yml
>
> PLAY [serverA]
> ****************************************************************************************************************************************************************************************************************
>
> TASK [Gathering Facts]
> **********************************************************************************************************************************************************************************************************************
> ok: [serverA]
>
> TASK [find the files]
> ***********************************************************************************************************************************************************************************************************************
> ok: [serverA]
>
> TASK [debug]
> ********************************************************************************************************************************************************************************************************************************
> ok: [serverA] => {
> "Apps_files.files.path": "VARIABLE IS NOT DEFINED!"
> }
>
> TASK [fetch]
> ********************************************************************************************************************************************************************************************************************************
> fatal: [serverA]: FAILED! => {"msg": "'list object' has no attribute
> 'path'"}
>
> PLAY RECAP
> **********************************************************************************************************************************************************************************************************************************
> serverA : ok=3 changed=0 unreachable=0 failed=1
> skipped=0 rescued=0 ignored=0
>
>
> When debug model only has Apps_files as variable:
> -debug:
> var: Apps_files
>
> The output of debug is:
> TASK [debug]
> ********************************************************************************************************************************************************************************************************************************
> ok: [serverA] => {
> "Apps_files": {
> "changed": false,
> "examined": 36,
> "failed": false,
> "files": [
> {
> "atime": 1567021803.0147924,
> "ctime": 1567021803.0087924,
> "dev": 64770,
> "gid": 0,
> "gr_name": "root",
> "inode": 134304,
> "isblk": false,
> "ischr": false,
> "isdir": false,
> "isfifo": false,
> "isgid": false,
> "islnk": false,
> "isreg": true,
> "issock": false,
> "isuid": false,
> "mode": "0644",
> "mtime": 1567021803.0047922,
> "nlink": 1,
> "path":
> "/usr/local/apps/log/AppsAdmin.stop.ALLAPPS.201908281548.21882.log", <--
> file wanted to get from serverA
> "pw_name": "root",
> "rgrp": true,
> "roth": true,
> "rusr": true,
> "size": 10253,
> "uid": 0,
> "wgrp": false,
> "woth": false,
> "wusr": true,
> "xgrp": false,
> "xoth": false,
> "xusr": false
> },
> {
> "atime": 1568752920.7074213,
> "ctime": 1567023296.6011353,
> "dev": 64770,
> "gid": 0,
> "gr_name": "root",
> "inode": 134315,
> "isblk": false,
> "ischr": false,
> "isdir": false,
> "isfifo": false,
> "isgid": false,
> "islnk": false,
> "isreg": true,
> "issock": false,
> "isuid": false,
> "mode": "0644",
> "mtime": 1567023296.5971353,
> "nlink": 1,
> "path":
> "/usr/local/apps/log/AppsAdmin.start.ALLAPPS.201908281606.30560.log", <--
> file wanted to get from serverA
> "pw_name": "root",
> "rgrp": true,
> "roth": true,
> "rusr": true,
> "size": 8549,
> "uid": 0,
> "wgrp": false,
> "woth": false,
> "wusr": true,
> "xgrp": false,
> "xoth": false,
> "xusr": false
> }
> ],
> "matched": 2,
> "msg": ""
> }
> }
>
> So I modified variable of 'debug' to 'Apps_files.files.path' for the file
> name and location that I want to get. Does anyone know why it failed?
> Thanks.
>
>
>
--
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/29744d7e-563e-49c6-9def-56bb3b614ab6%40googlegroups.com.