Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ansible继续在每次执行时创建多个API网关_Ansible_Aws Api Gateway - Fatal编程技术网

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:

这是我创建和部署AWSAPI网关的plabook内容。不知何故,Ansible在每次执行时都会不断创建重复的API网关,我不知道如何控制它

    - 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'') }}'