ec2 eni模块将ec2实例ID转换为列表并转换为字符串

时间:2019-06-21 10:11:04

标签: ansible

通过编写剧本创建ec2实例后

。我尝试在创建实例时将eni附加到该实例,但是却遇到错误,例如无效的实例ID。但是我将实例ID作为变量传递。实例ID以字符串格式转换。

- name: create an EC2 instance with SSD volume type
  ec2:
    key_name: standalone
    group: dmz
    instance_type: t2.micro
    region: "{{ aws_region }}"
    aws_access_key: "{{ aws_access_key }}"
    aws_secret_key: "{{ aws_secret_key }}"
    image: ami-01ed306a12b7d1c96
    assign_public_ip: yes
    vpc_subnet_id: "{{ my_public_subnet.subnet.id }}"
    volumes:
      - device_name: /dev/xvda
        volume_type: gp2  #insert the volume code here
        volume_size: 40  #size is in GB
      - device_name: /dev/xvdb
        volume_type: gp2  #insert the volume code here
        volume_size: 40  #size is in GB
      - device_name: /dev/xvdc
        volume_type: gp2  #insert the volume code here
        volume_size: 80  #size is in GB
    wait : true
    wait_timeout: 500
    group_id: security_group.group_id
    count_tag:
      Name: apacheserver
    exact_count: 1
  register: ec2
- name:               Set ec2 instance ID in variable
  set_fact:
    instance_ids: "{{ ec2.instance_ids }}"
    wait_timeout: 500
################################################ ## 3
- ec2_eni:
    subnet_id:  "{{ my_public_subnet.subnet.id }}"
    region: "{{ aws_region }}"
    aws_access_key: "{{ aws_access_key }}"
    aws_secret_key: "{{ aws_secret_key }}"
    security_groups: [ "sg-08d8d64b9bc1c92bb" ]
    state: present
    attached: yes
    instance_id: "{{  ec2.instance_ids   }}"

任务[vpc:ec2_eni] ********************************************* ****************************************************** ****************************************************** **********  [警告]:字符串字段中的值['i-0ebd2a684c5d87cfd'](类型列表)已转换为u“ ['i-0ebd2a684c5d87cfd']”(类型字符串)。如果这看起来不像你 期望,引用整个值以确保其不变。

致命:[localhost]:失败! => {“更改”:false,“ msg”:“无效ID:\” ['i-0ebd2a684c5d87cfd'] \“”}

PLAY RECAP ********************************************* ****************************************************** ****************************************************** **************** 本地主机:ok = 16更改= 1无法访问= 0失败= 1跳过= 0拯救了= 0忽略了= 0

0 个答案:

没有答案