【发布时间】:2017-05-06 08:22:31
【问题描述】:
我在使用 Ansible 角色 aws-vpc-nat-gateway 时遇到错误
我愿意:ansible-playbook create_nat_vpc.yml
我在使用这个模块时遇到这个错误:
错误!任务中未检测到任何操作。这通常表示拼写错误 模块名称,或不正确的模块路径。
错误似乎出现在 '/vagrant/roles/aws-vpc-nat-gateway/tasks/main.yml':第 3 行,第 3 列, 但可能在文件中的其他位置,具体取决于确切的语法 问题。
违规行似乎是:
# 在 VPC 中创建具有公共子网和私有子网的 VPC,并为私有网络设置 NAT 网关。
- 名称:设置 vpc
^这里
错误似乎出现在 '/vagrant/roles/aws-vpc-nat-gateway/tasks/main.yml':第 3 行,第 3 列, 但可能在文件中的其他位置,具体取决于确切的语法 问题。
违规行似乎是:
# 在 VPC 中创建具有公共子网和私有子网的 VPC,并为私有网络设置 NAT 网关。
- 名称:设置 vpc
^这里
create_nat_vpc.yml:
---
- hosts: local
connection: local
sudo: no
gather_facts: yes
vars:
region: ap-southeast-2
cidr: 172.23.0.0/16
public_subnet: 172.23.0.0/24
private_subnet: 172.23.1.0/24
public_subnet_az: ap-southeast-2a
private_subnet_az: ap-southeast-2a
roles:
- aws-vpc-nat-gateway
AWS 密钥和秘密使用aws config 存储
ansible.cfg:
# ./ansible.cfg
[defaults]
library = /usr/share/ansible:library
我错过了什么?
aws-vpc-nat-gateway/tasks/main.yml
---
# Creating a VPC with Public and Private subnet in a VPC and setup NAT gateway for the private network.
- name: setup vpc
hosts: localhost
gather_facts: true
sudo_user: false
pre_tasks:
- include_vars: ../vars/main.yml
tasks:
- name: create VPC with public and private subnet
ec2_vpc:
state: present
cidr_block: '{{ cidr }}'
subnets:
- cidr: '{{ public_subnet }}'
az: '{{ public_subnet_az }}'
resource_tags: { "Subnet":"Public" }
- cidr: '{{ private_subnet }}'
az: '{{ private_subnet_az }}'
resource_tags: { "Subnet":"Private" }
internet_gateway: True
route_tables:
- subnets:
- '{{ public_subnet }}'
routes:
- dest: 0.0.0.0/0
gw: igw
region: '{{ region }}'
register: vpc
- name: Copy the file to /tmp
template: src=create-nat-gw.sh dest=/tmp/create-nat-gw.sh mode=0755
- name: Create NAT gateway by executing the script
shell: sh /tmp/create-nat-gw.sh
- name: Change the route for VPC Private Subnet
hosts: localhost
gather_facts: true
sudo_user: false
pre_tasks:
- include_vars: ../vars/main.yml
tasks:
- name: Modify private subnet
ec2_vpc_route_table:
vpc_id: '{{ vpc.vpc_id }}'
region: '{{ region }}'
subnets:
- "{{ lookup('file', '/tmp/private-subnet') }}"
routes:
- dest: 0.0.0.0/0
gateway_id: "{{ lookup('file', '/tmp/nat-gateway') }}"
【问题讨论】:
-
@techraf 谢谢,我错过了。谢谢指正:)
标签: amazon-web-services ansible