我有几个 ansible 脚本,它们为各种服务(如 consul、kong 和一些 ECS 任务)提供 EC2 实例。我目前可以过滤使用的实例ec2_remote_facts:
来收集需要额外存储和使用的实例ec2_vol:.
- name: Gather EC2 Facts
ec2_remote_facts:
region: "{{ region }}"
filters:
"things"
register: info
- name: ec2-ebs
ec2_vol:
instance: "{{ item.id }}"
volume_size: 5
volume_type: gp2
device_name: xvdd
region: "{{ region }}"
name: "ebs-{{ environmentName }}-{{ item.id }}"
register: volumes
with_items: "{{ info.instances }}"
- name: ecs-tag
ec2_tag:
resource: "{{ item.volume_id }}"
region: "{{ region }}"
state: present
tags:
Environment: "{{ environmentName }}"
with_items: "{{ volumes.results }}"
我的解决方案是仅使用shell:
ssh 单独进入每台机器并运行相当于:vgcreate blah xvdd; lvcreate blah-volume blah; format
在每台机器上的脚本。但是,如果没有大量工作,我不知道如何使其具有幂等性,并且如果我们进行扩展,自定义 shell 脚本的灵活性就会降低。
我找到了 ansible lvol:
,但它要求我在新的 ec2 机器上运行。我们正在执行hosts:localhost
,我认为这意味着我们只是在我的机器上通过 ansible 使用 aws-cli,这意味着我实际上无法访问 ec2 实例。