Ansible-Roles/playbooks/gather_facts_vmware.yml
2026-05-08 22:12:36 +03:00

107 lines
4 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
# Сбор фактов о VMware vSphere инфраструктуре через vCenter API.
# Не использует SSH — всё выполняется локально через pyVmomi.
# Результаты сохраняются в vmware_facts/*.json и используются generate_report.py.
#
# Запуск:
# ansible-playbook -i inventory/prod/vmware/ playbooks/gather_facts_vmware.yml
- name: Сбор фактов VMware vSphere
hosts: vmware_vcenter
gather_facts: false
vars:
vmware_output_dir: "{{ playbook_dir }}/../vmware_facts"
tasks:
- name: Создать директорию для хранения VMware фактов
ansible.builtin.file:
path: "{{ vmware_output_dir }}"
state: directory
mode: "0755"
delegate_to: localhost
- name: Получить информацию о кластерах датацентра
community.vmware.vmware_cluster_info:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: "{{ vcenter_validate_certs }}"
datacenter: "{{ vcenter_datacenter }}"
register: _cluster_info
delegate_to: localhost
failed_when: false
- name: Получить системные факты ESXi-гипервизоров
community.vmware.vmware_host_facts:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: "{{ vcenter_validate_certs }}"
esxi_hostname: "{{ item }}"
register: _esxi_facts
loop: "{{ vcenter_esxi_hosts }}"
delegate_to: localhost
failed_when: false
- name: Получить список всех виртуальных машин
community.vmware.vmware_vm_info:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: "{{ vcenter_validate_certs }}"
vm_type: all
register: _vm_info
delegate_to: localhost
failed_when: false
- name: Получить информацию о датасторах
community.vmware.vmware_datastore_info:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: "{{ vcenter_validate_certs }}"
datacenter: "{{ vcenter_datacenter }}"
register: _datastore_info
delegate_to: localhost
failed_when: false
- name: Сохранить факты кластера в JSON
ansible.builtin.copy:
content: "{{ _cluster_info.clusters | default({}) | to_nice_json }}"
dest: "{{ vmware_output_dir }}/cluster_{{ vcenter_cluster }}.json"
mode: "0644"
delegate_to: localhost
when: _cluster_info is not failed
- name: Сохранить факты ESXi-гипервизоров в JSON
ansible.builtin.copy:
content: >-
{{
item.ansible_facts
| combine({'esxi_hostname': item.item})
| to_nice_json
}}
dest: "{{ vmware_output_dir }}/esxi_{{ item.item }}.json"
mode: "0644"
loop: "{{ _esxi_facts.results }}"
delegate_to: localhost
when:
- item.ansible_facts is defined
- item is not failed
- name: Сохранить список виртуальных машин в JSON
ansible.builtin.copy:
content: "{{ _vm_info.virtual_machines | default([]) | to_nice_json }}"
dest: "{{ vmware_output_dir }}/vms.json"
mode: "0644"
delegate_to: localhost
when: _vm_info is not failed
- name: Сохранить информацию о датасторах в JSON
ansible.builtin.copy:
content: "{{ _datastore_info.datastores | default([]) | to_nice_json }}"
dest: "{{ vmware_output_dir }}/datastores.json"
mode: "0644"
delegate_to: localhost
when: _datastore_info is not failed