Skip to content

Commit

Permalink
Merge pull request #103 from mikemorency/mm-feature/improve-info-role
Browse files Browse the repository at this point in the history
improve info role outputs
  • Loading branch information
mikemorency authored Oct 8, 2024
2 parents 2438010 + f844603 commit 362c4c3
Show file tree
Hide file tree
Showing 22 changed files with 196 additions and 86 deletions.
4 changes: 4 additions & 0 deletions changelogs/fragments/103-improve-info-role.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
minor_changes:
- info - changed default filenames from randomly generated string to static filename to remove community dependency
- info - added optional output variable which includes gathered info
110 changes: 104 additions & 6 deletions roles/info/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# info

A role that gather information from vcenter.
A role that gather information from vCenter.

## Requirements

Expand All @@ -20,6 +20,93 @@ N/A
- **info_validate_certs**
- Allows connection when SSL certificates are not valid. Set to false when certificates are not trusted.

### Output
- **info_expose_outputs_as_variable**
- If set to true, the role will expose the gathered information as a variable which can be used later on in your playbook. The variable is called `vmware_ops_info_outputs`. If set to false, this variable is not set.
- The variable and it's attributes (license, appliance, etc) are returned regardless if data was gathered or not. However, if you do not gather information pertaining to an attribute an empty data set is returned.
- The empty data set will be the same type as a populated dataset; meaning if the data set is normally a list, an empty list will be returned.
- For example, if `info_appliance` is set to `false`, then `vmware_ops_info_outputs.appliance` will be `{}`. If `info_guests` is set to `false`, then `vmware_ops_info_outputs.guests` will be `[]`.

The variable's attributes have the following data types:
```
vmware_ops_info_outputs:
appliance: dict
license: list(str)
cluster: list(dict)
guest: list(dict)
storage: list(dict)
```

An abbreviated example of the data returned can be found below:
```
"vmware_ops_info_outputs": {
"appliance": {
"access": {
"access": {
"consolecli": true,
"dcui": true,
"shell": {
"enabled": "False",
"timeout": "0"
},
"ssh": true
}
},
"firewall": {
"inbound": []
},
..... # note: this example is abbreviated for conciseness
},
"cluster": [
{
"My-Cluster": {
"configuration": {
"dasConfig": {
"enabled": false
}
},
"name": "My-Cluster",
"summary": {
"totalCpu": 514080
}
}
}
],
"guest": [
{
"advanced_settings": {
"cpuid.coresPerSocket.cookie": "1",
"ethernet0.pciSlotNumber": "32",
"guestinfo.vmtools.buildNumber": "22544099",
..... # note: this example is abbreviated for conciseness
},
]
"license": [
"00000-0AA0A-000AA-000AA-0A0A0",
]
"storage": [
{
"constraints_sub_profiles": [
{
"rule_set_info": [
{
"id": "com.vmware.storage.tag.openshift-rh-qfklm.property",
"value": [
"rh-qfklm"
]
}
],
"rule_set_name": "Tag based placement"
}
],
"description": null,
"id": "34d58084-5b43-49f7-a29e-fd4b00f9f801",
"name": "openshift-storage-policy-rh-qfklm"
}
]
}
```

### Appliance
- **info_appliance**
- Define whether appliance information should be gathered. Default is `false`.
Expand All @@ -28,35 +115,40 @@ N/A
- 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}`
- File where to store the gathered data. Default is `/tmp/vmware_ops_info_appliance`
- If set to an empty string or `false`, the data is not written to a file.

### License
- **info_license**
- Define whether license information should be gathered. Default is `false`.

- **info_license_file**
- File where to store the gathered data. Default is `/tmp/license-{random}`
- File where to store the gathered data. Default is `/tmp/vmware_ops_info_license`
- If set to an empty string or `false`, the data is not written to a file.

### Cluster
- **info_cluster**
- Define whether cluster information should be gathered. Default is `false`.

- **info_cluster_file**
- File where to store the gathered data. Default is `/tmp/cluster-{random}`
- File where to store the gathered data. Default is `/tmp/vmware_ops_info_cluster`
- If set to an empty string or `false`, the data is not written to a file.

### Storage
- **info_storage**
- Define whether storage information should be gathered. Default is `false`.

- **info_storage_file**
- File where to store the gathered data. Default is `/tmp/storage-{random}`
- File where to store the gathered data. Default is `/tmp/vmware_ops_info_storage`
- If set to an empty string or `false`, the data is not written to a file.

### Guest
- **info_guest**
- Define whether guest information should be gathered. Default is `false`.

- **info_guest_file**
- File where to store the gathered data. Default is `/tmp/guest-{random}`
- File where to store the gathered data. Default is `/tmp/vmware_ops_info_guest`
- If set to an empty string or `false`, the data is not written to a file.

## Dependencies

Expand All @@ -82,6 +174,12 @@ N/A

roles:
- role: cloud.vmware_ops.info

tasks:
# Note, this variable can contain a lot of data
- name: Debug Output Variable
ansible.builtin.debug:
var: vmware_ops_info_outputs
```
## License
Expand Down
11 changes: 6 additions & 5 deletions roles/info/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
info_validate_certs: true
info_expose_outputs_as_variable: 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) }}"
info_appliance_file: "/tmp/vmware_ops_info_appliance"

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

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

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

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

# Enable
info_guest: false
Expand Down
22 changes: 12 additions & 10 deletions roles/info/tasks/appliance_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
properties: "{{ info_appliance_gather }}"
register: __appliance

- name: Make sure directory exists
ansible.builtin.file: # noqa: risky-file-permissions
path: "{{ info_appliance_file | dirname }}"
state: "directory"

