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

Is there a Fact gathering module? #23

Open
lpereira1 opened this issue Mar 30, 2021 · 1 comment
Open

Is there a Fact gathering module? #23

lpereira1 opened this issue Mar 30, 2021 · 1 comment

Comments

@lpereira1
Copy link

Im trying to write some automation around UCS vnics and some of the defaults are causing me issues. Is there a facts module somewhere I can use so I can verify information before I make a change via the playbook.

Specifically, I added some vlans into a vnic template and the mtu was changed because the default is 1500 and I run another value.

@bakrir
Copy link

bakrir commented Apr 10, 2021

Hi @lpereira1,

You can use the ucs_query module to pull facts about a particular configuration or classid. It is very simple to use and provides a lot of detail that you will need to parse through. I use this module pretty heavily for auditing configuration. Here is an example of how I audit our ucs_vlans configuration (in our repo) against what is running on the actual system:

- hosts: all
  connection: local
  gather_facts: no
  vars:
  # vlan_list: []
    login_info: &login_info
      hostname: "{{ ucs_hostname }}"
      username: "{{ ucs_username }}"
      password: "{{ ucs_password }}"  
  
  tasks:
  - name: "COLLECT VLAN DETAILS FROM {{ ucs_hostname |upper }}"
    cisco.ucs.ucs_query:
      <<: *login_info
      class_ids: fabricVlan
    register: fabricVlan
  
  - set_fact:
      ucs_vlan_running_config: "{{ ucs_vlan_running_config | default({}) | combine ({ item.name : item.id }) }}"
    loop: "{{ fabricVlan.objects.fabricVlan }}"

  - set_fact:
      ucs_vlan_intended_config: "{{ ucs_vlan_intended_config | default({}) | combine ({ item.name : item.id }) }}"
    loop: "{{ ucs_vlans }}"
  
  - name: FIND VLAN DIFF (INTENDED VS RUNNING)
    set_fact:
      extra_vlans: "{{ (ucs_vlan_running_config | difference(ucs_vlan_intended_config)) }}"
      missing_vlans: "{{ (ucs_vlan_intended_config | difference(ucs_vlan_running_config)) }}"
    # no_log: true

  - name: "EXTRA VLANS"
    debug:
      msg: "{{ extra_vlans | ternary('VLANS TO DELETE/CHECK:', 'NO EXTRA VLANS') }}{{ extra_vlans|default(omit) }}"

  - name: "MISSING VLANS"
    debug:
      msg: "{{ missing_vlans | ternary('MISSING VLANS:', 'NO VLANS ARE MISSING') }}{{ missing_vlans|default(omit) }}"

For auditing vnics or vnic_template configuration, I think you'll need to use class_ids: vnicEther or class_ids: vnicLanConnTempl. I was planning on writing a query for something similar but I just haven't gotten around to it yet.

I hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants