我正在尝试通过拍摄来查找 Zookeeper 进程的状态/path/to/zookeeper/bin/zkServer.sh 状态并检查rc变量。但是 ansible 说输出中没有 rc 变量。
我附上了一些片段:
这里,输出显示 rc
changed: [staging] => {
"changed": true,
"cmd": [
"/path/to/zookeeper/bin/zkServer.sh",
"status"
],
"delta": "0:00:00.222272",
"end": "2017-10-17 14:30:23.937679",
"invocation": {
"module_args": {
"_raw_params": "/path/to/zookeeper/bin/zkServer.sh",
"_uses_shell": false,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"warn": true
}
},
"rc": 0,
"start": "2017-10-17 14:30:23.715407",
"stderr": "JMX enabled by default\nUsing config: /path/to/zookeeper/bin/../conf/zoo.cfg",
"stderr_lines": [
"JMX enabled by default",
"Using config: /path/to/zookeeper/bin/../conf/zoo.cfg"
],
"stdout": "Mode: follower",
"stdout_lines": [
"Mode: follower"
]
}
ansible 显示以下错误
fatal: [staging]: FAILED! => {
"failed": true,
"msg": "The conditional check 'output.rc != 0' failed. The error was: error while evaluating conditional (output.rc != 0): 'dict object' has no attribute 'rc'}
获取输出变量的任务:
- name : "Check Zookeeper Service"
command : /path/to/zookeeper/bin/zkServer.sh status
register : output
比较 rc 变量的任务
- name: "Checking RC"
fail: msg="Zookeeper Service is DOWN"
when: output.rc != 0
你能告诉我这里可能存在什么问题吗?
谢谢。
答案1
评论答案:
– “check rc”任务是否紧接着“check zookeeper”执行?
– 不,中间也有几个任务被跳过了,但它们确实注册了相同的变量。
– 这就是问题所在。
register:
即使对于跳过的任务也要记录结果。
看这个 SO 线程了解详情。