既存のモジュールがないパッケージ固有のコマンドを使用しています。コマンドの出力(stdout)は0または1のいずれかです。私はstdoutの値を後でプレイブックで使用するための変数に代入しようとしています。しかし、私は明らかにキャプチャされているstdoutを分離するように見えることはできません。不可能:レジスタを使用して特定のフィールドを選択する方法
ok: [hostname1] => {
"dmstate": {
"changed": true,
"msg": "All items completed",
"results": [
{
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": true,
"cmd": "/usr/bin/ssh -q hostname1 \"/opt/REDACTED/bin/dmctl -s localhost:8426/dmbroker get DomainManager::hostname1-ampm1::state\"",
"delta": "0:00:01.808716",
"end": "2017-09-06 13:28:04.853221",
"invocation": {
"module_args": {
"_raw_params": "/usr/bin/ssh -q hostname1 \"/opt/REDACTED/bin/dmctl -s localhost:8426/dmbroker get DomainManager::hostname1-ampm1::state\"",
"_uses_shell": true,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"warn": true
}
},
"item": "hostname1-ampm1",
"rc": 0,
"start": "2017-09-06 13:28:03.044505",
"stderr": "",
"stderr_lines": [],
"stdout": "0",
"stdout_lines": [
"0"
]
}
]
}
}
私はset_factを使用していたみました:隔離とdmstate.resultsを検索するために、私は正しい構文を把握することはできません。この
tasks:
- name: check status
shell: '/usr/bin/ssh -q {{ inventory_hostname }} "/opt/REDACTED/bin/dmctl -s localhost:8426/dmbroker get DomainManager::{{ item }}::state" '
register: dmstate
with_items: "{{ myprocess }}"
- name: find stdout value
set_fact: stdout_value="{{ item.stdout }}"
when: item.dmstate.results.stdout == "stdout"
with_items: dmstate.results
- name: show value of stdout
debug: var=stdout_value
結果はここにある:
fatal: [hostname1]: FAILED! => {"failed": true, "msg": "The conditional check 'item.dmstate.results.stdout == \"stdout\"' failed. The error was: error while evaluating conditional (item.dmstate.results.stdout == \"stdout\"): 'AnsibleUnsafeText' object has no attribute 'dmstate'\n\n
ありがとうございました!これは私の必要性を解決し、私は何を使うべきかをよく理解する助けになりました。 – gantte