Sorry if this already being asked before, but i can’t find any solution that match my problem..
I’m trying to convert the string that i have to integer:
- hosts: myhost
vars:
- variable1: 15
- variable2: "15"
- variable3: "{{ variable2 | int }}"
I tried to use variable2 (string) for calculation, so i convert it to int in variable3. But it failed with error message "Unexpected templating type error occurred on ({{ variable3 + 1 }}): coercing to Unicode: need string or buffer, int found"
So, i tried to use type_debug to find out each type of the 3 variable listed.
- variable1 is int
- variable2 is ansibleunicode
- variable3 is unicode
I don’t understand the difference between ansibleunicode and unicode or why it is listed as unicode instead of integer when i already convert it from string to integer using | int. What should I do?
>Solution :
Try the following.
- hosts: myhost
vars:
- variable1: 15
- variable2: "15"
tasks:
- name: test
debug: msg="{{ variable2 | int + 1}}"
delegate_to: localhost
output:
TASK [test] ***********************************************************************************************************************
ok: [remote -> localhost] => {
"msg": "16"
}