首页 » 翻译 » Ansible 入门 » 正文

ansible playbook 停止和启动亚马逊ec2主机

ansible playbook有一个ec2模块是专门给亚马逊云主机写的,因为云主机也频繁涉及停止,启动等相关的操作,


- name: Stop the node
local_action:
module: ec2
instance_ids: '{{ instance_id }}'
region: '{{ instance_region }}'
state: stopped
wait: True

其中,instance_id 是实例的id
instance_type 实例所属region

这两个都可以通过Dynamic Inventory 来获取到(http://docs.ansible.com/intro_dynamic_inventory.html)

需要注意的是wait选项,True是等待这个命令完成,即实例的状态为stopped


- name: Start the instance
local_action:
module: ec2
instance_ids: '{{ instance_id }}'
region: '{{ instance_region }}'
state: running
wait: True
register: running

启动同上

欢迎转载,转载请注明出处:http://www.503error.com/

Zhiming Zhang

Senior devops at Appannie
一个奔跑在运维路上的胖子
Zhiming Zhang

Latest posts by Zhiming Zhang (see all)