I have seen this error multiple times during my Ansible playbooks execution but always ignored it because I always got the expected result.
Eventually, I wanted to get rid of any errors/warnings from my final version of the playbook and wanted to take care of this error as well. Hence I had to do little readings in this error/warning.
[WARNING]: The value 1 (type int) in a string field was converted to u'1' (type string). If this does not look like what you expect, quote the entire value to ensure it does not change.
As per the Ansible official documentation this is the Default behavior of starting Ansible version 2.8. Ansible will warn if a module expects a string, but a non-string value is passed and automatically converted to a string.
For example – If your playbook inputs a value version number
1.10 (parsed as float value) would be converted to
'1.1'. Such conversions can result in unexpected behavior depending on context and also will/might your playbook’s expected outcomes
There are two solutions to address this issue.
1. ANSIBLE_STRING_CONVERSION_ACTION Environment Variable
This behavior can be changed to be an error or to be ignored by setting the
ANSIBLE_STRING_CONVERSION_ACTION environment variable, or by setting the
string_conversion_action configuration in the
defaults section of
You can refer to this link to change the
string_conversion_action parameter in
defaults section of
Ansible.cfg. This will make sure Ansible will not change the input to
2. Quote the input values in playbook
I personally prefer this method instead of editing
Ansible.cfg file. To make sure you’re not getting string field conversion Warning message you can simply quote the input value. Below is the example for the same.
- name: Sample sysctl task sysctl: name: net.bridge.bridge-nf-call-iptables value: '1' state: present
Below are the playbook screen captures of before and after quoting the values in playbook
I hope this helps everyone.