简体   繁体   English

我可以在 community.aws.ec2_vpc_route_table Ansible 模块中使用 group_vars/all.yml 吗?

[英]Can I use group_vars/all.yml in community.aws.ec2_vpc_route_table Ansible Module?

For example, I want to take this example play below.比如下面我想拿这个例子来玩。

# demo_setup.yml
- hosts: localhost
  gather_facts: False
  tasks:
  - name: Set up NAT-protected route table
    community.aws.ec2_vpc_route_table:
      vpc_id: vpc-1245678
      region: us-west-1
      tags:
        Name: Internal
      subnets:
        - 'SMTP Subnet'
        - 'Database Subnet'
        - 'Bastion Subnet'
      routes:
        - dest: 0.0.0.0/0
          instance_id: "{{ nat.instance_id }}"

Then use the group_vars/all.yml to call my variables然后使用 group_vars/all.yml 调用我的变量

# group_vars/all.yml
vpc: vpc-1245678
region: us-west-1
igw: igw-036dde5c85EXAMPLE
subnet_list:
  -  name: 'SMTP Subnet'
  -  name: 'Database Subnet'
  -  name: 'Database Subnet' 
# demo_setup.yml
- hosts: localhost
  gather_facts: False
  tasks:
  - name: Set up NAT-protected route table
    community.aws.ec2_vpc_route_table:
      vpc_id: {{ vpc }}
      region: {{ region }}
      tags:
        Name: Internal
      subnets:
        - "{{ subnet_list }}"
      routes:
        - dest: 0.0.0.0/0
          instance_id: "{{ igw }}"

The problem I am having is how can I input my su.net_list and place it in the community.aws.ec2_vpc_route_table module.我遇到的问题是如何输入我的su.net_list并将其放在community.aws.ec2_vpc_route_table模块中。

Instead of making su.net_list as a list of dictionaries, just make it a list of strings.不要将su.net_list作为字典列表,而是将其作为字符串列表。 This will make your life easier.这将使您的生活更轻松。

subnet_list:
  -  SMTP Subnet
  -  Database Subnet
  -  Database Subnet2 
# demo_setup.yml
- hosts: localhost
  gather_facts: False
  tasks:
  - name: Set up NAT-protected route table
    community.aws.ec2_vpc_route_table:
      vpc_id: "{{ vpc }}"
      region: "{{ region }}"
      tags:
        Name: Internal
      subnets: "{{ subnet_list }}"
      routes:
        - dest: 0.0.0.0/0
          instance_id: "{{ igw }}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM