CuriousMind
CuriousMind

Reputation: 34145

Running Cloudformation with Ansible, skips tasks

Please consider the following 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

It runs tasks/network/vpc.yml, which deploys a VPC with a pair of public and private subnets, NAT & route. As defined below:

---

# 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

The given task should run a cloud formation template but it doesn't when I execute it:

   $ 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

As I can see for some reason, ansible is skipping the task. I just don't understand why. Does anyone know?

Upvotes: 0

Views: 78

Answers (1)

techraf
techraf

Reputation: 68519

This looks trivial — the task should run when: vpc_stack is defined, but vpc_stack is not defined anywhere in the code you posted in the question, hence the task gets skipped.

Upvotes: 1

Related Questions