Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ansible

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?

like image 546
Robert Kerr Avatar asked Feb 12 '21 19:02

Robert Kerr


2 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
like image 85
jnbdz Avatar answered Nov 16 '22 06:11

jnbdz


Update your Ansible to the latest version, its a bug https://github.com/ansible/ansible/pull/71824

like image 4
h8n Avatar answered Nov 16 '22 05:11

h8n