# Ansible converts dictionary to string while it should not.

**URL:** <https://forum.ansible.com/t/ansible-converts-dictionary-to-string-while-it-should-not/34154>\
**Category:** Ansible Project\
**Created:** [November 4, 2020, 2:04pm UTC](https://forum.ansible.com/t/ansible-converts-dictionary-to-string-while-it-should-not/34154 "2020-11-04T14:04:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niek1](https://avatars.discourse-cdn.com/v4/letter/n/cab0a1/32.png) [@Niek1](https://forum.ansible.com/u/Niek1)\
**Post date:** [November 4, 2020, 2:04pm UTC](https://forum.ansible.com/t/ansible-converts-dictionary-to-string-while-it-should-not/34154/1 "2020-11-04T14:04:24Z")

</div>

Hi,

I’m having trouble with the cisco.mso.mso\_schema module ([Doc Page](https://docs.ansible.com/ansible/latest/collections/cisco/mso/mso_schema_module.html#parameter-templates)). I can’t get the first example to work and I think I know why, but I don’t know if I can solve it. So let me explain my problem.

When I try to add a schema, using the example:

_- name: Add a new schema_  
_cisco.mso.mso\_schema:_  
_host: mso\_host_  
_username: admin_  
_password: SomeSecretPassword_  
_schema: schema1_  
_state: present_  
_templates:_  
_- name: template1_  
_displayName: template1_  
_tenantId: niek\_tenant_

I get an error back from the MSO:

_“msg”:“MSO Error 125: Malformed body”,_  
_“payload”:{_  
_“code”:125,_  
_“info”:{_  
_“obj[0]”:[_  
_“"{‘displayName’: ‘template1’, ‘name’: ‘template1’, ‘tenantId’: ‘niek\_tenant’}" is not an object”_  
_]_  
_},_  
_“message”:“Malformed body”_  
}

In the error message, you can see that quotes have been added around the dictionary that specifies the parameters of the template that is created with the schema. I also get the following warning from ansible when I run my playbook:

_[WARNING]: The value “templates: {‘displayName’: ‘template1’, ‘name’: ‘template1’, ‘tenantId’: ‘niek\_tenant’}” (type dict) was converted to “templates: u”{‘displayName’: ‘template1’, ‘name’: ‘template1’, ‘tenantId’: ‘niek\_tenant’}“” (type string). If this does not look like what you expect, quote the entire value to ensure it does not change._

I also tried adding a schema using a POST request outside of ansible to the MSO. This worked, and the body of my POST was:

_{_  
_“displayName”: “schema1”,_  
_“templates”: [_  
_{_  
_“name”: “template1”,_  
_“displayName”: “template1”,_  
_“tenantId”: “5fa29a543c0000e9c3a6ed80”_  
_}_  
_]_  
_}_

I think that the post request that ansible sends to the MSO is (Notice the extra quotes around the template definition):

_{_  
_“displayName”: “schema1”,_  
_“templates”: [_  
_ **"** {_  
_“name”: “template1”,_  
_“displayName”: “template1”,_  
_“tenantId”: “5fa29a543c0000e9c3a6ed80”_  
_} **"** _  
_]_  
_}_

Can someone tell me if I’m doing something wrong, or if this might be a bug in Ansible or in the used Cisco module?

**Version information:**  
Ansible version: 2.10.2  
Python3 version: 3.6.9  
Cisco.mso version: 1.0.0

Kind regards,  
Niek

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [November 4, 2020, 2:21pm UTC](https://forum.ansible.com/t/ansible-converts-dictionary-to-string-while-it-should-not/34154/2 "2020-11-04T14:21:50Z")

</div>

Hi,

> I'm having trouble with the cisco.mso.mso\_schema module (Doc Page  
> \<[https://docs.ansible.com/ansible/latest/collections/cisco/mso/mso\_schema\_module.html#parameter-templates&gt;\](https://docs.ansible.com/ansible/latest/collections/cisco/mso/mso_schema_module.html#parameter-templates&gt;%5C)).  
> I can't get the first example to work and I think I know why, but I  
> don't know if I can solve it. So let me explain my problem.
> 
> When I try to add a schema, using the example:
> 
> \*- name: Add a new schema \*  
> \*cisco.mso.mso\_schema: \*  
> \* host: mso\_host\*  
> \* username: admin \*  
> \* password: SomeSecretPassword \*  
> \* schema: schema1\*  
> \* state: present \*  
> \* templates: \*  
> \* - name: template1\*  
> \* displayName: template1 \*  
> \* tenantId: niek\_tenant\*
> 
> I get an error back from the MSO:
> 
> \*"msg":"MSO Error 125: Malformed body",\*  
> \*"payload":{\*  
> \* "code":125,\*  
> \* "info":{\*  
> \* "obj[0]":[\*  
> \* "\"{'displayName': 'template1', 'name': 'template1',  
> 'tenantId': 'niek\_tenant'}\" is not an object"\*  
> \* ]\*  
> \* },\*  
> \* "message":"Malformed body"\*  
> }
> 
> In the error message, you can see that quotes have been added around  
> the dictionary that specifies the parameters of the template that is  
> created with the schema. I also get the following warning from  
> ansible when I run my playbook:
> 
> \*[WARNING]: The value "templates: {'displayName': 'template1',  
> 'name': 'template1', 'tenantId': 'niek\_tenant'}" (type dict) was  
> converted to "templates: u"{'displayName': 'template1', 'name':  
> 'template1', 'tenantId': 'niek\_tenant'}"" (type string). If this  
> does not look like what you expect, quote the entire value to ensure  
> it does not change.\*

well, Ansible did what the mso\_schema module asked for, namely convert  
the list of dicts to a list of strings. See the documentation of the  
parameter  
([https://docs.ansible.com/ansible/latest/collections/cisco/mso/mso\_schema\_module.html#parameter-templates](https://docs.ansible.com/ansible/latest/collections/cisco/mso/mso_schema_module.html#parameter-templates)).

I think someone accidentally set the element type to string here. You  
should file a bug in the repository:  
[https://github.com/CiscoDevNet/ansible-mso](https://github.com/CiscoDevNet/ansible-mso)

The error was introduced in this commit:  
[https://github.com/CiscoDevNet/ansible-mso/commit/98f010a6889c45536b925a0b77a99e816922929e](https://github.com/CiscoDevNet/ansible-mso/commit/98f010a6889c45536b925a0b77a99e816922929e)

Cheers,  
Felix

---

<div class="post-metadata">

**Author:** ![Niek1](https://avatars.discourse-cdn.com/v4/letter/n/cab0a1/32.png) [@Niek1](https://forum.ansible.com/u/Niek1)\
**Post date:** [November 4, 2020, 2:54pm UTC](https://forum.ansible.com/t/ansible-converts-dictionary-to-string-while-it-should-not/34154/3 "2020-11-04T14:54:48Z")

</div>

Thank you for the quick response Felix, I have filed a bug in the repository.
