# unable to run esxcli command with ansible

**URL:** <https://forum.ansible.com/t/unable-to-run-esxcli-command-with-ansible/38044>\
**Category:** Ansible Project\
**Created:** [June 1, 2023, 5:54pm UTC](https://forum.ansible.com/t/unable-to-run-esxcli-command-with-ansible/38044 "2023-06-01T17:54:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [June 1, 2023, 5:54pm UTC](https://forum.ansible.com/t/unable-to-run-esxcli-command-with-ansible/38044/1 "2023-06-01T17:54:39Z")

</div>

i got below pb

- name: test

hosts: all

gather\_facts: no

vars\_files:

- vcenter\_creds.yml

- vars.yml

tasks:

- name: Enable SSH service

vmware\_host\_service\_manager:

hostname: “{{ vcenter\_hostname }}”

username: “{{ vcenter\_sso\_admin }}”

password: “{{ vcenter\_sso\_pass }}”

esxi\_hostname: “{{ inventory\_hostname }}”

validate\_certs: no

state: present

service\_name: “TSM-SSH”

delegate\_to: localhost

- name: Esxcli

shell:

cmd: “esxcli vm process list”

delegate\_to: localhost

register: esxcli\_output

- name: Display esxcli output

debug:

var: esxcli\_output.stdout\_lines

but keep getting error:

![](https://mail.google.com/mail/u/0/images/cleardot.gif)

fatal: [xxxxxxxxx → localhost]: FAILED! =\> {“changed”: true, “cmd”: “esxcli”, “delta”: “0:00:00.009652”, “end”: “2023-06-01 10:49:02.878893”, “msg”: “non-zero return code”, “rc”: 127, “start”: “2023-06-01 10:49:02.869241”, “stderr”: “/bin/sh: esxcli: command not found”, “stderr\_lines”: [“/bin/sh: esxcli: command not found”], “stdout”: “”, “stdout\_lines”: }

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [June 1, 2023, 6:12pm UTC](https://forum.ansible.com/t/unable-to-run-esxcli-command-with-ansible/38044/2 "2023-06-01T18:12:51Z")

</div>

Are you running from the ESXi server? if not then you need to delegate tasks to the ESXi server which has esxcli.

Please see [https://medium.com/@AbhijeetKasurde/ansible-automating-esxcli-using-shell-module-6f691a551bca](https://medium.com/@AbhijeetKasurde/ansible-automating-esxcli-using-shell-module-6f691a551bca)

tl;dr -

---

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [June 1, 2023, 6:29pm UTC](https://forum.ansible.com/t/unable-to-run-esxcli-command-with-ansible/38044/3 "2023-06-01T18:29:17Z")

</div>

my hosts file includes the esxi host

also i am able to run “df -h” without issues
