vikramaditya234
vikramaditya234

Reputation: 1398

Ansible role: ERROR! no action detected in task

I am getting error using Ansible role aws-vpc-nat-gateway

I do: ansible-playbook create_nat_vpc.yml

I am getting this error while using this module:

ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.

The error appears to have been in '/vagrant/roles/aws-vpc-nat-gateway/tasks/main.yml': line 3, column 3, but may be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

# Creating a VPC with Public and Private subnet in a VPC and setup NAT gateway for the private network.

- name: setup vpc

^ here

The error appears to have been in '/vagrant/roles/aws-vpc-nat-gateway/tasks/main.yml': line 3, column 3, but may be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

# Creating a VPC with Public and Private subnet in a VPC and setup NAT gateway for the private network.

- name: setup vpc

^ here

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 key and secret is stored using aws config

ansible.cfg:

# ./ansible.cfg
[defaults]
library = /usr/share/ansible:library

What am I missing?

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') }}"

Upvotes: 0

Views: 3239

Answers (1)

techraf
techraf

Reputation: 68439

The Ansible role as defined in the repository is broken.


The file aws-vpc-nat-gateway/tasks/main.yml is a YAML file containing a list of plays (a playbook).

It is saved inside a structure for an Ansible role, in a tasks directory, where Ansible expects a YAML file containing only a list of tasks.

Ansible takes the first element, assumes it is a task, but does not find any action directive, so it throws an exception.


The file itself might work as a playbook though, so you can give it a try just by executing ansible-playbook main.yml (notice it includes variables through a relative path twice in separate plays).

Upvotes: 1

Related Questions