- name: get vhosts
  command: rabbitmqctl list_vhosts
  register: vhosts
  changed_when: false

by issuing

sudo ansible-playbook file.yml

results in:

TASK [030.sensu : get vhosts] **************************************************
fatal: [IP]: FAILED! => {"changed": false, "cmd": "rabbitmqctl list_vhosts", 
"failed": true, "msg": "[Errno 2] No such file or directory", "rc": 2}

while this error does not occur if ansible is run on the system itself.


1. Is the rc command missing?

Issuing rc both locally as remotely results in:

bash: rc: command not found...

If this would be an issue then running the playbook locally would fail as well.

2. Is this a known issue?

Querying "No such file or directory" rc ansible centos on the internet resulted in this Q&A.

According to one of the answers the issue is caused by command. Using shell instead would solve the problem. The solution was tried, but it did not solve the issue.


The return from ansible is json. Pretty printed:

  "changed": false,
  "cmd": "rabbitmqctl list_vhosts",
  "failed": true,
  "msg": "[Errno 2] No such file or directory",
  "rc": 2

You'll note msg contains "[Errno 2] No such file or directory". Instead rc is the return (exit) code, '2' in your case, of the command rabbitmqctl list_vhosts.

In shell (bash/sh/whatever) run rabbitmqctl. You may not have rabbitmqctl installed. Or, as EEAA rightfully suggests, it is not in $PATH. On some distros (Debian/Ubuntu) /usr/sbin is not included in normal users' path, but it is included for root.


Adding become: true to the file.yml:

- hosts:
    - <enter-IP>
    - 030.sensu
  become: true

and running it by issuing ansible-playbook file.yml solved the issue as well.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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