***************************************************************************node1 : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
看到数据类型显示为str让我很诧异,但这里给出了解释和处置办法(https://github.com/ansible/ansible/issues/14179)。
另外,假设您从Tower运转同一个剧本,将参数作为额外变量或调查字段来传递,参数的数据类型就会是int。
是的,这有点复杂,但假设您知道找什么,这些“功用”对您来说不成成绩。
5. 列出理想和变量无论您在库存中定义了变量,还是在剧本执行时期创立和赋予了额外变量,它在某个时分关于反省值很有用:
---
- name: vars
hosts: node1,node2
tasks:
- name: Dump vars
copy:
content: "{{ hostvars[inventory_hostname] | to_nice_yaml }}"
dest: "/tmp/{{ inventory_hostname }}_vars.txt"
delegate_to: control
- name: Dump facts
copy:
content: "{{ ansible_facts | to_nice_yaml }}"
dest: "/tmp/{{ inventory_hostname }}_facts.txt"
delegate_to: control
这将把变量和理想 (假设您在搜集理想)保存在独自的文件中,供您剖析。
6. 运用义务调试器从命令行排查您还可以运用Ansible调试器,在逐渐形式下执行剧本,并以交互方式反省变量和参数的内容。
此外,还可以实时改动变量的值,并继续执行。
可以在义务或剧本层面启用调试器,比如在以下示例中:
---
- name: Example using debugger
hosts: localhost
gather_facts: no
vars:
radius: "5.3"
pi: "3.1415926535"
debugger: on_failed
tasks:
- name: Calculate the area of a circle
debug:
msg:
- "Radius.............: {{ radius }}"
- "pi................: {{ pi }}"
- "Area of the circle: {{ (pi * (radius * radius)) }}"
事前声明一下:我将变量定义为字符串,我试图执行计算时这显然会引发错误。
> ansible-playbook xdebugger.yml
PLAY [Example using debugger]
***************************************************************************
TASK [Calculate the area of a circle]
***************************************************************************
fatal: [localhost]: FAILED! => {"msg": "Unexpected templating type error occurred on (Area of the circle: {{ (pi * (radius * radius)) }}): can't multiply sequence by non-int of type 'AnsibleUnicode'"}
[localhost] TASK: Calculate the area of a circle (debug)> p task_vars['pi']
'3.1415926535'
(责任编辑:admin)