# Encrypting credentials within the vmware inventory file

**URL:** <https://forum.ansible.com/t/encrypting-credentials-within-the-vmware-inventory-file/37182>\
**Category:** Ansible Project\
**Tags:** vmware\
**Created:** [October 6, 2022, 4:43am UTC](https://forum.ansible.com/t/encrypting-credentials-within-the-vmware-inventory-file/37182 "2022-10-06T04:43:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tyderian](https://avatars.discourse-cdn.com/v4/letter/t/58956e/32.png) [@Tyderian](https://forum.ansible.com/u/Tyderian)\
**Post date:** [October 6, 2022, 4:43am UTC](https://forum.ansible.com/t/encrypting-credentials-within-the-vmware-inventory-file/37182/1 "2022-10-06T04:43:52Z")

</div>

Hi everyone, first time post here!

I’ve setup the VMware inventory plugin for Ansible, and have had success in retrieving inventory results both with plaintext credentials in the .vmware.yml file and with the file fully encrypted with ansible-vault.

Unfortunately storing the credentials in plain text is not viable, neither is encrypting the whole file.  
After confirming that both the username and password fields in this inventory configuration file can be encrypted using ansible-vault, I attempted to do so - but I have been unable to get it to work.

Is there a particular trick to this?

The process I have followed so far is this:

1. encrypt the password string: `ansible-vault encrypt_string`
2. Paste the output of this into the .vmware.yml inventory file:

plugin: vmware\_vm\_inventory  
strict: False  
hostname: [vcenter.fqdn.com](http://vcenter.fqdn.com)  
username: [svcaccount@fqdn.com](mailto:svcaccount@fqdn.com)  
password: !vault |  
$ANSIBLE\_VAULT;1.1;AES256  
5 lines of digits…  
validate\_certs: False  
with\_tags: True

properties:

- ‘config.name’

- ‘config.guestId’

- ‘guest.ipAddress’

- ‘guest.hostName’

- ‘guest.toolsStatus’

- ‘summary.runtime.powerState’  
hostnames:

- ‘config.name’  
filters:

- 'summary.runtime.powerState == ‘poweredOn’

- 'guest.guestId == ‘rhel8\_64Guest’ or 'config.guestId == ‘rhel9\_64Guest’ or config.guestId == ‘ubuntu64Guest’

1. Run ansible-inventory to test:  
ansible-inventory --list -i inventory.vmware.yml --ask-vault-pass

The command fails with an error “Unable to logon to vCenter or ESXi API at xxxx.xxx.xxx:43 as xxxx: Cannot complete login due to an incorrect user name or password”.

If I change the encrypted password value to plaintext it works. If I encrypt the entire file it works.

Can anyone see anything that I am doing wrong?

Thank you!

Adam
