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

UCS_VLAN_Group module not found, Unable to create vlan group, add vlan to vlan group using ansible #129

Open
vivekanand552 opened this issue Jun 12, 2020 · 4 comments

Comments

@vivekanand552
Copy link

Hello All,

I am currently planning to automate my UCS infrastructure using ansible but I am stuck at the process of creating UCS_Vlan_Group and adding the already created vlan to the vlan group.

The specific module for vlan group seems to be not available and even when i check "ansible-doc ucs_vlan_group" its throwing an error module not found as below

[root@ansible-test ~]# ansible-doc ucs_vlan_group
[WARNING]: module ucs_vlan_group not found in: /root/.ansible/plugins/modules:/
usr/share/ansible/plugins/modules:/usr/lib/python2.7/site-
packages/ansible/modules.

I have also git cloned an Cisco UCS repository which said it had ucs_vlan_group module under it but still no luck, This is become a show stopper as this is a crucial step in automating my infrastructure.

Any help would be highly appreciated.

Ansible version and other details below

[root@ansible-test ~]# ansible --version
ansible 2.9.5
config file = /root/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Jun 11 2019, 14:33:56) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

Thanks and Regards
Vivekanand

@dsoper2
Copy link
Contributor

dsoper2 commented Jun 12, 2020

ucs_vlan_to_group requires the vlan group already exist in UCSM, so a recommended alternative is ucs_managed_objects:
- name: Configure vlan groups with managed objects
cisco.ucs.ucs_managed_objects:
<<: *login_info
objects:
- class: FabricNetGroup
module: ucsmsdk.mometa.fabric.FabricNetGroup
properties:
parent_mo_or_dn: fabric/lan
name: vlangroup1
native_net: Access
children:
- class: FabricPooledVlan
module: ucsmsdk.mometa.fabric.FabricPooledVlan
properties:
name: Access
- class: FabricPooledVlan
module: ucsmsdk.mometa.fabric.FabricPooledVlan
properties:
name: Application
- class: FabricPooledVlan
module: ucsmsdk.mometa.fabric.FabricPooledVlan
properties:
name: DataSource
delegate_to: localhost

Also note that active development for Ansible modules has moved to the Ansible collection maintained at https://galaxy.ansible.com/cisco/ucs. More information on collections can be found at https://docs.ansible.com/ansible/latest/user_guide/collections_using.html and Ansible 2.10 and later moves all Cisco modules into collecitons.

@vivekanand552
Copy link
Author

Hello dsoper2,

Thanks a lot for your inputs!

I tried to create a playbook with the same code you had given me above


  • name: add_vlan_group
    hosts: localhost
    gather_facts: false
    connection: local

    vars:
    ucs_hostname: 62.25.81.68
    ucs_username: ucspe
    ucs_password: ucspe
    ucs_state: present
    notes: Ansible test
    dumpfacts: False

    tasks:
    ucs_managed_objects:

    • name: Configure vlan groups with managed objects
      cisco.ucs.ucs_managed_objects:
      hostname: 62.25.81.68
      username: ucspe
      password: ucspe
      objects:
      class: FabricNetGroup
      module: ucsmsdk.mometa.fabric.FabricNetGroup
      properties: {name: inband, native_net: inband, parent_mo_or_dn: fabric/lan}
      children:
      class: FabricPooledVlan
      module: ucsmsdk.mometa.fabric.FabricPooledVlan
      properties: {name: vlan244}
      class: FabricPooledVlan
      module: ucsmsdk.mometa.fabric.FabricPooledVlan
      properties: {name: inband}
      class: FabricPooledVlan
      module: ucsmsdk.mometa.fabric.FabricPooledVlan
      properties: {name: vlan7}
      delegate_to: localhost

But I am getting an malformed error while executing the playbook as below

[root@ansible-test ~]# ansible-playbook ucs_vlangroup_latest.yaml -vvv
ansible-playbook 2.9.5
config file = /root/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.5 (default, Jun 11 2019, 14:33:56) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
Using /root/ansible.cfg as config file
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Parsed /etc/ansible/hosts inventory source with ini plugin
[WARNING]: While constructing a mapping from /root/ucs_vlangroup_latest.yaml, line 28, column 9, found a duplicate dict key (class). Using last defined value only.
[WARNING]: While constructing a mapping from /root/ucs_vlangroup_latest.yaml, line 28, column 9, found a duplicate dict key (module). Using last defined value only.
[WARNING]: While constructing a mapping from /root/ucs_vlangroup_latest.yaml, line 28, column 9, found a duplicate dict key (properties). Using last defined value only.
ERROR! A malformed block was encountered while loading tasks: {u'delegate_to': u'localhost', u'ucs_managed_objects': [{u'name': u'Configure vlan groups with managed objects'}], u'objects': {u'class': u'FabricNetGroup', u'properties': {u'parent_mo_or_dn': u'fabric/lan', u'name': u'inband', u'native_net': u'inband'}, u'module': u'ucsmsdk.mometa.fabric.FabricNetGroup', u'children': {u'class': u'FabricPooledVlan', u'module': u'ucsmsdk.mometa.fabric.FabricPooledVlan', u'properties': {u'name': u'vlan7'}}}, u'cisco.ucs.ucs_managed_objects': {u'username': u'ucspe', u'password': u'ucspe', u'hostname': u'62.25.81.68'}} should be a list or None but is <class 'ansible.parsing.yaml.objects.AnsibleMapping'>

The error appears to be in '/root/ucs_vlangroup_latest.yaml': line 3, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  • name: add_vlan_group
    ^ here

Require your kind help, also if you have a working sample playbook for creating vlan group and adding vlan to vlan group, Kindly share the same.

Regards
Vivekanand

@dsoper2
Copy link
Contributor

dsoper2 commented Jun 15, 2020

There are syntax errors in the yaml file. Github is changing formatting so you will want to ensure the following passes syntax checks with yamllint.

---
# Example Playbook: cisco.ucs.ucs_vlan_to_group.yml
- hosts: ucs
  connection: local
  gather_facts: false

  tasks:
    - name: Test that we have a UCS hostname, UCS username, and UCS password
      fail:
        msg: 'Please define the following variables: ucs_hostname, ucs_username and ucs_password.'
      when: ucs_hostname is not defined or ucs_username is not defined or ucs_password is not defined
      vars:
        # use "<<: *login_info" to substite the information below in each task
        # this is not required, however it makes the playbook shorter.
        login_info: &login_info
          hostname: "{{ ucs_hostname }}"
          username: "{{ ucs_username }}"
          password: "{{ ucs_password }}"

    - name: Configure vlan groups with managed objects
      cisco.ucs.ucs_managed_objects:
        <<: *login_info
        objects:
          - class: FabricNetGroup
            module: ucsmsdk.mometa.fabric.FabricNetGroup
            properties:
              parent_mo_or_dn: fabric/lan
              name: vlangroup1
              native_net: Access
            children:
              - class: FabricPooledVlan
                module: ucsmsdk.mometa.fabric.FabricPooledVlan
                properties:
                  name: Access
              - class: FabricPooledVlan
                module: ucsmsdk.mometa.fabric.FabricPooledVlan
                properties:
                  name: Application
              - class: FabricPooledVlan
                module: ucsmsdk.mometa.fabric.FabricPooledVlan
                properties:
                  name: DataSource
      delegate_to: localhost

@vivekanand552
Copy link
Author

Hello dsoper2,

Thanks a lot for that! the code worked fine and i am able to create vlan group and add vlans to vlan group.

Regards
Vivekanand

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