title: How to add and mount volumes for EC2 instance with Ansible
body: <p>I am trying to learn the Ansible with all my AWS stuff. So the first task which I want to do is creation the basic EC2 instance with mounted volumes.</p>
  <p>I wrote the Playbook according to Ansible docs, but it doesn't really work. My Playbook:</p>
  <pre><code># The play operates on the local (Ansible control) machine.
  - name: Create a basic EC2 instance v.1.1.0 2015-10-14
    hosts: localhost
    connection: local
    gather_facts: false
  
  # Vars.
    vars:
        hostname: Test_By_Ansible
        keypair: MyKey
        instance_type: t2.micro
        security_group: my security group   
        image: ami-d05e75b8                 # Ubuntu Server 14.04 LTS (HVM)
        region: us-east-1                   # US East (N. Virginia)
        vpc_subnet_id: subnet-b387e763      
        sudo: True
        locale: ru_RU.UTF-8
  
  # Launch instance. Register the output.
    tasks:
      - name: Launch instance
        ec2:
           key_name: &quot;{{ keypair }}&quot;
           group: &quot;{{ security_group }}&quot;
           instance_type: &quot;{{ instance_type }}&quot;
           image: &quot;{{ image }}&quot;
           region: &quot;{{ region }}&quot;
           vpc_subnet_id: &quot;{{ vpc_subnet_id }}&quot;
           assign_public_ip: yes
           wait: true
           wait_timeout: 500
           count: 1                         # number of instances to launch
           instance_tags:
              Name: &quot;{{ hostname }}&quot;
              os: Ubuntu
              type: WebService
        register: ec2
  
      # Create and attach a volumes.
      - name: Create and attach a volumes
        ec2_vol:
           instance: &quot;{{ item.id }}&quot;
           name: my_existing_volume_Name_tag
           volume_size: 1   # in GB
           volume_type: gp2
           device_name: /dev/sdf
           with_items: ec2.instances
        register: ec2_vol
  
      # Configure mount points.
      - name: Configure mount points - mount device by name
        mount: name=/system src=/dev/sda1 fstype=ext4 opts='defaults nofail 0 2' state=present
        mount: name=/data src=/dev/xvdf fstype=ext4 opts='defaults nofail 0 2' state=present
        
  </code></pre>
  <p>But this Playbook crushes on volumes mount with error:</p>
  <pre><code>fatal: [localhost] =&gt; One or more undefined variables: 'item' is undefined
  </code></pre>
  <p>How can I resolve this?</p>