Skip to content

Commit cbc37f8

Browse files
committed
Add get_all playbooks
Signed-off-by: Abhijeet Kasurde <[email protected]>
1 parent bccecd6 commit cbc37f8

10 files changed

+185
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.retry
22
ansible.cfg
33
inventory
4+
.idea

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ Examples
1616

1717
Example Ansible playbook to manage VMware using HTTP APIs:
1818

19-
- [Get a list of all ESXi hosts available in the given datacenter](../get_all_hosts.yml)
19+
- [Get a list of all Datacenters available](../get_all_datacenters.yml)
20+
- [Get a list of all Clusters available](../get_all_clusters.yml)
21+
- [Get a list of all ESXi hosts available](../get_all_hosts.yml)
22+
- [Get a list of all Datastores available](../get_all_datastores.yml)
23+
- [Get a list of all Network available](../get_all_networks.yml)
24+
- [Get a list of all Virtual machine available](../get_all_vms.yml)
25+
- [Get information about the given Cluster](../get_cluster_info.yml)
2026

2127

2228
Caveats

get_all_clusters.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
- name: Gather all clusters for vCenter
3+
gather_facts: no
4+
vars_files:
5+
- vcenter_vars.yml
6+
hosts: localhost
7+
tasks:
8+
- name: Login task
9+
include_tasks: login.yml
10+
11+
- name: Get clusters from vCenter
12+
uri:
13+
url: https://{{ vcenter_server }}/rest/vcenter/cluster
14+
force_basic_auth: yes
15+
validate_certs: "{{ validate_certs }}"
16+
headers:
17+
Cookie: "{{ login.set_cookie }}"
18+
register: vClusters
19+
20+
- name: Print names of clusters in the given vCenter
21+
debug:
22+
msg: "{{ item.name }}"
23+
with_items: "{{ vClusters.json.value }}"

get_all_datacenters.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
- name: Gather all datacenters for vCenter
3+
gather_facts: no
4+
vars_files:
5+
- vcenter_vars.yml
6+
hosts: localhost
7+
tasks:
8+
- name: Login task
9+
include_tasks: login.yml
10+
11+
- name: Get datacenters from vCenter
12+
uri:
13+
url: https://{{ vcenter_server }}/rest/vcenter/datacenter
14+
force_basic_auth: yes
15+
validate_certs: "{{ validate_certs }}"
16+
headers:
17+
Cookie: "{{ login.set_cookie }}"
18+
register: vDatacenters
19+
20+
- name: Print names of datacenters in the given vCenter
21+
debug:
22+
msg: "{{ item.name }}"
23+
with_items: "{{ vDatacenters.json.value }}"

get_all_datastores.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
- name: Gather all datastores for vCenter
3+
gather_facts: no
4+
vars_files:
5+
- vcenter_vars.yml
6+
hosts: localhost
7+
tasks:
8+
- name: Login task
9+
include_tasks: login.yml
10+
11+
- name: Get datastores from vCenter
12+
uri:
13+
url: https://{{ vcenter_server }}/rest/vcenter/datastore
14+
force_basic_auth: yes
15+
validate_certs: "{{ validate_certs }}"
16+
headers:
17+
Cookie: "{{ login.set_cookie }}"
18+
register: vdatastores
19+
20+
- name: Print names of datastores in the given vCenter
21+
debug:
22+
msg: "{{ item.name }}"
23+
with_items: "{{ vdatastores.json.value }}"

get_all_folders.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
- name: Gather all folders for vCenter
3+
gather_facts: no
4+
vars_files:
5+
- vcenter_vars.yml
6+
hosts: localhost
7+
tasks:
8+
- name: Login task
9+
include_tasks: login.yml
10+
11+
- name: Get folders from vCenter
12+
uri:
13+
url: https://{{ vcenter_server }}/rest/vcenter/folder
14+
force_basic_auth: yes
15+
validate_certs: "{{ validate_certs }}"
16+
headers:
17+
Cookie: "{{ login.set_cookie }}"
18+
register: vfolders
19+
20+
- name: Print names of folders in the given vCenter
21+
debug:
22+
msg: "{{ item.name }}"
23+
with_items: "{{ vfolders.json.value }}"

get_all_networks.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
- name: Gather all networks for vCenter
3+
gather_facts: no
4+
vars_files:
5+
- vcenter_vars.yml
6+
hosts: localhost
7+
tasks:
8+
- name: Login task
9+
include_tasks: login.yml
10+
11+
- name: Get networks from vCenter
12+
uri:
13+
url: https://{{ vcenter_server }}/rest/vcenter/network
14+
force_basic_auth: yes
15+
validate_certs: "{{ validate_certs }}"
16+
headers:
17+
Cookie: "{{ login.set_cookie }}"
18+
register: vnetworks
19+
20+
- name: Print names of networks in the given vCenter
21+
debug:
22+
msg: "{{ item.name }}"
23+
with_items: "{{ vnetworks.json.value }}"

get_all_vms.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
- name: Gather all VMs for vCenter
3+
gather_facts: no
4+
vars_files:
5+
- vcenter_vars.yml
6+
hosts: localhost
7+
tasks:
8+
- name: Login task
9+
include_tasks: login.yml
10+
11+
- name: Get VMs from vCenter
12+
uri:
13+
url: https://{{ vcenter_server }}/rest/vcenter/vm
14+
force_basic_auth: yes
15+
validate_certs: "{{ validate_certs }}"
16+
headers:
17+
Cookie: "{{ login.set_cookie }}"
18+
register: vVMs
19+
20+
- name: Print names of VMs in the given vCenter
21+
debug:
22+
msg: "{{ item.name }}"
23+
with_items: "{{ vVMs.json.value }}"

get_cluster_info.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
- name: Gather cluster information for vCenter
3+
gather_facts: no
4+
vars_files:
5+
- vcenter_vars.yml
6+
hosts: localhost
7+
tasks:
8+
- name: Login task
9+
include_tasks: login.yml
10+
11+
- name: Get clusters from vCenter
12+
uri:
13+
url: https://{{ vcenter_server }}/rest/vcenter/cluster
14+
force_basic_auth: yes
15+
validate_certs: "{{ validate_certs }}"
16+
headers:
17+
Cookie: "{{ login.set_cookie }}"
18+
register: vClusters
19+
20+
- name: Print names of clusters in the given vCenter
21+
set_fact:
22+
cluster_id: "{{ item.cluster }}"
23+
vars:
24+
cluster_id_query: "[?name == '{{ cluster_name }}']"
25+
with_items: "{{ vClusters.json.value }}"
26+
27+
- name: Get cluster info from vCenter
28+
uri:
29+
url: https://{{ vcenter_server }}/rest/vcenter/cluster/{{ cluster_id }}
30+
force_basic_auth: yes
31+
validate_certs: "{{ validate_certs }}"
32+
headers:
33+
Cookie: "{{ login.set_cookie }}"
34+
register: vCluster_info
35+
36+
- name: Print cluster's resource pool name
37+
debug:
38+
msg: "{{ vCluster_info.json.value['resource_pool'] }}"

vcenter_vars.yml

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99

1010
# VMware object related details
1111
- datacenter: DC0
12+
- cluster_name: DC0_C1

0 commit comments

Comments
 (0)