Пример #1
0
def main():
    _setting_exists = False
    module_args = dnac_argument_spec
    module_args.update(dhcp_servers=dict(type='list', required=False),
                       group_name=dict(type='str', default='-1'))

    module = AnsibleModule(argument_spec=module_args, supports_check_mode=True)

    #  Define Local Variables
    state = module.params['state']
    dhcp_servers = module.params['dhcp_servers']
    group_name = module.params['group_name']

    #  Build the payload dictionary
    payload = [{
        "instanceType": "ip",
        "namespace": "global",
        "type": "ip.address",
        "key": "dhcp.server",
        "value": dhcp_servers,
        "groupUuid": "-1"
    }]

    # instansiate the dnac class
    dnac = DnaCenter(module)

    # obtain the groupUuid and update the payload dictionary
    group_id = dnac.get_group_id(group_name)

    # Set the api_path
    dnac.api_path = 'api/v1/commonsetting/global/' + group_id + '?key=dhcp.server'

    dnac.process_common_settings(payload, group_id)
Пример #2
0
def main():
    _banner_exists = False
    module_args = dnac_argument_spec
    module_args.update(
        banner_message=dict(type='str',default='', required=False),
        group_name=dict(type='str',default='-1'), 
        retain_banner=dict(type='bool', default=True)
        )

    module = AnsibleModule(
        argument_spec = module_args,
        supports_check_mode = True
        )
    
    #  Set Local Variables 
    banner_message = module.params['banner_message']
    retain_banner = module.params['retain_banner']
    group_name = module.params['group_name']
    state = module.params['state']

    #  Build the payload dictionary
    payload = [
        {"instanceType":"banner",
        "namespace":"global",
        "type": "banner.setting",
        "key":"device.banner",
        "value": [
            {
              "bannerMessage": banner_message,
              "retainExistingBanner": retain_banner
        }],
        "groupUuid":"-1"
        }
        ]

    # instansiate the dnac class
    dnac = DnaCenter(module)

    # obtain the groupUuid and update the payload dictionary
    group_id = dnac.get_group_id(group_name)

    # set the retain banner attribute 
    if retain_banner:
        payload[0]['value'][0]['retainExistingBanner'] = True
    else: 
        payload[0]['value'][0]['retainExistingBanner'] = False

    # set the api_path
    dnac.api_path = 'api/v1/commonsetting/global/' + group_id + '?key=device.banner'

    dnac.process_common_settings(payload, group_id)
Пример #3
0
def main():
    module_args = dnac_argument_spec
    module_args.update(group_name=dict(type='str',
                                       default='-1',
                                       required=False),
                       snmp_servers=dict(type='list', required=False),
                       enable_dnac=dict(type='bool',
                                        required=False,
                                        default=True))

    module = AnsibleModule(argument_spec=module_args, supports_check_mode=True)
    #  Set Local Variables
    state = module.params['state']
    snmp_servers = module.params['snmp_servers']
    group_name = module.params['group_name']
    enable_dnac = module.params['enable_dnac']

    #  Build the payload dictionary
    payload = [{
        "instanceType":
        "snmp",
        "namespace":
        "global",
        "type":
        "snmp.setting",
        "key":
        "snmp.trap.receiver",
        "value": [{
            "ipAddresses": snmp_servers,
            "configureDnacIP": enable_dnac
        }],
        "groupUuid":
        "-1",
    }]

    # instansiate the dnac class
    dnac = DnaCenter(module)

    # obtain the groupUuid and update the payload dictionary
    group_id = dnac.get_group_id(group_name)

    # Set the api path
    dnac.api_path = 'api/v1/commonsetting/global/' + group_id + '?key=snmp.trap.receiver'

    # Process Setting Changes
    dnac.process_common_settings(payload, group_id)
Пример #4
0
def main():
    module_args = dnac_argument_spec
    module_args.update(
        primary_dns_server=dict(type='str', required=False, default=''),
        secondary_dns_server=dict(type='str', required=False),
        domain_name=dict(type='str', required=False, default=''),
        group_name=dict(type='str', required=False, default='-1')
        )

    module = AnsibleModule(
        argument_spec = module_args,
        supports_check_mode = True
        )

    #  Define local variables 
    state = module.params['state']
    domain_name = module.params['domain_name']
    primary_dns_server = module.params['primary_dns_server']
    secondary_dns_server = module.params['secondary_dns_server']
    group_name = module.params['group_name']

    #  Build the payload dictionary
    payload = [
        {"instanceType":"dns",
        "namespace":"global",
        "type": "dns.setting",
        "key":"dns.server",
        "value":[{
                 "domainName" : domain_name,
                 "primaryIpAddress": primary_dns_server,
                 "secondaryIpAddress": secondary_dns_server
                 }],
        "groupUuid":"-1",
        }
        ]

    # instansiate the dnac class
    dnac = DnaCenter(module)

    # obtain the groupUuid and update the payload dictionary
    group_id = dnac.get_group_id(group_name)

    # Set the api_path
    dnac.api_path = 'api/v1/commonsetting/global/' + group_id + '?key=dns.server'
    
    dnac.process_common_settings(payload, group_id)
