【问题标题】:How to Terminate multiple ec2 instances belonging to same security group with ansible?如何使用ansible终止属于同一安全组的多个ec2实例?
【发布时间】:2020-07-18 09:12:23
【问题描述】:

我刚刚开始在我的一些项目中使用 Ansible。对于测试脚本,我使用 ansible 创建了 57 个 ec2 实例。 所有这些实例都具有相同的安全组,使用 ansible 通过实例 id 终止它们将是一项繁琐的任务。有没有办法根据一些常见因素(如安全组或密钥对)使用 ansible 终止这些实例。我可以终止所有具有相同安全组或具有相同密钥对的实例,但它们的实例 ID 没有使用 ansible?

这是我用来创建这些实例的代码 sn-p。

---
  - name: Launching the AWS instance
    hosts: localhost
    tasks:
            - name: Launching the AWS instance
              ec2:
                      key_name: Ansible
                      region: ap-south-1
                      instance_type: t2.micro
                      image: ami-0620d12a9cf777c87
                      group: Akshay_ansible
                      count: 57
                      aws_access_key: XXXXXXXXXXXXXXXXXXXX
                      aws_secret_key: XXXXXXXXXXXXXXXXXXXXXXXXXXXX

【问题讨论】:

    标签: amazon-web-services amazon-ec2 ansible yaml


    【解决方案1】:

    可以使用ec2_instance 模块来完成。

    - ec2_instance:
        state: absent
        filters:
          key-name: Ansible
    

    有关可以使用的过滤器列表,请参阅请求参数here下的过滤器部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-30
      • 1970-01-01
      • 2018-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-25
      • 1970-01-01
      相关资源
      最近更新 更多