- name: Create JSON file from fetched data
ansible.builtin.copy:
content: "{{ __appliance.appliance | to_json }}"
dest: "{{ info_appliance_file }}"
mode: "0644"
- name: Write Appliance Results To File
when: info_appliance_file
block:
- name: Make sure directory exists
ansible.builtin.file: # noqa: risky-file-permissions
path: "{{ info_appliance_file | dirname }}"
state: "directory"
- name: Create JSON file from fetched data
ansible.builtin.copy:
content: "{{ __appliance.appliance | to_json }}"
dest: "{{ info_appliance_file }}"
mode: "0644"
26 changes: 14 additions & 12 deletions roles/info/tasks/cluster_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@
tags:
- cluster

- name: Make sure directory exists
ansible.builtin.file: # noqa: risky-file-permissions
path: "{{ info_cluster_file | dirname }}"
state: "directory"

- 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
- name: Write Cluster Results To File
when: info_cluster_file
block:
- name: Make sure directory exists
ansible.builtin.file: # noqa: risky-file-permissions
path: "{{ info_cluster_file | dirname }}"
state: "directory"
- 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
22 changes: 12 additions & 10 deletions roles/info/tasks/guest_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
validate_certs: "{{ info_validate_certs }}"
register: __guests

- name: Make sure directory exists
ansible.builtin.file: # noqa: risky-file-permissions
path: "{{ info_guest_file | dirname }}"
state: "directory"

- name: Create JSON file from fetched data
ansible.builtin.copy:
content: "{{ __guests | to_json }}"
dest: "{{ info_guest_file }}"
mode: "0644"
- name: Write Guest Results To File
when: info_guest_file
block:
- name: Make sure directory exists
ansible.builtin.file: # noqa: risky-file-permissions
path: "{{ info_guest_file | dirname }}"
state: "directory"
- name: Create JSON file from fetched data
ansible.builtin.copy:
content: "{{ __guests | to_json }}"
dest: "{{ info_guest_file }}"
mode: "0644"
22 changes: 12 additions & 10 deletions roles/info/tasks/license_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
validate_certs: "{{ info_validate_certs }}"
register: __license

- name: Make sure directory exists
ansible.builtin.file: # noqa: risky-file-permissions
path: "{{ info_license_file | dirname }}"
state: "directory"

- name: Create JSON file from fetched data
ansible.builtin.copy:
content: "{{ __license.licenses | to_json }}"
dest: "{{ info_license_file }}"
mode: "0644"
- name: Write License Results To File
when: info_license_file
block:
- name: Make sure directory exists
ansible.builtin.file: # noqa: risky-file-permissions
path: "{{ info_license_file | dirname }}"
state: "directory"
- name: Create JSON file from fetched data
ansible.builtin.copy:
content: "{{ __license.licenses | to_json }}"
dest: "{{ info_license_file }}"
mode: "0644"
10 changes: 10 additions & 0 deletions roles/info/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@
when: info_storage
tags:
- storage

- name: Expose Gathered Facts As Variable vmware_ops_info_outputs
ansible.builtin.set_fact:
vmware_ops_info_outputs:
license: "{{ __license.licenses | default([]) }}"
appliance: "{{ __appliance.appliance | default({}) }}"
guest: "{{ __guests.guests | default([]) }}"
cluster: "{{ _clusters_info.results | default([]) | map(attribute='clusters') }}"
storage: "{{ __storage_policy.spbm_profiles | default([]) }}"
when: info_expose_outputs_as_variable
22 changes: 12 additions & 10 deletions roles/info/tasks/storage_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
validate_certs: "{{ info_validate_certs }}"
register: __storage_policy

- name: Make sure directory exists
ansible.builtin.file: # noqa: risky-file-permissions
path: "{{ info_storage_file | dirname }}"
state: "directory"

- name: Create JSON file from fetched data
ansible.builtin.copy:
content: "{{ __storage_policy.spbm_profiles | to_json }}"
dest: "{{ info_storage_file }}"
mode: "0644"
- name: Write Storage Policy Results To File
when: info_storage_file
block:
- name: Make sure directory exists
ansible.builtin.file: # noqa: risky-file-permissions
path: "{{ info_storage_file | dirname }}"
state: "directory"
- name: Create JSON file from fetched data
ansible.builtin.copy:
content: "{{ __storage_policy.spbm_profiles | to_json }}"
dest: "{{ info_storage_file }}"
mode: "0644"
Empty file modified tests/integration/targets/runme.sh
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
- hosts: localhost
gather_facts: no
collections:
- community.general

tasks:
- name: Import eco-vcenter credentials
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
- hosts: localhost
gather_facts: no
collections:
- community.general

tasks:
- name: Import eco-vcenter credentials
Expand Down
2 changes: 0 additions & 2 deletions tests/integration/targets/vmware_ops_deploy_ovf_test/run.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
- hosts: localhost
gather_facts: no
collections:
- community.general

tasks:
- name: Import eco-vcenter credentials
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
- hosts: localhost
gather_facts: no
collections:
- community.general

tasks:
- name: Import eco-vcenter credentials
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
- hosts: localhost
gather_facts: no
collections:
- community.general

tasks:
- name: Import eco-vcenter credentials
Expand Down
2 changes: 0 additions & 2 deletions tests/integration/targets/vmware_ops_info_test/run.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
- name: Run Info Test Tasks
hosts: localhost
gather_facts: false
collections:
- community.general

tasks:

Expand Down
Loading

0 comments on commit 362c4c3

Please sign in to comment.