簡體   English   中英

Ansible 查找模塊無法打印找到匹配模式的文件

[英]Ansible find module fails to print files found matching pattern

我的目標服務器主目錄有如下文件:

$ cd ~
$ ls -la
total 84
drwxr--r--   7 wluser wluser  4096 Jun 11 02:56 .
drwxr-xr-x. 32 root    root     4096 Jun 10 03:20 ..
drwx------   4 wluser wluser    25 May 26 12:17 .ansible
-rw-------   1 wluser wluser 34681 Jun 11 03:29 .bash_history
-rw-r--r--   1 wluser wluser    18 Aug 21  2019 .bash_logout
-rw-r--r--   1 wluser wluser   193 Aug 21  2019 .bash_profile
-rw-r--r--   1 wluser wluser   231 Aug 21  2019 .bashrc
drwxrwxr-x   4 wluser wluser    27 Feb 17 04:48 .cache
drwxrwxr-x   4 wluser wluser    28 Feb 17 08:17 .config
-rw-r--r--   1 wluser wluser   172 Feb 17  2020 .kshrc
-rw-------   1 wluser wluser    40 May 28 11:59 .lesshst
drwxr-----   3 wluser wluser    18 Feb 17 08:17 .pki
-rw-------   1 wluser wluser  1204 Jul  5 10:05 .sh_history
drwxr--r--   2 wluser wluser    76 May 28 10:59 .ssh
-rw-------   1 wluser wluser 13314 Jun 11 02:56 .viminfo

我使用下面的 ansible play 來查找所有文件匹配模式:

121         - find:
122             paths: "/home/wluser/"
123             recurse: no
124             file_type: any
125             patterns:
126               - "*.sh*"
127               - "*.bash*"
128               - "*.ksh*"
129               - "*.profile*"
130               - ".ssh"
131           register: to_copy
132
133
134         - debug:
135             msg: "FOUNDDDXX {{ to_copy}}"

輸出顯示當我期望它可以工作並顯示主目錄中的所有文件時,它沒有匹配任何內容。

TASK [find] ***************************************************************************************************
task path: /web/playbooks/ansibleuser/va_action.yml:121

ok: [remotehost1] => {
    "changed": false,
    "examined": 72,
    "files": [],
    "invocation": {
        "module_args": {
            "age": null,
            "age_stamp": "mtime",
            "contains": null,
            "file_type": "any",
            "follow": false,
            "get_checksum": false,
            "hidden": false,
            "paths": [
                "/home/wluser/"
            ],
            "patterns": [
                "*.sh*",
                "*.bash*",
                "*.ksh*",
                "*.profile*",
                ".ssh"
            ],
            "recurse": false,
            "size": null,
            "use_regex": false
        }
    },
    "matched": 0,
    "msg": ""
}

TASK [debug] **************************************************************************************************
task path: /web/playbooks/ansibleuser/va_action.yml:134
ok: [remotehost1] => {
    "msg": "FOUNDDDXX {u'files': [], u'changed': False, 'failed': False, u'examined': 72, u'msg': u'', u'matched': 0}"
}

模式匹配可能不正確,但.ssh文件夾應該肯定匹配,但是也沒有找到。

$ ansible --version
ansible 2.4.2.0
  config file = /home/ansbladm/.ansible.cfg
  python version = 2.7.5

您能否建議我如何顯示與模式匹配的主目錄下的所有文件?

這對我有用

tasks:
- name: find files
  find:
    paths: /home/myuserId
    patterns:
    - "(.*bash.*)$"
    - "(.*ssh.*)$"
    use_regex: yes
    hidden: yes
  register: list_of_files
- name: print files
  debug:
    msg: "{{ list_of_files.files }}"

請注意use_regex: truehidden: true 沒有那個論點,它對我也不起作用。 我看到您在代碼中錯過了該參數。 試試看,讓我知道你看到了什么

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM