gpt4 book ai didi

python - 读取名称中包含 "("的 ansible 变量

转载 作者:行者123 更新时间:2023-12-05 09:36:38 27 4
gpt4 key购买 nike

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com