首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Ansible使用instance_interruption_behavior提供多个spot实例

使用Ansible使用instance_interruption_behavior提供多个spot实例
EN

Stack Overflow用户
提问于 2019-03-31 10:41:09
回答 1查看 963关注 0票数 3

我知道这似乎与过去提出的其他问题有关,但我觉得并非如此。你将对此作出判断。

我已经使用Ansible 1.5年了,我知道它不是提供基础设施的最佳工具,但是满足我的需求就足够了。

我正在使用AWS作为我的云提供商

是否有任何方法可以使Ansible提供相同类型的多个spot实例(类似于ec2 ansible模块中的count属性),将其设置为stop(behavior)而不是默认的终止

我的目标:

使用不同的EC2设置多个ec2_spot_requests实例。(每个实例都有请求),但我希望将其设置为stop(行为),而不是使用默认的终止instance_interruption_behavior。

到目前为止我所做的:

我知道Ansible有下面的模块来处理ec2基础结构。主要是

ec2. module.html

不要与ec2_instance模块混淆。

module.html

我可以像到目前为止所做的那样,使用ec2模块来设置spot实例,如下所示:

代码语言:javascript
复制
ec2:
  key_name: mykey
  region: us-west-1
  instance_type: "{{ instance_type }}"
  image: "{{ instance_ami }}"
  wait: yes
  wait_timeout: 100
  spot_price: "{{ spot_bid }}"
  spot_wait_timeout: 600
  spot_type: persistent
  group_id: "{{ created_sg.group_id }}"
  instance_tags:
    Name: "Name"
  count: "{{ my_count }}"
  vpc_subnet_id: " {{ subnet }}"
  assign_public_ip: yes
  monitoring: no
  volumes:
    - device_name: /dev/sda1
      volume_type: gp2
      volume_size: "{{ volume_size }}"

预问题:

上面的示例模块非常干净,允许我使用ec2模块和count属性根据自己的需求设置spot实例。

但是,它不允许我将instance_interruption_behavior设置为stop(除非我担心),它只是默认终止。

其他模块:

要在ec2_launch_template AnbleVersion2.8.0上发布(目前只在开发中可用),有一个名为:的新模块

module.html

这个模块为您提供更多的属性,这允许您使用ec2_instance模块的组合来设置所需的instance_interruption_behavior以停止(行为)。我就是这样做的:

代码语言:javascript
复制
- hosts: 127.0.0.1
  connection: local
  gather_facts: True
  vars_files:
    - vars/main.yml
  tasks:
    - name: "create security group"
      include_tasks: tasks/create_sg.yml

    - name: "Create launch template to support interruption behavior 'STOP' for spot instances"
      ec2_launch_template:
        name: spot_launch_template
        region: us-west-1
        key_name: mykey
        instance_type: "{{ instance_type }}"
        image_id: "{{ instance_ami }}"
        instance_market_options:
          market_type: spot
          spot_options:
            instance_interruption_behavior: stop
            max_price: "{{ spot_bid }}"
            spot_instance_type: persistent
        monitoring:
          enabled: no
        block_device_mappings:
          - device_name: /dev/sda1
            ebs:
              volume_type: gp2
              volume_size: "{{ manager_instance_volume_size }}"
      register: my_template

- name: "setup up a single spot instance"
  ec2_instance:
    instance_type: "{{ instance_type }}"
    tags:
      Name: "My_Spot"
    launch_template:
      id: "{{ my_template.latest_template.launch_template_id }}"
    security_groups:
      - "{{ created_sg.group_id }}"

主要问题:

从上面的代码片段中可以看出,ec2_launch_template Ansible模块不支持count属性,ec2_instance模块也不允许它。

是否有任何方法使ansible提供相同类型的多个实例(类似于ec2 ansible模块中的count属性)?

EN

回答 1

Stack Overflow用户

发布于 2019-03-31 12:51:24

通常,如果您同时管理大量EC2实例的副本,您可能希望使用自动缩放组EC2舰队

有一个助理秘书长模块,允许您通过ansible管理自动缩放组。这将允许您基于该启动模板部署多个EC2实例。

解决此问题的另一种技术是使用云层形成terraform模块,如果或terraform计划支持您想要做的事情。这还允许您在必要时在提供基础结构模板之前使用Jinja2模板语法进行一些巧妙的模板生成。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55440089

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档