title: Create EC2 Instance by Ansible Failed with ec2: error: unrecognized arguments:
body: <p>I am newbie to Ansible and follow <a href="https://djaodjin.com/blog/deploying-on-ec2-with-ansible.blog.html" rel="nofollow">this tutorial</a> to create a security group and an ec2 instance. The security group is created successfully, but creating ec2 instance is failed by ec2: </p>
  
  <blockquote>
    <p>error: unrecognized arguments:
    /home/ec2-user/.ansible/tmp/ansible-tmp-14244....</p>
  </blockquote>
  
  <p>I did set up aws credentials and asnsible variables properly as below</p>
  
  <pre><code># AWS Credentials
  export AWS_ACCESS_KEY_ID=xxx
  export AWS_SECRET_ACCESS_KEY=xxx
  
  # EC2 Environment Variables
  export ANSIBLE_HOSTS=/etc/ansible/ec2.py
  export EC2_INI_PATH=/etc/ansible/ec2.ini
  </code></pre>
  
  <p>The files and output are showed as follow. Any ideas for this issue? Thanks for your Help!</p>
  
  <pre><code>$ cat group_vars/all
  # Variables listed here are applicable to all host groups 
  key_name: sobrr-staging.pem
  aws_region: cn-north-1
  ami_id: ami-9e0c9ea7
  instance_type: m1.small
  
  $ cat basic-create.yml
  # Basic provisioning example
  - name: Create AWS resources
    hosts: localhost
    connection: local
    gather_facts: False
    tasks:
    - name: Create security group
      ec2_group:
        name: my-security-group
        description: "A Security group"
        region: "{{aws_region}}"
        rules:
          - proto: tcp
            type: ssh
            from_port: 22
            to_port: 22
            cidr_ip: 0.0.0.0/0
        rules_egress:
          - proto: all
            type: all
            cidr_ip: 0.0.0.0/0
      register: basic_firewall
  
    - name: debug basic_firewall
      debug: 'msg="{{ basic_firewall }}"'
  
    - name: create an EC2 instance
      local_action:
        module: ec2
        key_name: "{{key_name}}"
        region: "{{aws_region}}"
        group_id: "{{basic_firewall.group_id}}"
        instance_type: "{{instance_type}}"
        image: "{{ami_id}}"
        count: 1
        wait: yes
      register: basic_ec2
  
    - name: debug instance start
      debug: 'msg="{{ basic_ec2 }}"'
  </code></pre>
  
  <p>OUTPUT</p>
  
  <pre><code>ansible-playbook -i /etc/ansible/hosts -vvvv basic-create.yml
  /usr/lib64/python2.6/site-packages/Crypto/Util/number.py:57: PowmInsecureWarning: Not using mpz_powm_sec.  You should rebuild using libgmp &gt;= 5 to avoid timing attack vulnerability.
    _warn("Not using mpz_powm_sec.  You should rebuild using libgmp &gt;= 5 to avoid timing attack vulnerability.", PowmInsecureWarning)
  
  PLAY [Create AWS resources] ***************************************************
  
  TASK: [Create security group] *************************************************
  &lt;localhost&gt; region=cn-north-1 description=A Security group name=my-security-group
  &lt;localhost&gt;
  &lt;localhost&gt;
  &lt;localhost&gt; u'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /home/ec2-user/.ansible/tmp/ansible-tmp-1424461765.15-98406246607462/ec2_group; rm -rf /home/ec2-user/.ansible/tmp/ansible-tmp-1424461765.15-98406246607462/ &gt;/dev/null 2&gt;&amp;1']
  ok: [localhost] =&gt; {"changed": false, "group_id": "sg-63fae101"}
  
  TASK: [debug basic_firewall] **************************************************
  ok: [localhost] =&gt; {
      "msg": "{'invocation': {'module_name': u'ec2_group', 'module_args': ''}, 'changed': False, 'group_id': 'sg-63fae101'}"
  }
  
  TASK: [create an EC2 instance] ************************************************
  &lt;127.0.0.1&gt; instance_type=m1.small image=ami-9e0c9ea7 group_id=sg-63fae101 region=cn-north-1 key_name=sobrr-staging.pem
  &lt;127.0.0.1&gt;
  &lt;127.0.0.1&gt;
  &lt;127.0.0.1&gt;
  &lt;127.0.0.1&gt; u'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/env python /home/ec2-user/.ansible/tmp/ansible-tmp-1424461765.54-184834253412898/ec2 /home/ec2-user/.ansible/tmp/ansible-tmp-1424461765.54-184834253412898/arguments; rm -rf /home/ec2-user/.ansible/tmp/ansible-tmp-1424461765.54-184834253412898/ &gt;/dev/null 2&gt;&amp;1']
  failed: [localhost -&gt; 127.0.0.1] =&gt; {"failed": true, "parsed": false}
  usage: ec2 [-h] [--list] [--host HOST] [--refresh-cache]
  ec2: error: unrecognized arguments: /home/ec2-user/.ansible/tmp/ansible-tmp-1424461765.54-184834253412898/arguments
  
  
  FATAL: all hosts have already failed -- aborting
  
  PLAY RECAP ********************************************************************
             to retry, use: --limit @/home/ec2-user/basic-create.retry
  
  localhost                  : ok=2    changed=0    unreachable=0    failed=1
  </code></pre>