diff --git a/galaxy.yml b/galaxy.yml index fd46563e..cdbf96dd 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -22,4 +22,5 @@ build_ignore: dependencies: { "vmware.vmware_rest": ">=2.3.1", "community.vmware": ">=4.2.0", + "kubernetes.core": ">=3.0.1", } diff --git a/playbooks/info.yml b/playbooks/info.yml new file mode 100644 index 00000000..34266e34 --- /dev/null +++ b/playbooks/info.yml @@ -0,0 +1,6 @@ +- name: Gather infomation about VMware + hosts: all + gather_facts: false + + roles: + - role: cloud.vmware_ops.info diff --git a/roles/info/README.md b/roles/info/README.md new file mode 100644 index 00000000..acfdd6e5 --- /dev/null +++ b/roles/info/README.md @@ -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 diff --git a/roles/info/defaults/main.yml b/roles/info/defaults/main.yml new file mode 100644 index 00000000..b266bd6d --- /dev/null +++ b/roles/info/defaults/main.yml @@ -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 diff --git a/roles/info/tasks/appliance_info.yml b/roles/info/tasks/appliance_info.yml new file mode 100644 index 00000000..4a4ac65b --- /dev/null +++ b/roles/info/tasks/appliance_info.yml @@ -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" diff --git a/roles/info/tasks/cluster_info.yml b/roles/info/tasks/cluster_info.yml new file mode 100644 index 00000000..89e85840 --- /dev/null +++ b/roles/info/tasks/cluster_info.yml @@ -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 diff --git a/roles/info/tasks/guest_info.yml b/roles/info/tasks/guest_info.yml new file mode 100644 index 00000000..d96587bf --- /dev/null +++ b/roles/info/tasks/guest_info.yml @@ -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" diff --git a/roles/info/tasks/license_info.yml b/roles/info/tasks/license_info.yml new file mode 100644 index 00000000..b880f19a --- /dev/null +++ b/roles/info/tasks/license_info.yml @@ -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" diff --git a/roles/info/tasks/main.yml b/roles/info/tasks/main.yml new file mode 100644 index 00000000..3f6332a7 --- /dev/null +++ b/roles/info/tasks/main.yml @@ -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 diff --git a/roles/info/tasks/storage_info.yml b/roles/info/tasks/storage_info.yml new file mode 100644 index 00000000..666b165b --- /dev/null +++ b/roles/info/tasks/storage_info.yml @@ -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" diff --git a/tests/integration/targets/info_test/mock.json b/tests/integration/targets/info_test/mock.json new file mode 100644 index 00000000..972240dd --- /dev/null +++ b/tests/integration/targets/info_test/mock.json @@ -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}]" + } +} +] diff --git a/tests/integration/targets/info_test/run.yml b/tests/integration/targets/info_test/run.yml new file mode 100644 index 00000000..ae03d4b3 --- /dev/null +++ b/tests/integration/targets/info_test/run.yml @@ -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 diff --git a/tests/integration/targets/info_test/runme.sh b/tests/integration/targets/info_test/runme.sh new file mode 100755 index 00000000..a4c36631 --- /dev/null +++ b/tests/integration/targets/info_test/runme.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +source ../init.sh +exec ansible-playbook run.yml diff --git a/tests/integration/targets/info_test/tasks/main.yml b/tests/integration/targets/info_test/tasks/main.yml new file mode 100644 index 00000000..278ae96a --- /dev/null +++ b/tests/integration/targets/info_test/tasks/main.yml @@ -0,0 +1,4 @@ +--- +- name: Info role + ansible.builtin.import_role: + name: cloud.vmware_ops.info diff --git a/tests/integration/targets/info_test/vars.yml b/tests/integration/targets/info_test/vars.yml new file mode 100644 index 00000000..ba988a8e --- /dev/null +++ b/tests/integration/targets/info_test/vars.yml @@ -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