Ansible:(ansible.legacy.command)模块不支持的参数:警告

Nat*_*tan 12 ansible

今天我遇到了 Ansible playbook 的旧部分失败的情况:

现在的情况

- name: Install something
  shell: somecomand
  args:
    warn: false
Run Code Online (Sandbox Code Playgroud)

这会抛出致命错误:

"msg": "Unsupported parameters for (ansible.legacy.command) module: warn. Supported parameters include: chdir, _raw_params, removes, stdin, argv, executable, strip_empty_ends, stdin_add_newline, creates, _uses_shell."
Run Code Online (Sandbox Code Playgroud)

显然warn不再支持。我试图找到忽略警告的“新”方法,但我发现的所有内容都将我引向旧warn: false方法。

问题

忽略警告的“新”方法是什么?或者 - 如果想到更好的方法:解决此问题?

Ansible版本

pip show ansible
Name: ansible
Version: 7.0.0
Summary: Radically simple IT automation
Home-page: https://ansible.com/
Author: Ansible, Inc.
Author-email: info@ansible.com
License: GPLv3+
Location: /usr/local/lib/python3.10/dist-packages
Requires: ansible-core
Required-by:
Run Code Online (Sandbox Code Playgroud)

相同的剧本在以下情况下运行没有问题:

pip show ansible
Name: ansible
Version: 6.6.0
Summary: Radically simple IT automation
Home-page: https://ansible.com/
Author: Ansible, Inc.
Author-email: info@ansible.com
License: GPLv3+
Location: /home/ubuntu/.local/lib/python3.10/site-packages
Requires: ansible-core
Required-by: 
Run Code Online (Sandbox Code Playgroud)

Zei*_*tor 24

参数warnforshell在 Ansible 2.11 中已弃用,并在 Ansible 2.14 中删除。您可以查看以下资源以获取更多信息:

错误消息中报告的模块与实际使用的模块不同这一事实很奇怪。我没有调查这个问题,但看起来像是一些显示错误(待确认)

shell 的争论warn曾经是消除恼人警告的一种方法,例如:

您正在使用 XXX 的 shell,但有一个模块可以实现这一点。你确定你不是坏孩子吗?

ansible-lint如今,检查这些良好实践的方式已经完成,而消除警告的方式则有所不同

总之,此时你有 2 个选择:

  1. 降级到 ansible-core 2.13.x。由于您使用的是元社区包,因此正如您在问题中报告的那样,相应的最新版本是 ansible 6.6.0。
  2. 删除warn代码中所有 shell 任务的所有条目。如上所述。