我正在尝试创建一个剧本或角色,让我可以使用 ansible by tag 启动之前停止的 EC2 实例(EC2 实例通过标签分配到清单中的静态组)。该ec2.ini文件已更改为还返回有关已停止实例的信息。到目前为止我见过的唯一类似的例子依赖于ec2_factsget instance_ids。
ansible 网站上的官方示例region假设和instance_ids已经提前已知/硬编码。
- name: Start sandbox instances
hosts: localhost
gather_facts: false
connection: local
vars:
instance_ids:
- 'i-xxxxxx'
- 'i-xxxxxx'
- 'i-xxxxxx'
region: us-east-1
tasks:
- name: Start the sandbox instances
ec2:
instance_ids: '{{ instance_ids }}'
region: '{{ region }}'
state: running
wait: True
vpc_subnet_id: subnet-29e63245
assign_public_ip: yes
role:
- do_neat_stuff
- do_more_neat_stuff
Run Code Online (Sandbox Code Playgroud)
最好是我正在寻找一种解决方案,例如,如果可能的话,我可以从动态库存中获取必要的变量。