Ansible无法运行任何命令或shell。

3

我在我的树莓派上运行任何命令或shell时遇到了问题。

当我使用以下代码时:

- name: Example command
  ansible.builtin.command:
    cmd: "cat /etc/motd"

我遇到了这个错误:

Unsupported parameters for (ansible.builtin.command) module: cmd Supported parameters include: _raw_params, _uses_shell, argv, chdir, creates, executable, removes, stdin, stdin_add_newline, strip_empty_ends, warn"}

当我尝试这样做:

- name: Example command
  ansible.builtin.command: cat /etc/motd

我遇到了这个错误:

ERROR! this task 'ansible.builtin.command' has extra params, which is only allowed in the following modules: import_tasks, raw, include, include_tasks, include_vars, include_role, script, set_fact, win_command, add_host, shell, import_role, group_by, command, win_shell, meta

当我尝试使用ansible.builtin.shell时,我遇到了相同的错误。我尝试了几个其他命令,但都没有成功。似乎我无法运行任何命令而不出现这两个错误。
我使用的是ansible 2.9.6。我尝试升级它,但apt说它已经是最新的可用版本了。
感谢任何帮助。
2个回答

6

ansible.builtin.command替换为command。你的Ansible版本太旧,无法使用新语法。这适用于Ansible 2.9.6:

- hosts: localhost
  gather_facts: false
  tasks:
    - command: cat /etc/motd

谢谢,可以了。我不明白为什么在 ansible 2.9 版本的文档中要使用 ansible.builtin.command。 - e_scape
1
我认为问题在于2.9的后续版本确实支持新语法,而Ansible没有提供次要版本的文档(即您不会找到2.9.x和2.9.y的文档,只有2.9)。如果您只是获取2.9.6的源代码,您可以构建自己的本地文档版本,这将是正确的。 - larsks

0

我通过删除apt安装的Ansible版本,然后按照Ansible文档网站上的安装说明再次通过pip进行安装来解决了这个问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接