Suganthan Raj
Suganthan Raj

Reputation: 1970

How to resolve WARNING:The value 4 (type int) in a string field was converted to u'4' (type string) in Ansible?

I have decoded the extra variables in an Ansible playbook. I am passing the extra variables as encoded format. I am decoding the extra variables and parsing the key and value in my code. The code is:

meta="{"hostname":"oracleserver","username":"root","password":"admin@123","new_disk":"/dev/sdb","vg_name":"ts","lv_name":"tsdev","mnt_point":"/dev/sdb1","lv_size":"3G"}"

I have passed the encoded meta var as base64encode as below:

ansible-playbook init.yml -e meta=eyJob3N0bmFtZSI6Im9yYWNsZXNlcnZlciIsInVzZXJuYW1lIjoicm9vdCIsInBhc3N3b3JkIjoiYWRtaW5AMTIzIiwibmV3X2Rpc2siOiIvZGV2L3NkYiIsInZnX25hbWUiOiJ0cyIsImx2X25hbWUiOiJ0c2RldiIsIm1udF9wb2ludCI6Ii9kZXYvc2RiMSIsImx2X3NpemUiOiIzRyJ9
- name: creating the custom inventory at run time   
  hosts: localhost
  tasks:
    - name: Getting the meta json data
      set_fact:
        decoded_meta_data: "{{ meta | b64decode }}"
    - name: extracting the  hostname from meta data
      set_fact:
        hostname: "{{ decoded_meta_data.hostname }}"
    - debug: msg="{{ decoded_meta_data}} {{ decoded_meta_data.hostname}} {{ decoded_meta_data.lv_size }}"

After decoding the value, I am getting the output and warning as:

PLAY [creating the custom inventory at run time] ****************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************
ok: [localhost]

TASK [Getting the meta json data] *******************************************************************************************************************
ok: [localhost]

TASK [extracting the  hostname from meta data] ******************************************************************************************************
ok: [localhost]

TASK [debug] ****************************************************************************************************************************************
ok: [localhost] => {
    "msg": "{'username': u'root', 'mnt_point': u'/dev/sdb1', 'new_disk': u'/dev/sdb', 'lv_name': u'tsdev', 'hostname': u'oracleserver', 'vg_name': u'ts', 'lv_size': u'3G', 'password': u'admin@123'} oracleserver 3G"
}

[WARNING]: The value 4 (type int) in a string field was converted to u'4' (type string). If this does not look like what you expect, quote the entire value to ensure it does not change.

Upvotes: 3

Views: 3148

Answers (1)

You can add the following lines in the the defaults section of ~/.ansible.cfg

/etc/ansible/ansible.cfg
[defaults]
string_conversion_action = ignore

Upvotes: 3

Related Questions