Skip to content

Commit

Permalink
Add info role
Browse files Browse the repository at this point in the history
Signed-off-by: Ondra Machacek <omachace@redhat.com>
  • Loading branch information
machacekondra committed Apr 23, 2024
1 parent ecee0a2 commit 782dd38
Show file tree
Hide file tree
Showing 15 changed files with 294 additions and 0 deletions.
1 change: 1 addition & 0 deletions galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ build_ignore:
dependencies: {
"vmware.vmware_rest": ">=2.3.1",
"community.vmware": ">=4.2.0",
"kubernetes.core": ">=3.0.1",
}
6 changes: 6 additions & 0 deletions playbooks/info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- name: Gather infomation about VMware
hosts: all
gather_facts: false

roles:
- role: cloud.vmware_ops.info
79 changes: 79 additions & 0 deletions roles/info/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Gather information from vcenter

A role that gather information from vcenter.

## Requirements

N/A

## Role Variables
### Auth
- **info_username**:
- The vSphere vCenter username.

- **info_password**:
- The vSphere vCenter password.

- **info_hostname**:
- The hostname or IP address of the vSphere vCenter.

- **info_validate_certs**
- Allows connection when SSL certificates are not valid. Set to false when certificates are not trusted.

### Appliance
- **info_appliance_gather**
- Define the sections of the appliance to gather. By default we gather all appliance information.

- **info_appliance_file**
- File where to store the gathered data. Default is `/tmp/appliance-{random}`

### License
- **info_license_file**
- File where to store the gathered data. Default is `/tmp/appliance-{random}`

### Cluster
- **info_cluster_file**
- File where to store the gathered data. Default is `/tmp/appliance-{random}`

### Storage
- **info_storage_file**
- File where to store the gathered data. Default is `/tmp/appliance-{random}`

### Guest
- **info_guest_file**
- File where to store the gathered data. Default is `/tmp/appliance-{random}`

## Dependencies

- community.vmware
- vmware.vmware
- vmware.vmware_rest

