You need to create two files first in your /etc/ansible/playbooks. login.yml and vcenter_vars.yml. This will allow to pass through information to the other .yml playbooks.

login.yml

---
- name: Login into vCenter
  uri:
    url: https://{{ vcenter_server }}/rest/com/vmware/cis/session
    force_basic_auth: yes
    validate_certs: "{{ validate_certs }}"
    method: POST
    user: "{{ vcenter_user }}"
    password: "{{ vcenter_pass }}"
  register: login
vcenter_vars.yml

---
# Common variables
- validate_certs: no
- debug_flag: no

# vCenter related details
- vcenter_server: 192.168.1.13
- vcenter_user: administrator@vsphere.local
- vcenter_pass: VMware1!

# VMware object related details
#- datacenter: DC0
#- cluster_name: DC0_C1
#- vm_name: rhel_7_template

Now here are some examples below, I have tested all of them and they work. The yml files will need to be created in your playbook directory. Use the following command to run them

ansible-playbook /etc/ansible/playbooks/filename!!.yml
1.get_all_categories.yml

---
- name: Gather all Categories for vCenter
  gather_facts: no
  vars_files:
    - vcenter_vars.yml
  hosts: localhost
  tasks:
    - name: Login task
      include_tasks: login.yml

    - name: Get Categories from vCenter
      uri:
        url: https://{{ vcenter_server }}/rest/com/vmware/cis/tagging/category
        force_basic_auth: yes
        validate_certs: "{{ validate_certs }}"
        headers:
          Cookie: "{{ login.set_cookie }}"
      register: vCategories

    - name: Print names of Categories in the given vCenter
      debug:
        msg: "{{ item }}"
      with_items: "{{ vCategories.json.value }}"
2.get_all_clusters.yml

---
- name: Gather all clusters for vCenter
  gather_facts: no
  vars_files:
    - vcenter_vars.yml
  hosts: localhost
  tasks:
    - name: Login task
      include_tasks: login.yml

    - name: Get clusters from vCenter
      uri:
        url: https://{{ vcenter_server }}/rest/vcenter/cluster
        force_basic_auth: yes
        validate_certs: "{{ validate_certs }}"
        headers:
          Cookie: "{{ login.set_cookie }}"
      register: vClusters

    - name: Print names of clusters in the given vCenter
      debug:
        msg: "{{ item.name }}"
      with_items: "{{ vClusters.json.value }}"
3.get_all_datacenters.yml

---
- name: Gather all datacenters for vCenter
  gather_facts: no
  vars_files:
    - vcenter_vars.yml
  hosts: localhost
  tasks:
    - name: Login task
      include_tasks: login.yml

    - name: Get datacenters from vCenter
      uri:
        url: https://{{ vcenter_server }}/rest/vcenter/datacenter
        force_basic_auth: yes
        validate_certs: "{{ validate_certs }}"
        headers:
          Cookie: "{{ login.set_cookie }}"
      register: vDatacenters

    - name: Print names of datacenters in the given vCenter
      debug:
        msg: "{{ item.name }}"
      with_items: "{{ vDatacenters.json.value }}"
4.get_all_datastores.yml

---
- name: Gather all datastores for vCenter
  gather_facts: no
  vars_files:
    - vcenter_vars.yml
  hosts: localhost
  tasks:
    - name: Login task
      include_tasks: login.yml

    - name: Get datastores from vCenter
      uri:
        url: https://{{ vcenter_server }}/rest/vcenter/datastore
        force_basic_auth: yes
        validate_certs: "{{ validate_certs }}"
        headers:
          Cookie: "{{ login.set_cookie }}"
      register: vdatastores

    - name: Print names of datastores in the given vCenter
      debug:
        msg: "{{ item.name }}"
      with_items: "{{ vdatastores.json.value }}"
5.get_all_folders.yml

---
- name: Gather all folders for vCenter
  gather_facts: no
  vars_files:
    - vcenter_vars.yml
  hosts: localhost
  tasks:
    - name: Login task
      include_tasks: login.yml

    - name: Get folders from vCenter
      uri:
        url: https://{{ vcenter_server }}/rest/vcenter/folder
        force_basic_auth: yes
        validate_certs: "{{ validate_certs }}"
        headers:
          Cookie: "{{ login.set_cookie }}"
      register: vfolders

    - name: Print names of folders in the given vCenter
      debug:
        msg: "{{ item.name }}"
      with_items: "{{ vfolders.json.value }}"
