我正在一个Ansible项目中,我想在其中将通过tag-Name找到的现有EC2实例添加到我的自动缩放组中。我能够通过AMI或终止旧实例来找到它。但是我只是在寻找一种将它们添加到自动缩放组的方法,就像在Web管理控制台中一样。在我只需右键单击实例的地方,选择设置,将其附加到自动缩放组。以下代码全部在1个文件中。
查找EC2实例:
- hosts: localhost
connection: local
gather_facts: no
tasks:
- ec2_remote_facts:
region: eu-central-1
filters:
"tag:Name": Ubuntu_From_AMI
register: ec2found
- name: Add found instances to group
add_host: hostname="{{ item.public_ip_address }}" groups=ec2instances
with_items: "{{ ec2found.instances }}"
这是我添加自动缩放组的方式:
- hosts: localhost
connection: local
gather_facts: no
tasks:
- name: Add auto-scaling groups.
ec2_asg:
name: magento_scaling_group
load_balancers: 'LB_NAME'
availability_zones: [ 'eu-central-1a', 'eu-central-1b', 'eu-central-1c' ]
launch_config_name: "{{ lc.name }}"
min_size: 0
max_size: 5
desired_capacity: 0
vpc_zone_identifier: [ 'subnet-e712ad8c', 'subnet-e12e8dac', 'subnet-28e91a55' ]
tags:
- environment: production
propagate_at_launch: no
有可能吗?谢谢。
答案 0 :(得分:1)
基于the current list of modules,似乎没有此类功能。您需要create a new module或仅作弊并在常规command:
调用中使用aws cli
。如果您打算创建一个新模块,请考虑将其作为PR提交给Ansible项目,以便其他人将从您的工作中受益。