运行 Cloudformation with Ansible,跳过任务

Running Cloudformation with Ansible, skips tasks

请考虑以下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

它运行s tasks/network/vpc.yml,它部署了一个带有一对public和私有子网、NAT和路由的VPC。定义如下:

---

# 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 正在跳过该任务。我只是不明白为什么。有人知道吗?

这看起来微不足道——任务应该 运行 when: vpc_stack is defined,但是 vpc_stack 没有在您在问题中发布的代码中的任何地方定义,因此任务被跳过。