6.get_all_hosts.yml

---
- name: Gather all host system for vCenter
  gather_facts: no
  vars_files:
    - vcenter_vars.yml
  hosts: localhost
  tasks:
    - name: Login task
      include_tasks: login.yml

    - name: Get Hosts from vCenter
      uri:
        url: https://{{ vcenter_server }}/rest/vcenter/host
        force_basic_auth: yes
        validate_certs: "{{ validate_certs }}"
        headers:
          Cookie: "{{ login.set_cookie }}"
      register: vchosts

    - name: Print names of ESXi host system in the given vCenter
      debug:
        msg: "{{ item.name }}"
      with_items: "{{ vchosts.json.value }}"
7.get_all_networks.yml

---
- name: Gather all networks for vCenter
  gather_facts: no
  vars_files:
    - vcenter_vars.yml
  hosts: localhost
  tasks:
    - name: Login task
      include_tasks: login.yml

    - name: Get networks from vCenter
      uri:
        url: https://{{ vcenter_server }}/rest/vcenter/network
        force_basic_auth: yes
        validate_certs: "{{ validate_certs }}"
        headers:
          Cookie: "{{ login.set_cookie }}"
      register: vnetworks

    - name: Print names of networks in the given vCenter
      debug:
        msg: "{{ item.name }}"
      with_items: "{{ vnetworks.json.value }}"
8.get_all_tags.yml

---
- name: Gather all Tags for vCenter
  gather_facts: no
  vars_files:
    - vcenter_vars.yml
  hosts: localhost
  tasks:
    - name: Login task
      include_tasks: login.yml

    - name: Get Tags from vCenter
      uri:
        url: https://{{ vcenter_server }}/rest/com/vmware/cis/tagging/tag
        force_basic_auth: yes
        validate_certs: "{{ validate_certs }}"
        headers:
          Cookie: "{{ login.set_cookie }}"
      register: vTags

    - name: Print names of Tags in the given vCenter
      debug:
        msg: "{{ item }}"
      with_items: "{{ vTags.json.value }}"
9.get_all_vms.yml

---
- name: Gather all VMs for vCenter
  gather_facts: no
  vars_files:
    - vcenter_vars.yml
  hosts: localhost
  tasks:
    - name: Login task
      include_tasks: login.yml

    - name: Get VMs from vCenter
      uri:
        url: https://{{ vcenter_server }}/rest/vcenter/vm
        force_basic_auth: yes
        validate_certs: "{{ validate_certs }}"
        headers:
          Cookie: "{{ login.set_cookie }}"
      register: vVMs

    - name: Print names of VMs in the given vCenter
      debug:
        msg: "{{ item.name }}"
      with_items: "{{ vVMs.json.value }}"
10.get_cluster_info.yml

---
- name: Gather cluster information for vCenter
  gather_facts: no
  vars_files:
    - vcenter_vars.yml
  hosts: localhost
  tasks:
    - name: Login task
      include_tasks: login.yml

    - name: Get clusters from vCenter
      uri:
        url: https://{{ vcenter_server }}/rest/vcenter/cluster
        force_basic_auth: yes
        validate_certs: "{{ validate_certs }}"
        headers:
          Cookie: "{{ login.set_cookie }}"
      register: vClusters

    - name: Print names of clusters in the given vCenter
      set_fact:
        cluster_id: "{{ item.cluster }}"
      vars:
          cluster_id_query: "[?name == '{{ cluster_name }}']"
      with_items: "{{ vClusters.json.value }}"

    - name: Get cluster info from vCenter
      uri:
        url: https://{{ vcenter_server }}/rest/vcenter/cluster/{{ cluster_id }}
        force_basic_auth: yes
        validate_certs: "{{ validate_certs }}"
        headers:
          Cookie: "{{ login.set_cookie }}"
      register: vCluster_info

    - name: Print cluster's resource pool name
      debug:
        msg: "{{ vCluster_info.json.value['resource_pool'] }}"

By Kad