将公共IP创建到使用Ansible创建的EC2实例



在从剧本中创建AWS实例时,我试图将弹性IP连接到服务器上。并且正在遇到此错误。


致命:[Localhost]:失败!=> { " msg":"'dict对象'没有属性'instance_ids'"} 要重试,使用: - limit @/home/ubuntu/aws.retry



  • 名称:AWS实例创建主持人:本地连接:本地gather_facts:truevars: OS_IMAGE:AMI-063AA838BD7631E0B 位置:US-West-1 PEM:recippeeps-c VPC_SUBNET:子网FC5664A7 server_name:sagar测试 instance_type:t2.micro FireWall_Name:Sagar 描述:sagar_test_rule 计数:1

    任务:

      - name: ec2 security group
        ec2_group:
                name: "{{firewall_name}}"
                region: "{{location}}"
                description: "{{description}}"
                state: present
                rules:
                        - proto: tcp
                          from_port: 80
                          to_port: 80
                          cidr_ip: 0.0.0.0/0
                        - proto: tcp
                          from_port: 22
                          to_port: 22
                          cidr_ip: 0.0.0.0/0
                        - proto: tcp
                          from_port: 443
                          to_port: 443
                          cidr_ip: 0.0.0.0/0
        register: firewall
      - name: Debug firewall facts
        debug: msg="{{firewall}}"
    
      - name: creating AWS instance
        ec2:
                key_name: "{{pem}}"
                instance_type: "{{instance_type}}"
                region: "{{location}}"
                image: "{{os_image}}"
                termination_protection: no
                group_id: "{{firewall.group_id}}"
                wait: true
                count: "{{count}}"
                instance_tags:
                        Name: "{{server_name}}"
                        state: present
                vpc_subnet_id: "{{vpc_subnet}}"
                assign_public_ip: yes
        register: ec2
      - name: Debug EC2 facts
        debug: msg="{{ec2}}"
    
      - name: Providing a Static IP
        ec2_eip:
                in_vpc: yes
                reuse_existing_ip_allowed: yes
                region: "{{location}}"
                device_id: "{{ec2.instance_ids}}"
                wait_timeout: "20"
    

错误是明确的

"'dict对象'没有属性'instance_ids'

尝试使用它

    device_id: "{{ ec2.instance_ids }}"

您注册并打印 EC2

  register: ec2
- name: Debug EC2 facts
  debug: msg="{{ ec2 }}"

看看 instance_ids 是,或post ec2

相关内容

  • 没有找到相关文章

最新更新