此任务(名称)有额外的参数,仅允许
以下方面的问题ansible.builtin.shell和ansible.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
导致以下错误:
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
我试过ansible.builtin.command,带和不带cmd:参数。
我对用法有什么不明白?
回答
尝试这个:
- name: Force RabbitMQ to boot anyway
command: "/usr/sbin/rabbitmqctl force_boot"
register: result
ignore_errors: True
我基本上把ansible.builtin.. 这个对我有用。
register将输出捕获到名为result的变量中。
ignore_errors 非常有用,因此如果发生错误,Ansible 不会停止。
您可以使用以下命令输出该变量:
- debug: var=result