« Ansible : VMWare » : différence entre les versions
Page créée avec « = Utilisation de la collection "community" = https://github.com/ansible-collections/community.vmware La collection community pour VMWare contient un ensemble de rôles pe... » |
(Aucune différence)
|
Version du 2 octobre 2020 à 14:52
Utilisation de la collection "community"
https://github.com/ansible-collections/community.vmware
La collection community pour VMWare contient un ensemble de rôles permettant diverses opérations. Celle-ci est la "vieille" collection; la collection https://github.com/ansible-collections/vmware.vmware_rest est disponible à partir de Vcenter 7.0 et permet de se passer d'un paquet de dépendances.
Install prérequis
<source> sudo python3 -m pip install --upgrade pip setuptools pip install --upgrade git+https://github.com/vmware/vsphere-automation-sdk-python.git python3 -m pip install --upgrade git+https://github.com/vmware/vsphere-automation-sdk-python.git </source>
Utilisation
Je part ici sur une utilisation basique avec un ESXi "StandAlone" (donc sans VCenter).
Récupération d'informations sur une vm
<source lang='yaml'> --- - hosts: all
become: True
collections: - community.vmware
tasks:
- name: Gather some information about a guest using MoID
community.vmware.vmware_guest_info:
hostname: "esx.ju.lab"
username: "justine"
password: "mdp"
validate_certs: no
datacenter: "ha-datacenter" #ha-datacenter est la valeur à utiliser pour un ESX standalone
name: "lamp"
schema: "vsphere" #Schéma de sortie des infos. Peut être à summary
properties: ["config.hardware.memoryMB", "guest.disk", "overallStatus"] #Uniquement avec schema=vsphere
delegate_to: localhost
register: vm_moid_info
- name: Affiche
debug:
var: vm_moid_info
</source>
Donne quelque chose comme ça:
<source lang="json"> ok: [127.0.0.1] => {
"vm_moid_info": {
"changed": false,
"failed": false,
"instance": {
"config": {
"hardware": {
"memoryMB": 2048
}
},
"guest": {
"disk": [
{
"_vimtype": "vim.vm.GuestInfo.DiskInfo",
"capacity": 40130502656,
"diskPath": "/",
"filesystemType": null,
"freeSpace": 34717876224,
"mappings": []
},
{
"_vimtype": "vim.vm.GuestInfo.DiskInfo",
"capacity": 40130502656,
"diskPath": "/var/www/clients/client6/web9/log",
"filesystemType": null,
"freeSpace": 34717876224,
"mappings": []
},
{
"_vimtype": "vim.vm.GuestInfo.DiskInfo",
"capacity": 40130502656,
"diskPath": "/var/www/clients/client7/web7/log",
"filesystemType": null,
"freeSpace": 34717876224,
"mappings": []
},
{
"_vimtype": "vim.vm.GuestInfo.DiskInfo",
"capacity": 40130502656,
"diskPath": "/var/www/clients/client7/web6/log",
"filesystemType": null,
"freeSpace": 34717876224,
"mappings": []
},
{
"_vimtype": "vim.vm.GuestInfo.DiskInfo",
"capacity": 40130502656,
"diskPath": "/var/www/clients/client6/web5/log",
"filesystemType": null,
"freeSpace": 34717876224,
"mappings": []
},
{
"_vimtype": "vim.vm.GuestInfo.DiskInfo",
"capacity": 40130502656,
"diskPath": "/var/www/clients/client5/web4/log",
"filesystemType": null,
"freeSpace": 34717876224,
"mappings": []
},
{
"_vimtype": "vim.vm.GuestInfo.DiskInfo",
"capacity": 40130502656,
"diskPath": "/var/www/clients/client4/web1/log",
"filesystemType": null,
"freeSpace": 34717876224,
"mappings": []
},
{
"_vimtype": "vim.vm.GuestInfo.DiskInfo",
"capacity": 40130502656,
"diskPath": "/var/www/clients/client3/web3/log",
"filesystemType": null,
"freeSpace": 34717876224,
"mappings": []
},
{
"_vimtype": "vim.vm.GuestInfo.DiskInfo",
"capacity": 238787584,
"diskPath": "/boot",
"filesystemType": null,
"freeSpace": 189932544,
"mappings": []
}
]
},
"overallStatus": "green"
}
}
} </source>