# How to encode a str on a AnsibleUnicode format?

**URL:** <https://forum.ansible.com/t/how-to-encode-a-str-on-a-ansibleunicode-format/24646>\
**Category:** Ansible Developer\
**Created:** [June 5, 2017, 1:01pm UTC](https://forum.ansible.com/t/how-to-encode-a-str-on-a-ansibleunicode-format/24646 "2017-06-05T13:01:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Juan\_Manuel\_Parrilla](https://avatars.discourse-cdn.com/v4/letter/j/f17d59/32.png) [@Juan\_Manuel\_Parrilla](https://forum.ansible.com/u/Juan_Manuel_Parrilla)\
**Post date:** [June 5, 2017, 1:01pm UTC](https://forum.ansible.com/t/how-to-encode-a-str-on-a-ansibleunicode-format/24646/1 "2017-06-05T13:01:05Z")

</div>

Hi there,

I’m trying to modify the assert module, but I am having some troubles.

The error says that the entry variables must be unicode, but encoding it still do not work.

I am trying to extend the “that” array with some values, the correct type of objects on the array are this:

`

[WARNING]: Failure using method (v2\_runner\_on\_ok) in callback plugin  
(\<ansible.plugins.callback.default.CallbackModule object at 0x7fea57a73610\>): \<class  
‘ansible.parsing.yaml.objects.AnsibleUnicode’\> is not JSON serializable

`

And this is the native unicode:

`

[WARNING]: Failure using method (v2\_runner\_on\_ok) in callback plugin  
(\<ansible.plugins.callback.default.CallbackModule object at 0x7f8dd9784610\>): \<type ‘unicode’\> is not JSON  
serializable

`

There is any way to encode a variable from string to AnsibleUnicode?

Thank in advance.

Best regards

---

<div class="post-metadata">

**Author:** ![Juan\_Manuel\_Parrilla](https://avatars.discourse-cdn.com/v4/letter/j/f17d59/32.png) [@Juan\_Manuel\_Parrilla](https://forum.ansible.com/u/Juan_Manuel_Parrilla)\
**Post date:** [June 5, 2017, 1:10pm UTC](https://forum.ansible.com/t/how-to-encode-a-str-on-a-ansibleunicode-format/24646/2 "2017-06-05T13:10:16Z")

</div>

The original error is the next:

`

TASK [[Assert Comparission] SUCCESS] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /home/jparrill/ownCloud/RedHat/RedHat\_Consulting/BBVA/repos/ansible-config-management/assert.yml:8  
fatal: [localhost]: FAILED! =\> {  
“failed”: true,  
“msg”: “The conditional check ‘5af5b95a8e0d6c0455abeb5e2d435380 != 21bfc66dfa05f9f531e50298ff422986’ failed. The error was: template error while templating string: unexpected char u’a’ at 7. String: {% if 5af5b95a8e0d6c0455abeb5e2d435380 != 21bfc66dfa05f9f531e50298ff422986 %} True {% else %} False {% endif %}”  
}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
localhost : ok=1 changed=0 unreachable=0 failed=1

`
