我想循环并将查找/csv文件的字段合并到列表中。
以下是CSV文件示例并读入列表(hosts_list
)
id,hostname,host_ip,country_code,country_name
ID01,myhost1,10.2.3.2,US,United States
ID02,myhost2,10.2.3.3,US,United States
ID03,myhost3,10.2.3.4,UK,United Kingdom
ID04,myhost3,10.2.3.4,US,United Kingdom
预期输出为
['US-myhost1', 'US-myhost2', 'US-myhost3']
我用了两种方法
一个二个一个一个
有没有更好/更有效的方法来做到这一点?
2条答案
按热度按时间balp4ylt1#
简而言之:
如果没有
jmespath
/json_query
可用,最终可以将上面的vars
部分替换为:在这两种情况下,使用上述CSV内容,我们得到:
gdx19jrr2#
使用Jinja模板。例如,
给予
完整的测试行动手册示例
给予