Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/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
使用ansible_挂载和json_jquery的Playbook任务抛出错误_Ansible_Devops - Fatal编程技术网

使用ansible_挂载和json_jquery的Playbook任务抛出错误

使用ansible_挂载和json_jquery的Playbook任务抛出错误,ansible,devops,Ansible,Devops,我试图使用下面的任务来验证/dev/vdb分区的装入点是否为/data using ansible_mount。但是下面的playbook任务正在抛出断言失败错误。有人能告诉我为什么它会抛出错误,或者引导我找到正确的方法吗 附言:我对使用shell命令不感兴趣 - name: test for disk partitions vars: mount_data: "{{ ansible_mounts|json_query('[?device == `/dev/vdb

我试图使用下面的任务来验证/dev/vdb分区的装入点是否为/data using ansible_mount。但是下面的playbook任务正在抛出断言失败错误。有人能告诉我为什么它会抛出错误,或者引导我找到正确的方法吗

附言:我对使用shell命令不感兴趣

 - name: test for disk partitions
    vars:
      mount_data: "{{ ansible_mounts|json_query('[?device == `/dev/vdb`].mount') }}"

    assert:
      that:  mount_data == "/data"
      success_msg : "Expected mount point"
ansible_支架如下所示:

"ansible_mounts": [
            {
                "block_available": 51550174,
                "block_size": 4096,
                "block_total": 52425979,
                "block_used": 875805,
                "device": "/dev/vda1",
                "fstype": "xfs",
                "inode_available": 104768494,
                "inode_total": 104857072,
                "inode_used": 88578,
                "mount": "/",
                "options": "rw,relatime,attr2,inode64,noquota",
                "size_available": 211149512704,
                "size_total": 214736809984,
                "uuid": "3ef2b806-efd7-4eef-aaa2-2584909365ff"
            },
            {
                "block_available": 314410952,
                "block_size": 4096,
                "block_total": 314419200,
                "block_used": 8248,
                "device": "/dev/vdb",
                "fstype": "xfs",
                "inode_available": 125829117,
                "inode_total": 125829120,
                "inode_used": 3,
                "mount": "/data",
                "options": "rw,relatime,attr2,inode64,noquota",
                "size_available": 1287827259392,
                "size_total": 1287861043200,
                "uuid": "5214b6b0-04af-4ce9-ba46-06fa050d315f"
            },
            {
                "block_available": 26193352,
                "block_size": 4096,
                "block_total": 26201600,
                "block_used": 8248,
                "device": "/dev/vdc",
                "fstype": "xfs",
                "inode_available": 52428797,
                "inode_total": 52428800,
                "inode_used": 3,
                "mount": "/var/corefiles",
                "options": "rw,relatime,attr2,inode64,noquota",
                "size_available": 107287969792,
                "size_total": 107321753600,
                "uuid": "b7f230b1-ec81-4cd6-b2d4-20579eb135c6"
            }
        ],
执行任务时出现的错误

  FAILED! => {
    "assertion": "uu  == \"uu\"",
    "changed": false,
    "evaluated_to": false,
    "msg": "Assertion failed"
}

json_查询
中的
jmespath
表达式返回装载点列表,即使它只返回单个元素

您需要:

  • 检查列表的第一个元素是否等于字符串
  • 检查您的字符串是否包含在列表中
  • 以下三种解决方案都应该有效:

    that:mount_data.0==“/data”
    即:挂载数据包含“/数据”
    在mount_data中的“/data”
    
    您能显示输出吗?你能分享一下ansible\u mounts的样子吗?我不能添加ansible\u mounts o/p作为评论。我已经在我的问题后附上了ansible_mounts的o/p谢谢你的回答。但我真的不想使用位置。还有其他建议吗?第二个和第三个解决方案不使用位置。同时,在总是返回单个元素的列表上使用位置0并不是真正使用位置。这只是一种在其中获取单个字符串值的方法。您还可以将SO视为一种特定的工作方式。了解您的方法,更具体地说,在本例中:。很高兴我能帮忙。