Ansible var 文件var.yml:
---
OS: test123
OStype(gb): test
disk size(gb): test
main.yml
---
- name: read varibale-
hosts: localhost
gather_facts: no
tasks:
- include_vars: var.yml
- debug:
msg: "{{ OStype(gb) }}"
错误:
"msg": "The task includes an option with an undefined variable. The error was: 'OStype' is undefined\n\
最佳答案
对于变量名称包含特殊字符的情况,您可以使用 vars
lookup .
给定剧本:
- hosts: all
gather_facts: no
tasks:
- include_vars: vars.yml
- debug:
msg: "{{ lookup('vars', 'OStype(gb)') }}"
和文件vars.yml:
OS: test123
OStype(gb): test
disk size(gb): test
这会产生:
PLAY [all] *******************************************************************************************************
TASK [include_vars] **********************************************************************************************
ok: [localhost]
TASK [debug] *****************************************************************************************************
ok: [localhost] => {
"msg": "test"
}
PLAY RECAP *******************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
关于python - 读取名称中包含 "("的 ansible 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65010535/