【问题标题】:Ansible : [DEPRECATION WARNING]: Using bare variables is deprecated [duplicate]Ansible:[弃用警告]:不推荐使用裸变量[重复]
【发布时间】:2016-04-26 17:13:39
【问题描述】:

我认为这是剧本中产生错误的部分。我应该如何重写这部分?

roles: 
- role: json-transform
  json_transforms: '{{ clientValidation.json_transforms}}'

它会引发以下警告:

[DEPRECATION WARNING]: Using bare variables is deprecated. Update your playbooks so that the environment value uses the full variable syntax ('{{json_transforms}}'). This feature will be removed in a 
future release. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.

【问题讨论】:

  • 您使用的是什么 Ansible 版本?这种语法对我来说有点奇怪,通常我会使用类似:- { role: json-transform, json_transforms: '{{ clientValidation.json_transforms}}' } 所以你可能想尝试一下。
  • 我正在使用 Ansible 2.0.1 我已经尝试过你提到的但它没有工作。
  • 语法无关紧要-@ydaetskcoR 只是使用内联dict 语法而不是扩展的yaml dict 语法。它们在解析后的文档中完全相同。
  • 似乎这个问题在某种程度上与这里的这个主题有关 [1]。当您尝试对裸变量使用 then “when” 方法进行验证时,通常会发生这种情况。从 ansible 2.8 及更高版本开始,您应该使用 when: myVariable|bool 之类的东西以符合最新标准 [1] github.com/geerlingguy/ansible-role-ntp/issues/59

标签: ansible


【解决方案1】:

看起来你的高层没有什么问题——这可能是你角色内部的问题。不推荐使用的裸变量通常出现在with_xxx 循环中;例如:

- hosts: blar
  vars:
    items:
    - one
    - two
  tasks:
  - debug: msg="hi from {{ item }}"
    with_items: items

在这种情况下,它告诉您with_items: items 应该是with_items: "{{ items }}"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-12
    • 2012-05-10
    • 1970-01-01
    • 2021-08-09
    • 1970-01-01
    • 1970-01-01
    • 2020-01-31
    • 1970-01-01
    相关资源
    最近更新 更多