Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VMware: add properties option to vmware_host_facts module #62916

Merged

Conversation

sky-joker
Copy link
Contributor

@sky-joker sky-joker commented Sep 27, 2019

SUMMARY

Add properties option to vmware_host_facts module.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

vmware_host_facts

ADDITIONAL INFORMATION

It is possible to supplement the lack of information by combining the legacy output of the module and the output specifying properties as follows.

---
- name: Combine the results get using  vmware_guest_facts
  hosts: localhost
  gather_facts: no
  vars:
    hostname: vCenter IP
    username: administrator@vsphere.local
    password: password
    esxi_servers:
      - esxi-host-name
  tasks:
    - name: Gather some info from a host using the vSphere API output schema
      vmware_host_facts:
        hostname: "{{ hostname }}"
        username: "{{ username }}"
        password: "{{ password }}"
        validate_certs: no
        esxi_hostname: "{{ item }}"
        schema: vsphere
        properties:
          - name
          - hardware.memorySize
          - hardware.cpuInfo.numCpuCores
          - config.product.apiVersion
          - overallStatus
      register: result1
      loop: "{{ esxi_servers }}"

    - debug: var=result1

    - name: Gather vmware host facts from vCenter with tag information
      vmware_host_facts:
        hostname: "{{ hostname }}"
        username: "{{ username }}"
        password: "{{ password }}"
        validate_certs: no
        esxi_hostname: "{{ item }}"
        show_tag: True
      register: result2
      loop: "{{ esxi_servers }}"

    - debug: var=result2

    - name: Combine result1 and result2
      set_fact:
        data: >-
          {{ data | default([])
            + [item.ansible_facts | combine(combine_data)]
          }}
      vars:
        combine_data: >-
          {{ result2.results
            | selectattr('ansible_facts.ansible_hostname','equalto',item['ansible_facts']['name'])
            | list
            | first
          }}
      loop: "{{ result1.results }}"

    - debug: var=data

@ansibot
Copy link
Contributor

ansibot commented Sep 27, 2019

@ansibot
Copy link
Contributor

ansibot commented Sep 27, 2019

@sky-joker, just so you are aware we have a dedicated Working Group for vmware.
You can find other people interested in this in #ansible-vmware on Freenode IRC
For more information about communities, meetings and agendas see https://github.com/ansible/community

click here for bot help

@ansibot ansibot added affects_2.10 This issue/PR affects Ansible v2.10 cloud community_review In order to be merged, this PR must follow the community review workflow. feature This issue/PR relates to a feature request. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:community This issue/PR relates to code supported by the Ansible community. vmware VMware community labels Sep 27, 2019
@goneri
Copy link
Contributor

goneri commented Sep 30, 2019

Thanks @sky-joker for the patch! Nice job.

@ansibot ansibot removed the needs_triage Needs a first human triage before being processed. label Sep 30, 2019
@Akasurde Akasurde merged commit 7b7d266 into ansible:devel Oct 7, 2019
@sky-joker
Copy link
Contributor Author

Thank you @Akasurde for merging!

@sky-joker sky-joker deleted the add_properties_option_to_vmware_host_facts branch October 7, 2019 12:45
@ansible ansible locked and limited conversation to collaborators Nov 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.10 This issue/PR affects Ansible v2.10 cloud community_review In order to be merged, this PR must follow the community review workflow. feature This issue/PR relates to a feature request. module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community. vmware VMware community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants