请考虑以下site.yml
---
- name: Deployment Playbook
hosts: localhost
connection: local
gather_facts: no
environment:
AWS_DEFAULT_REGION: "{{ lookup('env', 'AWS_DEFAULT_REGION') | default('us-east-1', true) }}"
tasks:
- import_tasks: tasks/network/vpc.yml
它运行tasks/network/vpc.yml
,它部署一个带有一对公共和私有子网的VPC,NAT&路线。定义如下:
---
# VPC
- name: This deploys a VPC with a pair of public and private subnets spread across two Availability Zones. It deploys an Internet gateway, with a default route on the public subnets. It deploys a pair of NAT gateways (one in each zone), and default routes for them in the private subnets.
cloudformation:
stack_name: prod-vpc
state: present
region: us-east-1
disable_rollback: true
template: templates/infrastructure/network/vpc.yml
template_parameters:
EnvironmentName: "{{ environment_name }}"
VpcCIDR: 10.40.0.0/16
PublicSubnet1CIDR: 10.40.8.0/21
PublicSubnet2CIDR: 10.40.16.0/21
PrivateSubnet1CIDR: 10.40.24.0/21
PrivateSubnet2CIDR: 10.40.32.0/21
tags:
Environment: "{{ env }}"
Name: prod-vpc
Stack: "{{ stack_name }}"
when: vpc_stack is defined
register: prod_vpc_stack
给定的任务应该运行云形成模板,但在执行时不会:
$ ansible --version
ansible 2.4.2.0
config file = None
configured module search path = [u'/Users/gaurish/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/Cellar/ansible/2.4.2.0_1/libexec/lib/python2.7/site-packages/ansible
executable location = /usr/local/bin/ansible
python version = 2.7.14 (default, Dec 10 2017, 14:22:32) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.38)]
$ ansible-playbook site.yml
PLAY [Deployment Playbook] **********************************************************************************************************************
TASK [This deploys a VPC with a pair of public and private subnets spread across two Availability Zones. It deploys an Internet gateway, with a default route on the public subnets. It deploys a pair of NAT gateways (one in each zone), and default routes for them in the private subnets.] ***
skipping: [localhost]
PLAY RECAP **************************************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=0
正如我可以看到的那样,ansible正在逃避任务。我只是不明白为什么。有谁知道吗?
答案 0 :(得分:1)
这看起来微不足道 - 任务应该运行when: vpc_stack is defined
,但vpc_stack
未在您在问题中发布的代码中的任何位置定义,因此任务将被跳过。