【问题标题】:How to add tags to a elastic ip with ansible如何使用ansible将标签添加到弹性IP
【发布时间】:2020-01-08 11:31:36
【问题描述】:

如何将带有 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] (item=i-08d2c1fee9eef9001) => {"ansible_loop_var": “项目”,“更改”:假,“项目”:“i-08d2c1fee9eef9001”,“味精”: “(ec2_eip)模块不支持的参数:支持的标签 参数包括:allow_reassociation、aws_access_key、 aws_secret_key、debug_botocore_endpoint_logs、device_id、ec2_url、 in_vpc, private_ip_address, profile, public_ip, region, release_on_disassociation、reuse_existing_ip_allowed、security_token、 状态、验证证书、等待超时"}

【问题讨论】:

  • 你可以看看ec2_tag模块,它是用来标记AWS资源的。试试这个。 Link
  • @ShubhamVaishnav 能否举例说明ec2_tag 模块如何与ec2_eip 一起应用

标签: amazon-web-services ansible


【解决方案1】:

基于https://github.com/ansible/ansible/pull/55190,我认为目前无法使用 ansible 模块标记 EIP。

【讨论】:

  • 请提供有关链接资源内容的一些额外数据,因为此链接将来可能会停止工作...
【解决方案2】:

您可以使用 ec2_tag 模块来标记 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

【讨论】:

    猜你喜欢
    • 2020-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-18
    相关资源
    最近更新 更多