18

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?

2
  • Mind the but may be elsewhere in the file depending on the exact syntax problem. of Ansible here. I do suspect your issue lies indeed elsewhere, are you sure of your line breaks, your indents? Feb 12, 2021 at 20:39
  • 4
    You should triple check the ansible version you have reported. Because the only way I could reproduce your exact error message is by runnig a similar task in ansible lower than 2.10 (I used 2.9.0 in a vritualenv for my test). I have also tested with the exact version you reported and it works without any warnings or error. If you run an older version than 2.10, you can't use the full collection name and the module name is simply shell. Note that shell will work in both ansible pre and post 2.10 if you need compatibility between versions. Feb 12, 2021 at 22:38

3 Answers 3

21

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
2
  • 2
    But why do FQCNs not work in some cases? Apr 20, 2022 at 6:27
  • 1
    @stackprotector it's a bug on some ansible versions, see h8n answer
    – kaios
    Aug 25, 2022 at 12:45
10

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

1
  • 1
    This fixed it for me. The confusing thing was that the version of Ansible that is in apt is 2.9.6 which is end of life. I removed that and installed the latest version via pip and it works fine now. Aug 7, 2022 at 12:58
1

Try putting "" around your command i.e.

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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.