unable to run esxcli command with ansible

233 views
Skip to first unread message

Tony Wong

unread,
Jun 1, 2023, 1:54:39 PM6/1/23
to Ansible Project
i got below pb

nametest

  hostsall

  gather_factsno

  vars_files:

    - vcenter_creds.yml

    - vars.yml

 

  tasks:

    - nameEnable SSH service

      vmware_host_service_manager:

        hostname"{{ vcenter_hostname }}"

        username"{{ vcenter_sso_admin }}"

        password"{{ vcenter_sso_pass }}"

        esxi_hostname"{{ inventory_hostname }}"

        validate_certsno

        statepresent

        service_name"TSM-SSH"

      delegate_tolocalhost

 

    - nameEsxcli

      shell:

        cmd"esxcli vm process list"

      delegate_tolocalhost

      registeresxcli_output

 

    - nameDisplay esxcli output

      debug:

        varesxcli_output.stdout_lines






but keep getting error: 




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": []}

Abhijeet Kasurde

unread,
Jun 1, 2023, 2:13:17 PM6/1/23
to ansible...@googlegroups.com
Are you running from the ESXi server? if not then you need to delegate tasks to the ESXi server which has esxcli.


tl;dr -

---
- hosts: localhost
  gather_facts: no
  tasks:
  - name: Start SSH service setting for an ESXi Host in given Cluster
    vmware_host_service_manager:
      hostname: '{{ vcenter_hostname }}'
      username: '{{ vcenter_username }}'
      password: '{{ vcenter_password }}'
      esxi_hostname: '{{ item }}'
      service_name: TSM-SSH
      state: present
    loop: "{{ groups['esxi'] }}"

- hosts: esxi
  tasks:
    - name: Get information about all the VMs
      shell: esxcli vm process list

and

[esxi]
foo.example.com ansible_ssh_user=root

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/3d9dc4ac-0821-494b-b25f-d9e458789a6en%40googlegroups.com.


--
Thanks,
Abhijeet Kasurde

Tony Wong

unread,
Jun 1, 2023, 2:29:41 PM6/1/23
to ansible...@googlegroups.com
my hosts file includes the esxi host

also i am able to run "df -h" without issues

You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/adBLPTrtunI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAFwWkHp4KfgvvyB%2BP3dPkBGsczuAKngpAgCVJCY3SneouO4mmA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages