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

12 views
Skip to first unread message

Paul Bauer

unread,
Aug 17, 2023, 11:43:34 PM8/17/23
to Ansible Project
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

Todd Lewis

unread,
Aug 18, 2023, 10:12:53 AM8/18/23
to ansible...@googlegroups.com, uto...@gmail.com
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.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/84cec934-05e7-4ed8-a67a-44d35f83bb0cn%40googlegroups.com.

-- 
Todd

Paul Bauer

unread,
Aug 18, 2023, 1:57:44 PM8/18/23
to Ansible Project
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

Reply all
Reply to author
Forward
0 new messages