用值列表更新用户字典

时间:2019-02-27 17:22:00

标签: ansible

Ansible 2.7,服务器和目标正在运行ubuntu。

在我的剧本中,我有tr=pd.DataFrame({"Col1":[1,1,1,1,3,3],"Col2":[1,2,2,2,4,4]}) print (tr) 个字典列表:

users

我还提取了ok: [virtual_tournesol] => { "users": [ { "key": "toto", "value": [ "toto", "/home/toto/.ssh/id_rsa" ] }, { "key": "riri", "value": [ "www-data", "/home/riri/.ssh/id_rsa" ] } ] } 列表中生成的ssh密钥:

pubkeys

如何合并两个数据,以便仅使用ok: [virtual_tournesol] => { "pubkeys": [ "ssh-rsa XXX1 ansible-generated on tournesol", "ssh-rsa XXX2 ansible-generated on tournesol" ] } 才能继续执行任务?我希望得到:

users

编辑:在python中,它将给出类似的内容:

ok: [virtual_tournesol] => {
"users": [
    {
        "key": "toto",
        "value": [
            "toto",
            "/home/toto/.ssh/id_rsa",
            "ssh-rsa XXX1 ansible-generated on tournesol"
        ]
    },
    {
        "key": "riri",
        "value": [
            "www-data",
            "/home/riri/.ssh/id_rsa",
            "ssh-rsa XXX2 ansible-generated on tournesol"
        ]
    }
]
}

1 个答案:

答案 0 :(得分:1)

zip是一个不错的选择。下面的代码

spring:
  cloud:
    config:
      server:
        git: 
          uri: https://gitlab.com/somerepo.git
          username: someuser
          password: somepass
          default-label: branchname

给予

- set_fact:
    user1: "{{ user1|default({}) | combine(
             { item.0.key: item.0.value + [ item.1 ] } ) }}"
  loop: "{{ users|zip(pubkeys)|list }}"
- debug:
    msg: "{{ user1|dict2items }}"