通過debug模組去確認返回結果的資料結構
1.通過debug模組去確認返回結果的資料結構
獲取Task任務結果 - name: check nginx syntax shell: /usr/sbin/nginx -t register: nginxsyntax 通過debug模組去確認返回結果的資料結構 - name: print nginx syntax result debug: var=nginxsyntax "nginxsyntax": { "changed": true, "cmd": "/usr/sbin/nginx -t", "delta": "0:00:00.012045","end": "2017-08-12 20:19:04.650718", "rc": 0, "start": "2017-08-12 20:19:04.638673", "stderr": "nginx: the configuration file /etc/nginx/nginx.conf syntax is ok\nnginx: configuration file /etc/nginx/nginx.conf test is successful", "stderr_lines": [ "nginx: the configuration file /etc/nginx/nginx.conf syntax is ok", "nginx: configuration file /etc/nginx/nginx.conf test is successful" ], "stdout": "", "stdout_lines": [] }
2.我的debug
--- - name: a template example hosts: frame remote_user: root tasks: - name: max login try count shell: egrep -i 'MaxAuthTries' /etc/ssh/sshd_config |awk '{print $2}' register: try_count - name: echo last shell result var debug: var=try_count - name: echo last shell result debug: msg: "{{ try_count['stdout_lines'] }}"
TASK [max login try count] *************************************************************************************************************************
changed: [10.0.0.4]
TASK [echo last shell result var] ******************************************************************************************************************
ok: [10.0.0.4] => {
"try_count": {
"changed": true,
"cmd": "egrep -i 'MaxAuthTries' /etc/ssh/sshd_config |awk '{print $2}'",
"delta": "0:00:00.050398",
"end": "2020-10-27 21:05:05.333621",
"failed": false,
"rc": 0,
"start": "2020-10-27 21:05:05.283223",
"stderr": "",
"stderr_lines": [],
"stdout": "6",
"stdout_lines": [
"6"
]
}
}
TASK [echo last shell result] **********************************************************************************************************************
ok: [10.0.0.4] => {
"msg": [
"6"
]
}