【问题标题】:ansible deprecation warning with custom objects in aptapt中带有自定义对象的ansible弃用警告
【发布时间】:2020-06-06 17:58:31
【问题描述】:

我收到 Ansible 的弃用警告

[弃用警告]:通过 squash_actions 使用循环时仅调用一次“apt”已被弃用。不要使用循环来提供多个项目并指定名称:“{{ item.name | default(item) }}”,请使用名称:“{{ apt_dependencies }}”并删除循环。此功能将在 2.11 版中删除。可以通过在 ansible.cfg 中设置 deprecation_warnings=False 来禁用弃用警告。

- name: 'Install system dependencies'
  apt:
    name: "{{ item.name | default(item) }}"
    state: "{{ item.state | default('present') }}"
  with_items: "{{ apt_dependencies }}"

这让我可以这样做

apt_dependencies:
- name: curl
  state: absent
- name: ntp
  state: present
- docker

它建议用“{{ apt_dependencies }}”替换名称,但这不适用于自定义名称/状态

我这样做是为了安装依赖项以及删除服务器上不需要的任何内容

任何想法如何在没有警告的情况下将其更改为工作,我可以将其关闭,但我宁愿在删除之前修复它

【问题讨论】:

  • 请向我们展示您的剧本中的确切警告信息。
  • 我想这会有所帮助,添加到描述中

标签: linux ansible dependencies apt


【解决方案1】:

它建议用“{{ apt_dependencies }}”替换名称,但这不适用于自定义名称/状态

如果你将它们分成两个步骤,添加和删除:

- set_fact:
   remove_apt_packages: >-
     {{ apt_dependencies 
     | selectattr("state", "==", "absent")
     | map(attribute="name")
     | list }}

   # using "!= absent" allows for the case where the list item
   # doesn't say "present" such as your "docker" example
   add_apt_packages: >-
     {{ apt_dependencies 
     | selectattr("state", "!=", "absent")
     | map(attribute="name")
     | list }}
- name: 'Remove system dependencies'
  apt:
    name: "{{ remove_apt_packages }}"
    state: absent
- name: 'Install system dependencies'
  apt:
    name: "{{ add_apt_packages }}"
    state: present

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多