This task (name) has extra params, which is only allowed

Viewed 16023

Having an issue with ansible.builtin.shell and ansible.builtin.command. Probably not using them right, but usage matches the docs examples.
Ansible version 2.10.3

In roles/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

Resulting in the following error:

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

I've tried ansible.builtin.command, both with and without the cmd: parameter.
What don't I understand about the usage?

3 Answers

Try this:

- name: Force RabbitMQ to boot anyway
  command: "/usr/sbin/rabbitmqctl force_boot"
  register: result
  ignore_errors: True

I basically took out the ansible.builtin.. It works for me.

register captures the output into a variable named result.

ignore_errors is useful so that if an error occurs Ansible will not stop.

You can output that variable with:

- debug: var=result

Try putting "" around your command i.e.

 ansible.builtin.shell: "/usr/sbin/rabbitmqctl force_boot"
Related