Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops Ansible解析来自循环_Loops_Parsing_Ansible - Fatal编程技术网

Loops Ansible解析来自循环

Loops Ansible解析来自循环,loops,parsing,ansible,Loops,Parsing,Ansible,对ansible来说相当陌生-以下是我正在尝试做的。我已经创建了一个剧本来监控一些服务器。剧本中的任务之一是检查服务器是否成功备份 任务如下: -name: Grabbing all of the files that were created today on Server1 shell: find /back/up/location/ -maxdepth 1 -daystart -ctime 0 -print with_items: - '{{ inventory_hostname

对ansible来说相当陌生-以下是我正在尝试做的。我已经创建了一个剧本来监控一些服务器。剧本中的任务之一是检查服务器是否成功备份

任务如下:

-name: Grabbing all of the files that were created today on Server1
 shell: find /back/up/location/ -maxdepth 1 -daystart -ctime 0 -print
 with_items:
   - '{{ inventory_hostname }}'
 when: item == "Server1"
 register: Server1
我在这里访问输出:

-debug: var=Server1.results
输出显示为:

ok: [Server1] => {
"changed": false, 
"Server1.results": [
    {
        "_ansible_item_result": true, 
        "_ansible_no_log": false, 
        "_ansible_parsed": true, 
        "changed": true, 
        "cmd": "find /back/up/location/ -maxdepth 1 -daystart -ctime 0 -print", 
        "delta": "0:00:00.007869", 
        "end": "2017-03-21 16:39:27.110185", 
        "invocation": {
            "module_args": {
                "_raw_params": "find /back/up/location/ -maxdepth 1 -daystart -ctime 0 -print",
                "_uses_shell": true, 
                "chdir": null, 
                "creates": null, 
                "executable": null, 
                "removes": null, 
                "warn": true
            }
        }, 
        "item": "Server1", 
        "rc": 0, 
        "start": "2017-03-21 16:39:27.102316", 
        "stderr": "", 
        "stderr_lines": [], 
        "stdout": "/back/up/location/\n/back/up/location/FULL-2017-03-22_14-22",
        "stdout_lines": [
            "/back/up/location/", 
            "/back/up/location/FULL-2017-03-22_14-22"
        ]
    }
]
然而,我真的只关心这一点:

          ` "stdout_lines": [
            "/back/up/location/", 
            "/back/up/location/FULL-2017-03-22_14-22"
        ]`
为了进行以下比较:

-debug: msg="Backup was successful"
 when: Server1.results|length != 0
ansible中是否有方法解析
Server1.results
以仅包含
stdout\u行
字段?欢迎任何建议和帮助

您应该能够使用:
-debug:var=Server1.results[0]。stdout_行

为什么像在Ansible中通常那样使用循环而不是主机模式在主机上进行迭代?@KonstantinSuvorov,我想我不知道this@KonstantinSuvorov.split属性是否适用于ansible中的列表?错误<代码>结果是一个列表。你说得对。它应该是Server1.results[0].stdout\u行。