当我调试从命令模块注册的变量时,我无法访问 ansible 返回的结果数组中的某些值。
我正在使用 with_items 运行多个命令并将结果注册到“registeredVar”中。我尝试访问这样的结果,registeredVar.results.stdout但我得到“变量未定义!” 错误。
我还尝试在调试任务中循环遍历结果数组,但出现“对象”没有属性“stdout”错误
以下是我正在运行的任务
- name: check configuration
shell: "{{ item }}"
register: falcon_config
with_items:
- /opt/CrowdStrike/falconctl -g --aph
- /opt/CrowdStrike/falconctl -g --cid
- /opt/CrowdStrike/falconctl -g --app
Run Code Online (Sandbox Code Playgroud)
下面是输出变量的调试任务
- debug:
var: falcon_config['results'].stdout
Run Code Online (Sandbox Code Playgroud)
替代方案:
- debug:
var: '{{ item.stdout }}'
with_items: falcon_config['results']
Run Code Online (Sandbox Code Playgroud)
这是运行时结果数组的调试输出falcon_config['results']
"falcon_config['results']": [
{
"_ansible_ignore_errors": null,
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": true,
"cmd": "/opt/CrowdStrike/falconctl -g --aph",
"delta": "0:00:00.006724",
"end": "2019-07-29 10:36:05.481672",
"failed": false,
"invocation": {
"module_args": {
"_raw_params": "/opt/CrowdStrike/falconctl …Run Code Online (Sandbox Code Playgroud) ansible ×1