Looping through data/vars file turns number into a string when creating a site in Cisco DNA Center

When using the task below with the yaml data that is shown below I end up getting an error indicating that my latitude number is not a number. If I just hard code a number in the latitude value the task works as expected. Any suggestions on how to get this to work?

Ansible task

DNA Center Site Creation

  • name: Create building
    cisco.dnac.site_create:
    dnac_host: “{{ ansible_host }}”
    dnac_username: “{{ username }}”
    dnac_password: “{{ password }}”
    dnac_verify: false
    dnac_port: 443
    dnac_version: “2.3.3.0”
    site:
    building:
    address: “{{ item.address }}”
    country: “{{ item.country }}”
    latitude: “{{ (item.latitude | float) }}”
    longitude: “{{ (item.longitude | float) }}”
    name: “{{ item.name }}”
    parentName: “{{ item.parent_name }}”
    type: “{{ item.site_type }}”
    loop: “{{ sites }}”
    when: item.site_type == ‘building’

YAML Data

vars file for dnac-create-site-hierarchy

sites:

North America

  • name: “US”
    site_type: “area”
    parent_name: “Global”
  • name: “Big Campus”
    site_type: “area”
    parent_name: “Global/US”
  • name: “Big_bldg”
    site_type: “building”
    address: “2222 Big Dr.”
    country: “United States”
    latitude: 44.22222
    longitude: -111.11111
    parent_name: “Global/US/Big Campus”

Error Message returned from the Cisco DNAC SDK which is required for the Cisco.DNAC Ansible Module

raise MalformedRequest(
dnacentersdk.exceptions.MalformedRequest: {‘type’: ‘building’, ‘site’: {‘building’: {‘address’: ‘2222 Big Dr.’, ‘country’: ‘United States’, ‘latitude’: ‘44.22222’, ‘longitude’: ‘-111.11111’, ‘name’: ‘Big_bldg’, ‘parentName’: ‘Global/US/Big Campus’}}} is invalid. Reason: data.site.building.latitude must be number
failed: [dna-center-lab] (item={‘name’: ‘Big_bldg’, ‘site_type’: ‘building’, ‘address’: ‘2222 Big Dr.’, ‘country’: ‘United States’, ‘latitude’: 44.22222, ‘longitude’: -111.11111, ‘parent_name’: ‘Global/US/Big Campus’}) => {
“ansible_loop_var”: “item”,
“item”: {
“address”: “2222 Big Dr.”,
“country”: “United States”,
“latitude”: 44.22222,
“longitude”: -111.11111,
“name”: “Big_bldg”,
“parent_name”: “Global/US/Big Campus”,
“site_type”: “building”
},
“msg”: “An error occured when executing operation. The error was: {‘type’: ‘building’, ‘site’: {‘building’: {‘address’: ‘2222 Big Dr.’, ‘country’: ‘United States’, ‘latitude’: ‘44.22222’, ‘longitude’: ‘-111.11111’, ‘name’: ‘Big_bldg’, ‘parentName’: ‘Global/US/Big Campus’}}} is invalid. Reason: data.site.building.latitude must be number”
}

Thank you,

Paul

It seems like a bug to me, but according to https://github.com/cisco-en-programmability/dnacenter-ansible/blob/main/plugins/modules/site_create.py latitude and longitude are both type int, not float.

Thank you for the input. Agreed on the variable type, but it will take a float if hard coded. You won’t get very accurate location without some decimal places. 0.1 is about 9 miles. I’ll see about submitting a bug report.

Paul