Ansible 断言模块失败,出现"Invalid conditional detected: invalid syntax (<unknown>, line 1)"



我正在处理一个角色,在某个时刻,该角色会在现有路径上创建一些新目录,其中第一个名为";DB2_打补丁";。因为多个用户需要能够访问这些目录,所以我想确保目录";以上";我的都是替别人执行的。

我的计划是:

  1. 用";DB2_打补丁";;因此我有了需要检查的目录
  2. 在分隔符上再次分割缩短的路径"/">
  3. 使用join重新创建路径,同时使用stat获取必要的信息
  4. 做最后一次断言,看看是否一切正常

好吧,这个最后断言失败了:

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

assert任务看起来是这样的,我正试图循环一个变量;项目";也是可变的。这是";result_join.results.{{item}}.stat.xoth"。

- 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 }}
  • 我不明白为什么会发生错误,因为我可以从循环外的result_join中提取值;例如使用"{{result_join.results.0.stat.path}}"带调试

看起来,当我使用";result_join.results.{{item}}.stat.xoth"在一个循环中,有些事情搞砸了。我怎样才能做到这一点?

请参阅引用键:值字典变量。引用属性

that:
result_join.results[item].stat.xoth

例如

- hosts: localhost
vars:
result_join:
results:
item1:
stat:
xoth: true
item2:
stat:
xoth: false
tasks:
- debug:
var: result_join.results[item].stat.xoth
loop:
- item1
- item2

给出

TASK [debug] ****
ok: [localhost] => (item=item1) => 
ansible_loop_var: item
item: item1
result_join.results[item].stat.xoth: true
ok: [localhost] => (item=item2) => 
ansible_loop_var: item
item: item2
result_join.results[item].stat.xoth: false

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

- debug:
var: result_join.results[item].stat.xoth
loop: [item1, item2]
- debug:
msg: "{{ result_join.results[item].stat.xoth }}"
loop: [item1, item2]

相关内容

最新更新