Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.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 assert模块失败,返回“0”;检测到无效条件:无效语法(<;未知>;,第1行)";_Ansible_Assert_Stat - Fatal编程技术网

Ansible assert模块失败,返回“0”;检测到无效条件:无效语法(<;未知>;,第1行)";

Ansible assert模块失败,返回“0”;检测到无效条件:无效语法(<;未知>;,第1行)";,ansible,assert,stat,Ansible,Assert,Stat,我正在处理一个角色,在某个时候,它会在已经存在的路径上创建一些新目录,其中第一个名为“DB2_patching”。因为多个用户需要能够访问这些目录,所以我想确保“上面”我的目录都为其他人执行 我的计划是: 使用“DB2_补丁”分割路径;因此,我有我需要检查的目录 在分隔符“/”上再次拆分缩短的路径 使用join重新创建路径,同时使用stat获取必要的信息 做最后一个断言,看看是否一切正常 好吧,这个最后的断言失败了: “{”msg:“条件检查'result_join.results.0.stat

我正在处理一个角色,在某个时候,它会在已经存在的路径上创建一些新目录,其中第一个名为“DB2_patching”。因为多个用户需要能够访问这些目录,所以我想确保“上面”我的目录都为其他人执行

我的计划是:

  • 使用“DB2_补丁”分割路径;因此,我有我需要检查的目录
  • 在分隔符“/”上再次拆分缩短的路径
  • 使用join重新创建路径,同时使用stat获取必要的信息
  • 做最后一个断言,看看是否一切正常
  • 好吧,这个最后的断言失败了:

    “{”msg:“条件检查'result_join.results.0.stat.xoth' 失败。错误为:检测到无效的条件:无效语法 (,第1行)“}”

    assert任务看起来像这样,我试图循环一个变量,其中“item”也是变量。这是“result_join.results.{item}}.stat.xoth”

    • 我不明白为什么会发生错误,因为我能够从循环外的result_join中提取值;例如,在调试中使用“{result\u join.results.0.stat.path}}”
    似乎,当我在循环中使用“result\u join.results.{{item}}}.stat.xoth”时,出现了一些问题。我如何才能做到这一点?

    请参见。引用属性

    
    result\u join.results[item].stat.xoth
    
    比如说

    -hosts:localhost
    变量:
    结果:
    结果:
    项目1:
    斯达:
    是的
    项目2:
    斯达:
    xoth:错
    任务:
    -调试:
    var:result\u join.results[item].stat.xoth
    循环:
    -项目1
    -项目2
    
    给予

    任务[调试]****
    确定:[localhost]=>(item=item1)=>
    ansible_循环变量:项
    项目:项目1
    result\u join.results[item].stat.xoth:true
    确定:[localhost]=>(item=item2)=>
    ansible_循环变量:项
    项目:项目2
    result\u join.results[item].stat.xoth:false
    

    可以显示变量或消息。请参阅

    -调试:
    var:result\u join.results[item].stat.xoth
    循环:[item1,item2]
    -调试:
    msg:“{result_join.results[item].stat.xoth}”
    循环:[item1,item2]
    
    欢迎使用SO!请参阅。更新问题并将问题最小化为'result\u join.results.{item}.stat.xoth'。并删除不相关的详细信息。我编辑了这篇文章。我很抱歉没有遵守这些策略。我希望现在一切正常。是否可以在断言消息中使用路径值?我使用xoth进行评估,但希望显示类似“success_msg:”result_join.results[{item}].stat.path具有对其他人的执行权限。“”这不起作用。请展开整个表达式。请参见答案后的示例。在success_msg中使用“result_join.results[{{item}}].stat.path”产生:“msg”:“result_join.results[0].stat.path”;使用“{{result_join.results[{{item}].stat path}”产生{“msg”:模板化字符串时出现模板错误:应为标记“:”,已获取“}”。字符串:{{result\u join.results[{{item}}].stat.path}}}}两者都不显示项的路径
    - name: check execute for others
      assert:
        that:
          result_join.results.{{ item }}.stat.xoth
        success_msg: "Directory has execute permission for others."
        fail_msg: "Directory doesn't have execute permission for others!"
      with_sequence: start=0 end={{ nr_entries }}