Ansible继续在每次执行时创建多个API网关
这是我创建和部署AWSAPI网关的plabook内容。不知何故,Ansible在每次执行时都会不断创建重复的API网关,我不知道如何控制它Ansible继续在每次执行时创建多个API网关,ansible,aws-api-gateway,Ansible,Aws Api Gateway,这是我创建和部署AWSAPI网关的plabook内容。不知何故,Ansible在每次执行时都会不断创建重复的API网关,我不知道如何控制它 - name: deploy API Gateway tags: deploy aws_api_gateway: state: present region: "{{ aws_region }}" swagger_file: swagger.yml stage:
- name: deploy API Gateway
tags: deploy
aws_api_gateway:
state: present
region: "{{ aws_region }}"
swagger_file: swagger.yml
stage: test
deploy_desc: test deployment
register: api_result
- debug:
var: api_result
- name: test api gateway endpoint
uri:
url: https://{{ api_result.api_id }}.execute-api.{{ aws_region }}.amazonaws.com/test
return_content: yes
register: webpage
- debug:
var: webpage
这是我的招摇过市文件:
---
swagger: "2.0"
info:
version: "2018-05-10T07:51:38Z"
title: "MyAPI"
description: "REST API"
host: "rijjh41w9e.execute-api.ap-south-1.amazonaws.com"
basePath: "/test"
schemes:
- "https"
paths:
/:
get:
produces:
- "application/json"
responses:
200:
description: "200 response"
schema:
$ref: "#/definitions/Empty"
x-amazon-apigateway-integration:
uri: "arn:aws:apigateway:ap-south-1:lambda:path/2015-03-31/functions/arn:aws:lambda:ap-south-1:174336093897:function:MyLambda/invocations"
responses:
default:
statusCode: "200"
passthroughBehavior: "when_no_match"
httpMethod: "POST"
contentHandling: "CONVERT_TO_TEXT"
type: "aws"
definitions:
Empty:
type: "object"
title: "Empty Schema"
请帮助我限制Ansible,这样它就不会在每次执行时都创建重复的API网关。好吧,据我所知,它还不受支持(始终创建)
在创建另一个api网关之前,您可以编写一个新模块,列出当前api网关(通过名称获取相关id)和删除(通过api_id)
@Koby Ben Mordechai说 根据文档,它还不受支持(总是创建),您可以编写一个新模块,列出当前api网关(通过名称获取相关id)并在创建另一个网关之前删除(通过api_id) 今天(~2019年夏天),如果未定义
api\u id
,将创建一个新端点;否则更新它(如果存在,您是所有者,…)
问题在于通过名称检索现有端点
可以通过库/aws\u api\u gateway\u get\u id.py
完成(灵感来源于原始版本):
ansible剧本中的用法:
- name: Get AWS API Gateway id if exist
aws_api_gateway_get_id:
name: the-api-endpoint-name
register: aws_api_gateway_get_id_result
- name: Deploying API endpoint
aws_api_gateway:
api_id: '{{ aws_api_gateway_get_id_result.api_id | default(omit, true) }}'
stage: default
swagger_text: '{{ lookup(''template'', ''swagger.yml.j2'') }}'
- name: Get AWS API Gateway id if exist
aws_api_gateway_get_id:
name: the-api-endpoint-name
register: aws_api_gateway_get_id_result
- name: Deploying API endpoint
aws_api_gateway:
api_id: '{{ aws_api_gateway_get_id_result.api_id | default(omit, true) }}'
stage: default
swagger_text: '{{ lookup(''template'', ''swagger.yml.j2'') }}'