# ESXi upgrade using ansible playbook

**URL:** <https://forum.ansible.com/t/esxi-upgrade-using-ansible-playbook/5085>\
**Category:** Get Help\
**Tags:** vmware\
**Created:** [April 23, 2024, 9:33am UTC](https://forum.ansible.com/t/esxi-upgrade-using-ansible-playbook/5085 "2024-04-23T09:33:00Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![kkrishnasamy01](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kkrishnasamy01/32/1804_2.png) [@kkrishnasamy01](https://forum.ansible.com/u/kkrishnasamy01)\
**Post date:** [April 23, 2024, 9:33am UTC](https://forum.ansible.com/t/esxi-upgrade-using-ansible-playbook/5085/1 "2024-04-23T09:33:00Z")

</div>

Getting an error while patch the esxi host. Please help…

fatal: [localhost]: FAILED! =\> {“changed”: false, “cmd”: “esxcli software vib install -d /vmfs/volumes/datastore\_10.115.81.40/VMware-ESXi-7.0U3n-21930508-depot.zip”, “msg”: “[Errno 2] No such file or directory: b’esxcli’”, “rc”: 2, “stderr”: “”, “stderr\_lines”: , “stdout”: “”, “stdout\_lines”: }

* * *

tasks:

- name: ESXi enter maintenance  
register: status  
vmware\_maintenancemode:  
hostname: “{{ vcenter\_hostname }}”  
username: “{{ vcenter\_username }}”  
password: “{{ vcenter\_password }}”  
esxi\_hostname: “{{ esxi\_ip\_address }}”  
#esxi\_password: “{{ esxi\_passwd }}”  
evacuate: yes  
validate\_certs: no  
timeout: 3600  
state: present  
delegate\_to: localhost

- debug: var=status.msg

- name: ESXi Install Update  
command: “esxcli software vib install -d /vmfs/volumes/datastore\_10.115.81.40/VMware-ESXi-7.0U3n-21930508-depot.zip”

- debug:  
msg: vib

* * *

---

<div class="post-metadata">

**Author:** ![kurokobo](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kurokobo/32/182_2.png) [@kurokobo](https://forum.ansible.com/u/kurokobo)\
**Post date:** [April 23, 2024, 12:17pm UTC](https://forum.ansible.com/t/esxi-upgrade-using-ansible-playbook/5085/2 "2024-04-23T12:17:39Z")

</div>

> [@kkrishnasamy01](#):
>
> fatal: [localhost]: FAILED!

This `[localhost]` means that the task is invoked to `localhost` instead of your ESXi. You should specify the target node of this task to your ESXi, by changing `hosts` on your playbook or `delegate_to` on the task.

---

<div class="post-metadata">

**Author:** ![kkrishnasamy01](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kkrishnasamy01/32/1804_2.png) [@kkrishnasamy01](https://forum.ansible.com/u/kkrishnasamy01)\
**Post date:** [April 23, 2024, 2:01pm UTC](https://forum.ansible.com/t/esxi-upgrade-using-ansible-playbook/5085/3 "2024-04-23T14:01:32Z")

</div>

i tried changing local host to my esxi host ip x.x.x.x but different error now

## TASK [ESXi enter maintenance] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* fatal: [localhost → x.x.x.x]: UNREACHABLE! =\> {“changed”: false, “msg”: “Failed to connect to the host via ssh: root@x.x.x.x: Permission denied (publickey,keyboard-interactive).”, “unreachable”: true}

tasks:

- name: ESXi enter maintenance  
register: status  
vmware\_maintenancemode:  
hostname: “{{ vcenter\_hostname }}”  
username: “{{ vcenter\_username }}”  
password: “{{ vcenter\_password }}”  
esxi\_hostname: “{{ esxi\_ip\_address }}”  
#esxi\_password: “{{ esxi\_passwd }}”  
evacuate: yes  
validate\_certs: no  
timeout: 3600  
state: present  
delegate\_to: x.x.x.x

- debug: var=status.msg

- name: ESXi Install Update  
command: “esxcli software vib install -d /vmfs/volumes/datastore\_x.x.x.x/VMware-ESXi-7.0U3n-21930508-depot.zip”

* * *

---

<div class="post-metadata">

**Author:** ![kurokobo](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kurokobo/32/182_2.png) [@kurokobo](https://forum.ansible.com/u/kurokobo)\
**Post date:** [April 23, 2024, 2:21pm UTC](https://forum.ansible.com/t/esxi-upgrade-using-ansible-playbook/5085/4 "2024-04-23T14:21:22Z")

</div>

The `delegate_to: localhost` for the task `ESXi enter maintenance` should not be changed. My comment is for the task `ESXi Install Update`.

Also you have to enable SSH service on ESXi.  
To enable SSH service, you can do it by hand or use [community.vmware.vmware\_host\_service\_manager](https://docs.ansible.com/ansible/latest/collections/community/vmware/vmware_host_service_manager_module.html).

---

<div class="post-metadata">

**Author:** ![kkrishnasamy01](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kkrishnasamy01/32/1804_2.png) [@kkrishnasamy01](https://forum.ansible.com/u/kkrishnasamy01)\
**Post date:** [April 23, 2024, 3:40pm UTC](https://forum.ansible.com/t/esxi-upgrade-using-ansible-playbook/5085/5 "2024-04-23T15:40:48Z")

</div>

After SSH enable via play book but still below error.  
i could see host going into MM and ssh also looks good.

* * *

TASK [ESXi Install Update] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [localhost]: FAILED! =\> {“changed”: false, “cmd”: “esxcli software vib install -d /vmfs/volumes/datastore\_10.115.81.40/VMware-ESXi-7.0U3n-21930508-depot.zip”, “msg”: “[Errno 2] No such file or directory: b’esxcli’”, “rc”: 2, “stderr”: “”, “stderr\_lines”: , “stdout”: “”, “stdout\_lines”: }

* * *

Please find my play book mentioned below.,

* * *

- hosts: localhost  
gather\_facts: no

---

<div class="post-metadata">

**Author:** ![kurokobo](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kurokobo/32/182_2.png) [@kurokobo](https://forum.ansible.com/u/kurokobo)\
**Post date:** [April 23, 2024, 3:47pm UTC](https://forum.ansible.com/t/esxi-upgrade-using-ansible-playbook/5085/6 "2024-04-23T15:47:38Z")

</div>

Please read my comment above again 😞

> [@ESXi upgrade using ansible playbook](http://forum.ansible.com/t/esxi-upgrade-using-ansible-playbook/5085/2):
>
> This [localhost] means that the task is invoked to localhost instead of your ESXi. You should specify the target node of this task to your ESXi, by changing hosts on your playbook or delegate\_to on the task.

---

<div class="post-metadata">

**Author:** ![kurokobo](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kurokobo/32/182_2.png) [@kurokobo](https://forum.ansible.com/u/kurokobo)\
**Post date:** [April 23, 2024, 4:09pm UTC](https://forum.ansible.com/t/esxi-upgrade-using-ansible-playbook/5085/7 "2024-04-23T16:09:41Z")

</div>

The appropriate target node for each task depends on the modules used in the task.

The `delegate_to` is used when you want to change the target node of the task from the target nodes which specified by the `hosts` in the playbook.

---

<div class="post-metadata">

**Author:** ![kkrishnasamy01](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kkrishnasamy01/32/1804_2.png) [@kkrishnasamy01](https://forum.ansible.com/u/kkrishnasamy01)\
**Post date:** [April 24, 2024, 3:49am UTC](https://forum.ansible.com/t/esxi-upgrade-using-ansible-playbook/5085/8 "2024-04-24T03:49:58Z")

</div>

Nope still not working …getting below error

fatal: [localhost]: FAILED! =\> {“changed”: true, “cmd”: “/bin/esxcli software vib install -d /vmfs/volumes/datastore\_x.x.x.x/VMware-ESXi-7.0U3n-21930508-depot.zip”, “delta”: “0:00:00.010569”, “end”: “2024-04-24 09:17:58.494133”, “msg”: “non-zero return code”, “rc”: 127, “start”: “2024-04-24 09:17:58.483564”, “stderr”: “/bin/sh: 1: /bin/esxcli: not found”, “stderr\_lines”: [“/bin/sh: 1: /bin/esxcli: not found”], “stdout”: “”, “stdout\_lines”: }

---

<div class="post-metadata">

**Author:** ![kurokobo](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kurokobo/32/182_2.png) [@kurokobo](https://forum.ansible.com/u/kurokobo)\
**Post date:** [April 24, 2024, 4:32am UTC](https://forum.ansible.com/t/esxi-upgrade-using-ansible-playbook/5085/9 "2024-04-24T04:32:37Z")

</div>

> [@kkrishnasamy01](#):
>
> fatal: [localhost]: FAILED!

Hey have you read my comment? My English may have been poor, but I do not want to repeat the same comments any more.

---

<div class="post-metadata">

**Author:** ![kkrishnasamy01](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kkrishnasamy01/32/1804_2.png) [@kkrishnasamy01](https://forum.ansible.com/u/kkrishnasamy01)\
**Post date:** [April 24, 2024, 4:48am UTC](https://forum.ansible.com/t/esxi-upgrade-using-ansible-playbook/5085/10 "2024-04-24T04:48:44Z")

</div>

hi…Please read the error once again …the error reports something different not for the localhost issue. I tired all the steps … If you have any idea please reply or else ignore.

msg": “[Errno 2] No such file or directory: b’esxcli’”, “rc”: 2, “stderr”: “”, “stderr\_lines”: , “stdout”: “”, “stdout\_lines”: }

---

<div class="post-metadata">

**Author:** ![kurokobo](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kurokobo/32/182_2.png) [@kurokobo](https://forum.ansible.com/u/kurokobo)\
**Post date:** [April 24, 2024, 4:54am UTC](https://forum.ansible.com/t/esxi-upgrade-using-ansible-playbook/5085/11 "2024-04-24T04:54:03Z")

</div>

From the beginning, before I care about the content of the error message, I see the problem with `[localhost]` next to `fatal:`:

 ![image](https://us1.discourse-cdn.com/ansible/original/2X/4/4bcc9b4052c57057998fa0a539a4ff99e7d33e55.png)

This means that your task is trying to run `esxicli` on `localhost` with SSH or local connection.  
I don’t think this is correct for your task, and that’s why I repeatedly mentioned `hosts` and `delegate_to`.

If the `No such file or directory` error is truly came from ESXi, the line `fatal` should start with the ESXi hostname or IP address as follows:

```bash
fatal: [<ESXI_HOSTNAME_OR_IP_ADDRESS>]: FAILED! => {“changed”: true, ...

```

or if the task is delegated to ESXi,

```bash
fatal: [localhost -> <ESXI_HOSTNAME_OR_IP_ADDRESS>]: FAILED! => {“changed”: true, ...

```

---

<div class="post-metadata">

**Author:** ![mariolenz](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mariolenz/32/108_2.png) [@mariolenz](https://forum.ansible.com/u/mariolenz)\
**Post date:** [April 24, 2024, 3:46pm UTC](https://forum.ansible.com/t/esxi-upgrade-using-ansible-playbook/5085/12 "2024-04-24T15:46:06Z")

</div>

I’ve started with ESX 2.5 nearly 20 years ago and I’m also maintaining `community.vmware`.

That said, we’re using this collection heavily at work. But I would _never_ use it to update ESXi hosts. I don’t think Ansible is the right tool to do this. Use vCenter Lifecycle Manager for this.

---

<div class="post-metadata">

**Author:** ![mariolenz](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mariolenz/32/108_2.png) [@mariolenz](https://forum.ansible.com/u/mariolenz)\
**Post date:** [April 25, 2024, 6:37am UTC](https://forum.ansible.com/t/esxi-upgrade-using-ansible-playbook/5085/13 "2024-04-25T06:37:30Z")

</div>

If you want to run esxcli commands, maybe you should have a look at [Get-EsxCli](https://developer.vmware.com/docs/powercli/latest/vmware.vimautomation.core/commands/get-esxcli/). We use PowerCLI a lot where Ansible doesn’t feel like the right tool (or `community.vmware` simply lacks the functionality we need).

---

<div class="post-metadata">

**Author:** ![vuser](https://avatars.discourse-cdn.com/v4/letter/v/41988e/32.png) [@vuser](https://forum.ansible.com/u/vuser)\
**Post date:** [April 8, 2025, 6:47pm UTC](https://forum.ansible.com/t/esxi-upgrade-using-ansible-playbook/5085/14 "2025-04-08T18:47:20Z")

</div>

Hi Mariolenz,  
I know this is an older post…please bare with me. I wholehartedly agree about using vCenter Lifecycle Manager to update; however, any way to trigger the cluster remediation action from ansible? Im looking to integrate our ticketting system into ansible and essentially have the following process kick off:

1. admin submits a scheduled change request
2. on approval, connect to ansible aap and schedule cluster remediation
3. collect failure output

I am very new to ansible and just now getting familiar with community.vmware module. I have an idea on how to complete what I want using PowerCLI but I would like to centralize automations into AAP.

Is this even possible or should i just go the PowerCLI route and just piece a hybrid of the two?

---

<div class="post-metadata">

**Author:** ![mariolenz](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mariolenz/32/108_2.png) [@mariolenz](https://forum.ansible.com/u/mariolenz)\
**Post date:** [April 9, 2025, 5:37pm UTC](https://forum.ansible.com/t/esxi-upgrade-using-ansible-playbook/5085/15 "2025-04-09T17:37:04Z")

</div>

@vuser ATM it’s not possibly. I haven’t figured out yet how to control vCenter Lifecycle Manager stuff through the API, which I would need to implement this.

Anyway, when I do I think managing cluster images would be more important than triggering an update.

So if you want to have a quick solution, use another way like PowerCLI or something similar. I don’t know when we’ll be able to implement this.

BTW If you’re new to ansible and `community.vmware`, I suggest to also have a look at [vmware.vmware](https://galaxy.ansible.com/ui/repo/published/vmware/vmware/) and [vmware.vmware\_rest](https://galaxy.ansible.com/ui/repo/published/vmware/vmware_rest/). I don’t think those collections have a solution for your problem, but they might provide some interesting modules to fix other problems you might run into.

Especially have a look at `vmware.vmware` since I’ve started to deprecate modules in `community.vmware` in favour of ones in this collection 😉

---

<div class="post-metadata">

**Author:** ![Ulises\_Vasquez](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ulises_vasquez/32/7759_2.png) [@Ulises\_Vasquez](https://forum.ansible.com/u/Ulises_Vasquez)\
**Post date:** [April 10, 2025, 5:47am UTC](https://forum.ansible.com/t/esxi-upgrade-using-ansible-playbook/5085/16 "2025-04-10T05:47:13Z")

</div>

@mariolenz hey there! thank you for the reply. I did check out the other two but its as you said. By the way thank you for the work you and the others put into this. So far im loving the learning experience and currently tearing my hair out with the vmware\_guest module but in all im enjoying it lol.

Im thinking I might have some luck just executing a powercli script from anisible. This will probably be a good Friday task.

Thanks again for the reply, much appreciated! take care.

---

<div class="post-metadata">

**Author:** ![sven](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sven/32/4237_2.png) [@sven](https://forum.ansible.com/u/sven)\
**Post date:** [May 28, 2025, 10:40am UTC](https://forum.ansible.com/t/esxi-upgrade-using-ansible-playbook/5085/17 "2025-05-28T10:40:25Z")

</div>

Actually, this is possible to do, we’re using this for 2,5 years to set/update the LCM image and apply those changes to each ESXi Hosts.  
The API Calls are a real mess and for setting an Image you’ve to make at least 10-20 API Calls.
