【发布时间】:2019-05-27 22:00:50
【问题描述】:
我正在尝试通过 Ansible 管理 AWS 安全组,并希望向它们添加标签。 谁能给我一个例子来说明如何做到这一点?
例如,我有一个安全组“test_security_group”,我想向该安全组添加一个标签“foo”。
根据 Ansible 文档,ec2_tag 模块可以工作,但到目前为止我还没有成功地将它与安全组一起使用。
【问题讨论】:
标签: amazon-web-services ansible
我正在尝试通过 Ansible 管理 AWS 安全组,并希望向它们添加标签。 谁能给我一个例子来说明如何做到这一点?
例如,我有一个安全组“test_security_group”,我想向该安全组添加一个标签“foo”。
根据 Ansible 文档,ec2_tag 模块可以工作,但到目前为止我还没有成功地将它与安全组一起使用。
【问题讨论】:
标签: amazon-web-services ansible
像这样:
- name: Create security group for app instances
local_action:
module: ec2_group
name: "http-everywhere"
description: "My Security Group"
vpc_id: "vpc=abcd1234"
region: "us-east-1"
rules:
- proto: tcp
from_port: 80
to_port: 80
cidr_ip: 0.0.0.0/0
register: aws_sg
- name: Tag the security group with a name
local_action:
module: ec2_tag
resource: "{{aws_sg.group_id}}"
region: "us-east-1"
state: present
tags:
Name: "My Security Group Name"
env: "production"
service: "web"
【讨论】:
从 ansible 2.4 开始,您可以直接指定标签
- name: Create ec2 security group
ec2_group:
name: SSH
description: SSH
vpc_id: "{{ default_vpc_id }}"
region: "{{ aws_region }}"
tags:
Name: SSH
Tag1: Value1
Tag2: Value2
rules:
- proto: tcp
ports:
- 22
cidr_ip: 0.0.0.0/0
【讨论】: