代码之家  ›  专栏  ›  技术社区  ›  Rene B.

如何使用ansible向弹性ip添加标签

  •  0
  • Rene B.  · 技术社区  · 5 年前

    如何将ansible标签添加到分配的弹性ip。官方文件中没有任何信息:

    https://docs.ansible.com/ansible/latest/modules/ec2_eip_module.html

    示例代码如下所示:

    - name: provision new instances with ec2
      ec2:
        keypair: mykey
        instance_type: c1.medium
        image: ami-40603AD1
        wait: yes
        group: webserver
        count: 3
      register: ec2
    
    - name: associate new elastic IPs with each of the instances
      ec2_eip:
        device_id: "{{ item }}"
      loop: "{{ ec2.instance_ids }}"
    

    失败:[localhost](项目=i-08d2c1fee9eef9001)=>{“ansible_loop_var”: “项目”,“变更”:假,“项目”:“i-08d2c1fee9eef9001”,“信息”: 参数包括:allow_reassociation、aws_access_key、, 解除关联时释放,重用现有ip,安全令牌,

    0 回复  |  直到 5 年前
        1
  •  1
  •   user36585    4 年前

    您可以使用ec2_标记模块标记ec2资源。

    https://docs.ansible.com/ansible/latest/modules/ec2_tag_module.html#ec2-tag-module

    - name: associate new elastic IP with instance
      ec2_eip:
        device_id: "{{ l_ec2_instance_id }}"
      register: l_eip_register
    
    - name: tag the elastic IP
      ec2_tag:
        resource: "{{ l_eip_register.allocation_id }}"
        tags:
          Name: webserver