错误:子网不是Ansible任务或处理程序中的合法参数

时间:2015-10-22 13:46:51

标签: yaml ansible ansible-playbook amazon-vpc

我是Ansible的新手,非常感谢我对我的剧本提供一些帮助。我想在AWS中创建一个带有2个子网的VPC。这是我得到的错误:

[root@aws]# ansible-playbook --syntax-check vpc_pub_pri.yml
playbook: vpc_pub_pri.yml
ERROR: subnets is not a legal parameter in an Ansible task or handler

任何帮助都会很棒〜干杯〜

---
- name: Provision a VPC with public/private subnets and an IGW
  hosts: local
  connection: local
  tasks:
  - name: Create 2 subnets
    module: ec2_vpc
    region: us-west-2
    cidr_block: 192.168.0.0/23
    resource_tags: { "Name":"vpc" }
    subnets:
      - cidr: 192.168.0.0/24
        az: us-west-2a
        resource_tags: { "Name":"public" }
      - cidr: 192.168.1.0/24
        az: us-west-2c
        resource_tags: { "Name":"private" }
    internet_gateway: True
    route_tables:
      - subnets:
          - 192.168.0.0/24
          - 192.168.1.0/24
        routes:
          - dest: 0.0.0.0/0
            gw: igw
    register: vpc

1 个答案:

答案 0 :(得分:0)

我不知道其余的参数是否正常,但这里的主要问题是缩进。子网等是ec2_vpc模块的参数。另外,我从未见过module:符号,可能没问题。但这应该有效:

---
- name: Provision a VPC with public/private subnets and an IGW
  hosts: local
  connection: local
  tasks:
  - name: Create 2 subnets
    ec2_vpc: 
      region: us-west-2
      cidr_block: 192.168.0.0/23
      resource_tags: { "Name":"vpc" }
      subnets:
        - cidr: 192.168.0.0/24
          az: us-west-2a
          resource_tags: { "Name":"public" }
        - cidr: 192.168.1.0/24
          az: us-west-2c
          resource_tags: { "Name":"private" }
      internet_gateway: True
      route_tables:
        - subnets:
            - 192.168.0.0/24
            - 192.168.1.0/24
          routes:
            - dest: 0.0.0.0/0
              gw: igw
    register: vpc