## Example Playbook
```yaml
---
- name: Manage vmware operation visibility
hosts: all
gather_facts: false

vars:
info_hostname: "vcenterhostname"
info_username: "username"
info_password: "password"

info_license: true
info_storage: true
info_appliance: true

roles:
- role: cloud.vmware_ops.info
```
## License
GNU General Public License v3.0 or later
See [LICENCE](https://github.com/ansible-collections/cloud.aws_troubleshooting/blob/main/LICENSE) to see the full text.
## Author Information
- Ansible Cloud Content Team
26 changes: 26 additions & 0 deletions roles/info/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
info_validate_certs: true
info_hostport: "{{ info_hostname + ':' + info_port if info_port is defined else info_hostname }}"

# Appliance
info_appliance_gather: all
info_appliance_file: "/tmp/appliance-{{ lookup('community.general.random_string', special=false) }}"

# Cluster
info_datacenters: []
info_cluster_file: "/tmp/cluster-{{ lookup('community.general.random_string', special=false) }}"

# Guest
info_guest_file: "/tmp/guest-{{ lookup('community.general.random_string', special=false) }}"

# License
info_license_file: "/tmp/license-{{ lookup('community.general.random_string', special=false) }}"

# Storage
info_storage_file: "/tmp/storage-{{ lookup('community.general.random_string', special=false) }}"

# Enable
info_guest: false
info_cluster: false
info_license: false
info_storage: false
info_appliance: false
15 changes: 15 additions & 0 deletions roles/info/tasks/appliance_info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
- name: Fetch the appliance information
vmware.vmware.appliance_info:
hostname: "{{ info_hostname }}"
username: "{{ info_username }}"
password: "{{ info_password }}"
port: "{{ info_port | d(omit) }}"
validate_certs: "{{ info_validate_certs }}"
gather: "{{ info_appliance_gather }}"
register: __apliance

- name: Create JSON file from fetched data
ansible.builtin.copy:
content: "{{ __apliance | map(attribute='appliance') | to_json }}"
dest: "{{ info_appliance_file }}"
mode: "0644"
35 changes: 35 additions & 0 deletions roles/info/tasks/cluster_info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
- name: Get clusters
vmware.vmware_rest.vcenter_cluster_info:
vcenter_hostname: "{{ info_hostport }}"
vcenter_username: "{{ info_username }}"
vcenter_password: "{{ info_password }}"
vcenter_validate_certs: "{{ info_validate_certs }}"
register: __clusters
tags:
- cluster

- name: Get cluster info
community.vmware.vmware_cluster_info:
hostname: "{{ info_hostname }}"
username: "{{ info_username }}"
password: "{{ info_password }}"
port: "{{ info_port | d(omit) }}"
validate_certs: "{{ info_validate_certs }}"
cluster_name: "{{ item.name }}"
schema: vsphere
properties:
- name
- configuration.dasConfig.enabled
- summary.totalCpu
loop: "{{ __clusters.value }}"
register: __clusters_info
tags:
- cluster

- name: Create JSON file from fetched data
ansible.builtin.copy:
content: "{{ __clusters_info.results | map(attribute='clusters') | to_json }}"
dest: "{{ info_cluster_file }}"
mode: "0644"
tags:
- cluster
14 changes: 14 additions & 0 deletions roles/info/tasks/guest_info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
- name: Guest info
vmware.vmware.guest_info:
hostname: "{{ info_hostname }}"
username: "{{ info_username }}"
password: "{{ info_password }}"
port: "{{ info_port | d(omit) }}"
validate_certs: "{{ info_validate_certs }}"
register: __guests

- name: Create JSON file from fetched data
ansible.builtin.copy:
content: "{{ __guests | to_json }}"
dest: "{{ info_guest_file }}"
mode: "0644"
14 changes: 14 additions & 0 deletions roles/info/tasks/license_info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
- name: Fetch the license information
vmware.vmware.license_info:
hostname: "{{ info_hostname }}"
username: "{{ info_username }}"
password: "{{ info_password }}"
port: "{{ info_port | d(omit) }}"
validate_certs: "{{ info_validate_certs }}"
register: __license

- name: Create JSON file from fetched data
ansible.builtin.copy:
content: "{{ __license.licenses | to_json }}"
dest: "{{ info_license_file }}"
mode: "0644"
29 changes: 29 additions & 0 deletions roles/info/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
- name: License info
ansible.builtin.include_tasks: license_info.yml
when: info_license
tags:
- license

- name: Appliance info
ansible.builtin.include_tasks: appliance_info.yml
when: info_appliance
tags:
- appliance

- name: Guest info
ansible.builtin.include_tasks: guest_info.yml
when: info_guest
tags:
- guest

- name: Cluster info
ansible.builtin.include_tasks: cluster_info.yml
when: info_cluster
tags:
- cluster

- name: Storage info
ansible.builtin.include_tasks: storage_info.yml
when: info_storage
tags:
- storage
14 changes: 14 additions & 0 deletions roles/info/tasks/storage_info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
- name: Gather storage policy
community.vmware.vmware_vm_storage_policy_info:
hostname: "{{ info_hostname }}"
username: "{{ info_username }}"
password: "{{ info_password }}"
port: "{{ info_port | d(omit) }}"
validate_certs: "{{ info_validate_certs }}"
register: __storage_policy

- name: Create JSON file from fetched data
ansible.builtin.copy:
content: "{{ __storage_policy.spbm_profiles | to_json }}"
dest: "{{ info_storage_file }}"
mode: "0644"
25 changes: 25 additions & 0 deletions tests/integration/targets/info_test/mock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[
{
"httpRequest": {
"method": "POST",
"path": "/rest/com/vmware/cis/session"
},
"httpResponse": {
"statusCode": 200,
"body": {"value": "72300ca9ff16c5743fa0a6328c8570ce"}
}
},
{
"httpRequest": {
"method" : "GET",
"path" : "/api/vcenter/cluster"
},
"httpResponse": {
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
},
"body": "[{\"drs_enabled\":false,\"cluster\":\"domain-c2808\",\"name\":\"DC0_C0\",\"ha_enabled\":false}]"
}
}
]
19 changes: 19 additions & 0 deletions tests/integration/targets/info_test/run.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- hosts: localhost
gather_facts: no
collections:
- community.general
vars_files:
- vars.yml

tasks:
- name: Vcsim
ansible.builtin.import_role:
name: prepare_soap

- name: Vcsim
ansible.builtin.import_role:
name: prepare_rest

- name: Import info role
ansible.builtin.import_role:
name: info_test
3 changes: 3 additions & 0 deletions tests/integration/targets/info_test/runme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
source ../init.sh
exec ansible-playbook run.yml
4 changes: 4 additions & 0 deletions tests/integration/targets/info_test/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- name: Info role
ansible.builtin.import_role:
name: cloud.vmware_ops.info
10 changes: 10 additions & 0 deletions tests/integration/targets/info_test/vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
info_hostname: "127.0.0.1"
info_username: "user"
info_password: "pass"
info_port: "8989"
info_hostport: "127.0.0.1:1080"
info_validate_certs: false

mock_file: "info_test"

info_cluster: true

0 comments on commit 782dd38

Please sign in to comment.