playbook debug模块定义变量
---
如果我们想在执行一条命令之后想要通过debug模块输出命令的执行结果可以通过以下方式:
···
- name: login to rancher service
shell: "docker run --net=host --rm {{ registry_ip }}:{{ registry_port }}/{{ rancher_curl_version }} -s https://{{ cluster_vip }}/v3-public/localProviders/local?action=login -H 'content-type: application/json' --data-binary '{\"username\":\"admin\",\"password\":\"admin\"}' --insecure|jq -r .token"
register: rancher_login_token
run_once: yes
- name: define first login rancher token
debug: var=rancher_login_token.stdout
run_once: yes
···
输出结果如下:
```
TASK [rancher : define first login rancher token] ******************************************************************************************************************************************
ok: [192.168.100.11] => {
"rancher_login_token.stdout": "token-sjptv:v68l44wzgk95k78vw4jxq8xrdd7rh58x9bxjdjn4nr2d2gj5559qgp"
}
```