Пример #5
0
def main():
    module_args = dnac_argument_spec
    module_args.update(timezone=dict(type='str', default='GMT'),
                       group_name=dict(type='str', default='-1'),
                       location=dict(type='str'))

    module = AnsibleModule(argument_spec=module_args, supports_check_mode=True)

    #  set local variables
    state = module.params['state']
    group_name = module.params['group_name']
    location = module.params['location']
    timezone = module.params['timezone']

    #  Build the payload dictionary
    payload = [{
        "instanceType": "timezone",
        "instanceUuid": "",
        "namespace": "global",
        "type": "timezone.setting",
        "key": "timezone.site",
        "value": [""],
        "groupUuid": "-1"
    }]

    # instansiate the dnac class
    dnac = DnaCenter(module)

    # obtain the groupUuid and update the payload dictionary
    group_id = dnac.get_group_id(group_name)

    # update payload with timezone
    if location:
        timezone = dnac.timezone_lookup(location)

    payload[0].update({'value': [timezone]})

    # # check if the configuration is already in the desired state
    dnac.api_path = 'api/v1/commonsetting/global/' + group_id + '?key=timezone.site'

    # process common settings
    dnac.process_common_settings(payload, group_id)
Пример #6
0
def main():
    _group_exists = False
    _parent_exists = False

    module_args = dnac_argument_spec
    module_args.update(
        state=dict(type='str', default='present', choices=['absent', 'present', 'update']),
        group_name=dict(type='str', required=True),
        group_type=dict(type='str', default='area', choices=['area','building']),
        group_parent_name=dict(type='str', default='-1'),
        group_building_address=dict(type='str', default='123')
    )

    result = dict(
        changed=False,
        original_message='',
        message='')

    module = AnsibleModule(
        argument_spec = module_args,
        supports_check_mode = False
        )

    # build the required payload data structure
    payload = {
        "childIds":[""],
        "groupTypeList": ["SITE"],
        "name": module.params["group_name"],
        "additionalInfo":[
            {"attributes":{
                "type":module.params["group_type"]
            },
            "nameSpace":"Location"}
         ]
    }


    # Instantiate the DnaCenter class object
    dnac = DnaCenter(module)
    dnac.api_path = 'api/v1/group'

    #  Get the groups
    groups = dnac.get_obj()
    try: 
      _group_names = [group['name'] for group in groups['response']]
    except TypeError: 
      module.fail_json(msg=groups)
      
    # does group provided exist
    if module.params['group_name'] in _group_names:
        _group_exists = True
    else:
        _group_exists = False

    # does parent provided exist
    if module.params['group_parent_name'] in _group_names:
        _parent_exists = True
    else:
        _parent_exists = False
        module.fail_json(msg='Parent Group does not exist...')

    # find the parent Id specificed by the name
    #_parent_id = [ group['id'] for group in groups['response'] if group['name'] == module.params['group_parent_name']]
    if module.params['group_parent_name'] == 'Global' or module.params['group_parent_name'] == '-1':
        payload.update({'parentId' : ''})
    elif _parent_exists:
        _parent_id = dnac.get_group_id(module.params['group_parent_name'])
        payload.update({'parentId': _parent_id})
    else:
        result['changed'] = False
        module.fail_json(msg="Parent doesn't exist!", **result)

    #  lookup lat/long based on provided address
    if module.params['group_type'] == 'building':
        attribs = dnac.parse_geo(module.params['group_building_address'])
        payload['additionalInfo'][0]['attributes'].update(attribs)

    if module.params['state'] == 'present' and _group_exists:
        result['changed'] = False
        result['intended_payload'] = payload
        module.exit_json(msg='Group already exists.', **result)
    elif module.params['state'] == 'present' and not _group_exists:
        dnac.create_obj(payload)
    elif module.params['state'] == 'absent' and _group_exists:
        _group_id = [group['id'] for group in groups['response'] if group['name'] == module.params['group_name']]
        dnac.delete_obj(_group_id[0])
    elif module.params['state'] == 'absent' and not _group_exists:
        result['changed'] = False
        module.exit_json(msg='Group Does not exist.  Cannot delete.', **result)


    '''