On 12.09.2018 12:19, Eric Chang wrote:
let`s say I have some tasks below

first I want to detect a folder exists or not in all developer`s home_dir and register to eus_exist , and i will do something to whom did not have
the folder( D/eus)

- name: detect if D/eus exists
  tags: eus
  stat:
   path: "{{ item.home }}"
  register: eus_exist
  with_items: "{{ developers }}"


- name: debug eus_exist
  tags: eus
  debug:
    var:
neo_exist.results




and the debug messages like this

在此輸入代碼...
"neo_exist": {
        "changed": false,
        "msg": "All items completed",
        "results": [
            {
                "_ansible_ignore_errors": null,
                "_ansible_item_result": true,
                "_ansible_no_log": false,
                "_ansible_parsed": true,
                "changed": false,
                "failed": false,
                "invocation": {
                    "module_args": {
                        "checksum_algorithm": "sha1",
                        "follow": false,
                        "get_attributes": true,
                        "get_checksum": true,
                        "get_md5": null,
                        "get_mime": true,
                        "path": "/home/cch/D/eus"
                    }
                },
                "item": {
                    "dhome": "/home/cch/D",
                    "name": "cch",
                    "nb": "dc075.abc.com",
                    "neohome": "/home/cch/D/eus",
                    "ws": "qs055.abc.com"
                },
                "stat": {
                    "atime": 1536734130.8954637,
                    "attr_flags": "e",
                    "attributes": [
                        "extents"
                    ],
                    "block_size": 4096,
                    "blocks": 8,
                    "charset": "binary",
                    "ctime": 1536734058.8687162,
                    "dev": 66308,
                    "device_type": 0,
                    "executable": true,
                    "exists": true,
                    "gid": 19000,
                    "gr_name": "em",
                    "inode": 1315032,
                    "isblk": false,
                    "ischr": false,
                    "isdir": true,
                    "isfifo": false,
                    "isgid": false,
                    "islnk": false,
                    "isreg": false,
                    "issock": false,
                    "isuid": false,
                    "mimetype": "inode/directory",
                    "mode": "0755",
                    "mtime": 1536734058.8687162,
                    "nlink": 15,
                    "path": "/home/cch/D/eus",
                    "pw_name": "cch",
                    "readable": true,
                    "rgrp": true,
                    "roth": true,
                    "rusr": true,
                    "size": 4096,
                    "uid": 5000,
                    "version": "4154610742",
                    "wgrp": false,
                    "woth": false,
                    "writeable": true,
                    "wusr": true,
                    "xgrp": true,
                    "xoth": true,
                    "xusr": true
                }
            },

<snip />

I have no idea to use which attr to determine that folder exists or not.
any suggestions ??? thanks !

An example on how you can use it.

- debug: msg="The following path doesn't exist {{ item.stat.path }}"
  when: item.stat.exists == false
  with_items: '{{ neo_exist.results }}

--
Kai Stian Olstad

--
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/6a9cc51d21787ebb0c2a107cf0c19521%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to