Ansible converts dictionary to string while it should not.

23 views
Skip to first unread message

Niek

unread,
Nov 4, 2020, 9:04:24 AM11/4/20
to Ansible Project
Hi,

I'm having trouble with the cisco.mso.mso_schema module (Doc Page). 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

Felix Fontein

unread,
Nov 4, 2020, 9:22:50 AM11/4/20
to ansible...@googlegroups.com
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.*

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).

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

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

Cheers,
Felix

Niek

unread,
Nov 4, 2020, 9:54:48 AM11/4/20
to Ansible Project
Thank you for the quick response Felix, I have filed a bug in the repository.
Reply all
Reply to author
Forward
0 new messages