Ansible read_csv模块报错‘Key is not unique for value ''’问题排查
问题描述
我的Ansible Playbook此前可正常运行,近期未做任何修改却出现如下报错:
TASK [read_csv] ***************************************************** fatal: [localhost]: FAILED! => {"changed": false, "msg": "Key 'username' is not unique for value ''"}
对应的Playbook代码:
--- - name: Read User hosts: localhost tasks: - read_csv: path: opt/ansible.csv key: username fieldnames: username,usergroups,ipaddress,lastlogindate delimiter: ',' register: usersdata
使用的CSV文件内容示例:
| Username | User_groups | IP Address | Last Login Date |
|---|---|---|---|
| Apple | A | 192.34.50.183 | 12/4/2021 |
| Blizz | B | 192.34.50.145 | 3/8/2021 |
请问报错中的value ''是什么?为何使用'username'作为key会出错?
问题更新
我尝试了Vladimir Botka提供的Playbook,可成功运行,输出如下:
PLAY [Read User] *************************************************************** TASK [Gathering Facts] ********************************************************* ok: [localhost] TASK [read_csv] **************************************************************** ok: [localhost] TASK [debug] ******************************************************************* ok: [localhost] => { "usersdata.dict": {} } ...(省略中间输出) PLAY RECAP ********************************************************************* localhost : ok=13 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
之后我再次运行原Playbook,未做任何修改却不再报错,输出如下:
PLAY [Read User] *************************************************************** TASK [Gathering Facts] ********************************************************* ok: [localhost] TASK [read_csv] **************************************************************** ok: [localhost] PLAY RECAP ********************************************************************* localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
我认为该报错“Key is not unique for value ''”可能是由bug导致,运行触发usersdata变量输出字典和列表的Playbook后问题自行解决。已确认CSV中Username列无缺失值,也无重复的'username'内容。
内容的提问来源于stack exchange,提问作者Whaily
相关产品推荐
相关产品推荐

