Unable to set up NFS on EC2 instances launched using Ansible

Hi,

I am unable to get NFS configured correctly on EC2 instances launched via the ‘ec2’ module in Ansible. When I launch instances using the exact same AMI from the AWS EC2 console, NFS works without a hitch.

First I’ll describe my setup, and then how to reproduce the problem. I’m running Ansible from a Mac OSX Yosemite version 10.10.3.

$ ansible --version
ansible 1.9.2

I was also able to reproduce the problem from a machine running Debian 8.1 with Ansible version 1.9.

This is the ansible playbook I’m using to launch 2 ec2 instances.

$ cat test-nfs.yml

  • hosts: localhost
    tasks:
  • ec2:
    key_name: my_key
    aws_region: us-east-1
    zone: us-east-1c
    image: ami-d05e75b8
    vpc_subnet_id: subnet-cba9efbc
    instance_type: t2.micro
    exact_count: 2
    count_tag:
    Name: nfs-test
    instance_tags:
    Name: nfs-test
    assign_public_ip: yes
    wait: yes

Launch two instances.

$ ansible-playbook -i ./ec2.py test-nfs.yml

Then, SSH into the first instance and set up NFS.

$ ssh ubuntu@
$ sudo mkdir -m 777 /test
$ sudo apt-get install nfs-kernel-server
$ sudo cat “/test *(rw,async,no_subtree_check)” >> /etc/exports
$ sudo service nfs-kernel-server restart

Attempt to mount NFS on the second instance.

$ sudo mkdir -m 777 /test
$ sudo apt-get install nfs-common
$ sudo mount :/test /test

The last step (mounting /test) hangs and times out if the instances were launched using the ansible ec2 module, but completes almost instantly when the instance are launched from the AWS EC2 console or using the AWS CLI.

$ aws ec2 run-instances --image-id ami-d05e75b8 --count 1 --instance-type t2.micro --key-name test --security-group-ids sg-8fd0f7eb --subnet-id subnet-cba9efbc

Any help would be greatly appreciated. I can provide additional information about the setup if requested.

Bug solved. I was not specifying the correct security group. I had confused ansible groups with ec2 security groups in my code.