- name: Web Security group
ec2_group:
name: "{{ vpc_name }}-web-db-sg"
state: present
description: Security group for RDS servers in the VPC
vpc_id: "{{vpc_id}}"
region: "{{ aws_region }}"
rules:
- proto: tcp
group_id: "{{ item }}"
ports:
- 5432
- 3306
- 1433
with_items: "{{public_sg_ids}}"
register: web_sg
这是我尝试运行的代码片段,但无法运行。我的目标是为AWS安全组制定三个规则,其中public_sg_ids是三个公共安全组['sg-03198a28b7edf1f0e','sg-038b16577691b2d2f','sg-047fe11a7290946b5']的列表。 错误是
The task includes an option with an undefined variable. The error was: 'item' is undefined
答案 0 :(得分:0)
检查您的缩进:
- name: Web Security group
ec2_group:
name: "{{ vpc_name }}-web-db-sg"
state: present
description: Security group for RDS servers in the VPC
vpc_id: "{{vpc_id}}"
region: "{{ aws_region }}"
rules:
- proto: tcp
group_id: "{{ item }}"
ports:
- 5432
- 3306
- 1433
with_items: "{{public_sg_ids}}"
register: web_sg
有关Loops
的更多示例,请参见Documentation
答案 1 :(得分:0)
我会使用“循环”而不是“ with_items”