【问题标题】:Ansible yaml rearrangement causes errorAnsible yaml 重排导致错误
【发布时间】:2023-03-12 17:05:01
【问题描述】:

my_tags 事实分配正在第二个分配中工作。列出的第一个分配导致失败,但这只是一个简单的重新排列。是的,我在运行它时正确地注释/取消了注释。

代码如下:

- name: Set optional tag
  when: machine_type.find('substr') != -1
  set_fact:
    # vvv some quoting error? vvv
    my_tags: {{ my_tags | default('') }}, sbc_type:{{ direction }},
    # vvv works just fine vvv
    #my_tags: sbc_type:{{ direction }}, {{ my_tags | default('') }}

这是错误:

    my_tags: {{ my_tags | default('') }}, sbc_type:{{ direction }},
                                        ^
We could be wrong, but this one looks like it might be an issue with
missing quotes.

当我从终端复制粘贴到此处时,如果有任何线索,克拉 (^) 指向“方向”变量,但我没有看到正在使用任何选项卡。

为什么重排会导致这个错误?

【问题讨论】:

  • 尝试" "引用{{ }}的第一组或第二组或两者。

标签: yaml ansible ansible-playbook


【解决方案1】:

这记录在Hey Wait, A YAML gotcha:

YAML 语法要求,如果你以 {{ foo }} 开始一个值,你 引用整行,因为它想确保你没有试图 启动 YAML 字典。

所以你应该这样写:

my_tags: "{{ my_tags | default('') }}, sbc_type:{{ direction }},"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多