gpt4 book ai didi

json - 如何解决警告 :The value 4 (type int) in a string field was converted to u'4' (type string) in Ansible?

转载 作者:行者123 更新时间:2023-12-04 15:43:05 25 4
gpt4 key购买 nike

我已经解码了 Ansible 剧本中的额外变量。我将额外的变量作为编码格式传递。我正在解码额外的变量并解析我代码中的键和值。代码是:

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"}"

我已将编码后的元变量作为 base64encode 传递,如下所示:

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 }}"

解码值后,我得到输出和警告:

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.

最佳答案

您可以在 ~/.ansible.cfg 的默认部分添加以下行

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

关于json - 如何解决警告 :The value 4 (type int) in a string field was converted to u'4' (type string) in Ansible?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57037832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com