Ansible-core 2.16 迁移指南

本节讨论了 ansible-core 2.15 与 ansible-core 2.16 之间的行为变化。

本指南旨在帮助您更新 Playbook、插件以及 Ansible 基础设施的其他部分,以便它们能与此版本的 Ansible 协同工作。

我们建议您在阅读本页的同时,参考 ansible-core 2.16 更新日志 (Changelog),以了解您可能需要进行的更新。

本文档是移植系列指南的一部分。完整的移植指南列表可以在 移植指南 中找到。

Playbook

  • 条件判断 - 由于在 ansible-core 2.16.1 中修复了安全问题 CVE-2023-5764,当嵌入式模板引用来自不可信来源(如模块结果或被标记为 !unsafe 的变量)的数据时,包含嵌入式模板块的条件表达式可能会失败,并显示错误信息“Conditional is marked as unsafe, and cannot be evaluated.”。当引用不可信数据时,带有嵌入式模板的条件判断可能是恶意模板注入的来源,且几乎总是可以在不使用嵌入式模板的情况下重写。Playbook 任务的条件关键字(如 whenuntil)长期以来一直显示警告,不鼓励在条件判断中使用嵌入式模板;此警告现已扩展到非任务条件,例如 assert 动作。

    - name: task with a module result (always untrusted by Ansible)
      shell: echo "hi mom"
      register: untrusted_result
    
    # don't do it this way...
    # - name: insecure conditional with embedded template consulting untrusted data
    #   assert:
    #     that: '"hi mom" is in {{ untrusted_result.stdout }}'
    
    - name: securely access untrusted values directly as Jinja variables instead
      assert:
        that: '"hi mom" is in untrusted_result.stdout'
    

命令行

弃用内容

模块

已移除的模块

弃用通知

值得注意的模块变更

插件

迁移自定义脚本

网络