Initial commit of Ansible inventory playbooks
This commit is contained in:
32
get_esxi_inventory.yml
Normal file
32
get_esxi_inventory.yml
Normal file
@@ -0,0 +1,32 @@
|
||||
---
|
||||
- name: Gather VM inventory from ESXi hypervisor
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
vars:
|
||||
esxi_hostname: "your_esxi_host_ip" # Replace with your ESXi host IP or hostname
|
||||
esxi_username: "root" # Replace with your ESXi username
|
||||
esxi_password: "your_password" # Replace with your ESXi password (use ansible-vault for security)
|
||||
validate_certs: false # Set to true if you have valid certs
|
||||
|
||||
tasks:
|
||||
- name: Gather information about all VMs on the ESXi host
|
||||
community.vmware.vmware_vm_info:
|
||||
hostname: "{{ esxi_hostname }}"
|
||||
username: "{{ esxi_username }}"
|
||||
password: "{{ esxi_password }}"
|
||||
validate_certs: "{{ validate_certs }}"
|
||||
register: vm_info
|
||||
|
||||
- name: Display the VM inventory
|
||||
debug:
|
||||
var: vm_info
|
||||
|
||||
- name: Save VM inventory to file
|
||||
copy:
|
||||
content: "{{ vm_info | to_nice_json }}"
|
||||
dest: /root/esxi_vm_inventory.json
|
||||
|
||||
# Notes:
|
||||
# - Install the community.vmware collection: ansible-galaxy collection install community.vmware
|
||||
# - Ensure pyvmomi is installed on the control machine: pip install pyvmomi
|
||||
# - For production, secure passwords with ansible-vault or use environment variables.
|
||||
Reference in New Issue
Block a user