此任务(名称)有额外的参数,仅允许

Rob*_*err 10 ansible

以下方面的问题ansible.builtin.shellansible.builtin.command。可能没有正确使用它们,但用法与文档示例相匹配。
Ansible 版本 2.10.3

角色/rabbitmq/tasks/main.yml

---
# tasks file for rabbitmq

# If not shut down cleanly, the following will fix:
# systemctl stop rabbitmq-server
- name: Stop RabbitMQ service
  ansible.builtin.service:
    name: rabbitmq-server
    state: stopped
  become: yes

# rabbitmqctl force_boot
# https://www.rabbitmq.com/rabbitmqctl.8.html
# force_boot  Ensures that the node will start next time, even if it was not the last to shut down.
- name: Force RabbitMQ to boot anyway
  ansible.builtin.shell: /usr/sbin/rabbitmqctl force_boot

# systemctl start rabbitmq-server
- name: Stop RabbitMQ service
  ansible.builtin.service:
    name: rabbitmq-server
    state: started
  become: yes
Run Code Online (Sandbox Code Playgroud)

导致以下错误:

ERROR! this task 'ansible.builtin.shell' has extra params, which is only allowed in the following modules: shell, command, ansible.windows.win_shell, ...

The error appears to be in '.../roles/rabbitmq/tasks/main.yml': line 15, > column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

# force_boot  Ensures that the node will start next time, even if it was  not the last to shut down.
- name: Force RabbitMQ to boot anyway
 ^ here
Run Code Online (Sandbox Code Playgroud)

我试过ansible.builtin.command,带和不带cmd:参数。
我对用法有什么不明白?

小智 10

将您的 Ansible 更新到最新版本,这是一个错误https://github.com/ansible/ansible/pull/71824


jnb*_*bdz 6

尝试这个:

- name: Force RabbitMQ to boot anyway
  command: "/usr/sbin/rabbitmqctl force_boot"
  register: result
  ignore_errors: True
Run Code Online (Sandbox Code Playgroud)

我基本上把ansible.builtin.. 这个对我有用。

register将输出捕获到名为result的变量中。

ignore_errors 非常有用,因此如果发生错误,Ansible 不会停止。

您可以使用以下命令输出该变量:

- debug: var=result
Run Code Online (Sandbox Code Playgroud)

  • 但为什么 FQCN 在某些情况下不起作用? (2认同)