Ansible:如何根据列表中的特定单词将列表转换/过滤为字典

森蒂尔·库马尔 BK

我有一个列表,需要根据列表List:input 中的特定单词将该列表转换/过滤为字典

 [
        "[profile appdev]\r\nArn: aaa.dev:333:iam\r\nRegion: ap.southeast2\r\n\r\n",
        "[profile applead]\r\nArn: aaa.techlead:333:iam\r\nRegion: ap.southeast2\r\n\r\n",
        "[profile appprod]\r\nArn: aaa.techlead:333:iam\r\nRegion: ap.southeast2\r\n\r\n",
        "[profile apppadmin]\r\nArn: aaa.techlead:333:iam\r\nRegion: ap.southeast2\r\n\r\n",
        "[profile appsupport]\r\nArn: aaa.dev:333:iam\r\nRegion: ap.southeast2\r\n\r\n",
        "[profile appguest]\r\nArn: aaa.techlead:433:iam\r\nRegion: ap.southeast3"
 ]

字典:输出

{
[profile appdev]:"profile appdev]\r\nArn: aaa.dev:333:iam\r\nRegion: ap.southeast2\r\n\r\n",
[profile applead]:"[profile applead]\r\nArn: aaa.techlead:333:iam\r\nRegion: ap.southeast2\r\n\r\n"
[profile appprod]:"[profile appprod]\r\nArn: aaa.techlead:333:iam\r\nRegion: ap.southeast2\r\n\r\n",
[profile apppadmin]:"[profile apppadmin]\r\nArn: aaa.techlead:333:iam\r\nRegion: ap.southeast2\r\n\r\n",
[profile appsupport]:"[profile appsupport]\r\nArn: aaa.dev:333:iam\r\nRegion: ap.southeast2\r\n\r\n",
[profile appguest]:"[profile appguest]\r\nArn: aaa.techlead:433:iam\r\nRegion: ap.southeast3"
}

是否可以在 Ansible 中实现

弗拉基米尔·博特卡

试试这个

    - set_fact:
        dict1: "{{ dict(keys|zip(list1)) }}"
      vars:
        regex: '(\[.*\])(.*)'
        replace: '\1'
        keys: "{{ list1|map('regex_replace', regex, replace)|list }}"

给定变量list1 中的列表,创建一个键列表。例如,使用mapregex_replace来创建列表然后使用dictzip创建字典。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何从熊猫字典中创建到特定单词列表的前5个接近单词的数据框

从python列表中查找特定单词

如何从值中过滤特定单词

如何根据特定的组合逻辑将列表字典转换为唯一字典列表?

我该如何过滤一个DataFrame,该DataFrame在Pandas的列中的特定单词列表之后保留行?

使用计数器创建列表中特定单词的字典

Ansible:如何从字典列表中过滤一些元素

如何根据Flutter中包含的单词过滤列表?

根据特定单词拆分字符串列表

如何突出显示符合条件的特定单元格或将其过滤为特定列表

将列表转换为字典 - Ansible YAML

如何根据值和列表过滤字典

根据列表中存在的键值过滤字典

如何在Oracle Apex中过滤给定单词的往返列表?

如何根据特定数字过滤列表字典的列表行?

如何将列表转换为以元组为键的字典

如何将列表(大小为一)转换为字典?

将列表中的列表转换为字典

Pyspark 将列表转换为特定列中的字典

如何根据特定单词将标题居中

如何在 LinkedList 中搜索特定单词并返回它在列表中的位置以及出现的次数

如何根据特定元素值在Haskell中过滤列表?

删除列表中的所有特定单词

使用 `stringr` 检测列表中的特定单词

在列表中搜索包含特定单词的字符串

Python - 如何转换字典列表中的列表

Ansible:如何将字符串列表转换为字典列表

如何从熊猫数据框中计算列表中的特定单词?

如何替换列表中的每第二个特定单词