Ansible将两个嵌套的json文件合并为json格式的单个文件

Ansible将两个嵌套的json文件合并为json格式的单个文件,json,ansible,append,Json,Ansible,Append,我有两个json,希望将一个附加到另一个json中,并将它们保存在一个文件中。我已经做了一系列的工作来读取这些值,并使用以下方法将它们放入变量中: - name: Set json combine to add new event set_fact: event_json_create: "{{ lookup('file', 'event_template.json') }}" - name: Set json combine to get the existing list

我有两个json,希望将一个附加到另一个json中,并将它们保存在一个文件中。我已经做了一系列的工作来读取这些值,并使用以下方法将它们放入变量中:

- name: Set json combine to add new event
  set_fact:
     event_json_create: "{{ lookup('file', 'event_template.json') }}" 

- name: Set json combine to get the existing list of events
  set_fact:
     event_json_existing: "{{ lookup('file', 'notification.json') }}" 
现在,我想将event_json_create附加到event_json_existing

事件_json_create如下所示:

"event_json_create": {
    "LambdaFunctionConfigurations": [{
        "Events": [
            "s3:ObjectCreated:*"
        ],
        "Filter": {
            "Key": {
                "FilterRules": [{
                    "Name": "prefix",
                    "Value": [
                        "keying_service/response/"
                    ]
                }]
            }
        },
        "LambdaFunctionArn": "arn:aws:lambda:us-east-1:*******:function:xyz"
    }]
}
"event_json_existing": {
           "LambdaFunctionConfigurations": [
               {
                   "Events": [
                       "s3:ObjectCreated:*"
                   ],
                   "Filter": {
                       "Key": {
                           "FilterRules": [
                               {
                                   "Name": "Prefix",
                                   "Value": "staging/inbound/Source_Contact/ac/input_fia/"
                               }
                           ]
                       }
                   },
                   "Id": "Eventtry",
                   "LambdaFunctionArn": "arn:aws:lambda:us-east-1:******:function:abc"
               }
           ]
       }
事件_json_existing如下所示:

"event_json_create": {
    "LambdaFunctionConfigurations": [{
        "Events": [
            "s3:ObjectCreated:*"
        ],
        "Filter": {
            "Key": {
                "FilterRules": [{
                    "Name": "prefix",
                    "Value": [
                        "keying_service/response/"
                    ]
                }]
            }
        },
        "LambdaFunctionArn": "arn:aws:lambda:us-east-1:*******:function:xyz"
    }]
}
"event_json_existing": {
           "LambdaFunctionConfigurations": [
               {
                   "Events": [
                       "s3:ObjectCreated:*"
                   ],
                   "Filter": {
                       "Key": {
                           "FilterRules": [
                               {
                                   "Name": "Prefix",
                                   "Value": "staging/inbound/Source_Contact/ac/input_fia/"
                               }
                           ]
                       }
                   },
                   "Id": "Eventtry",
                   "LambdaFunctionArn": "arn:aws:lambda:us-east-1:******:function:abc"
               }
           ]
       }
如何将这两个json附加到ansible中,确保这两个json都在主组:lambdFunctionConfiguration下,然后将其写入json文件中。因此,我期望的结果是:

{
    "LambdaFunctionConfigurations": [{
            "Events": [
                "s3:ObjectCreated:*"
            ],
            "Filter": {
                "Key": {
                    "FilterRules": [{
                        "Name": "prefix",
                        "Value": [
                            "keying_service/response/"
                        ]
                    }]
                }
            },
            "LambdaFunctionArn": "arn:aws:lambda:us-east-1:*******:function:xyz"
        },
        {
            "Events": [
                "s3:ObjectCreated:*"
            ],
            "Filter": {
                "Key": {
                    "FilterRules": [{
                        "Name": "Prefix",
                        "Value": "staging/inbound/Source_Contact/ac/input_fia/"
                    }]
                }
            },
            "Id": "Eventtry",
            "LambdaFunctionArn": "arn:aws:lambda:us-east-1:*******:function:abc"
        }
    ]
}
请帮忙

此模板

shell> cat events.json.j2
{{ events|to_nice_json }}
以及下面的任务

    - set_fact:
        events: "{{ {'LambdaFunctionConfigurations':
                     ([event_json_create.LambdaFunctionConfigurations.0] +
                      [event_json_existing.LambdaFunctionConfigurations.0])} }}"
    - template:
        src: events.json.j2
        dest: events.json
给予


这个步骤在这里用于什么?shell>cat events.json.j2{{{events}到{nice_json}我应该如何在ansible中使用以下命令?显示文件内容的首选命令是什么?请看一看。我已经修改了ques,希望在LambdaFunctionConfiguration下保留文件event_json_中的所有内容,并将新内容添加到其中。我在那里添加了TopicConfiguration作为另一个组。我将在json文件中打印内容。提前谢谢你的帮助你把问题改了,所以我的答案不再有效。这是行不通的。若要继续,您可能需要还原问题并打开一个新问题。请参阅。特别是,引用
Minimal:代码越多,人们发现问题的可能性就越小