<p dir="auto">Trying to launch ec2 instance using ansible 1.8.3 gives me:</p>
<p dir="auto">Traceback (most recent call last):<br>
File "/var/lib/jenkins/.ansible/tmp/ansible-tmp-1424337493.09-167968274609306/ec2", line 2998, in <br>
main()<br>
File "/var/lib/jenkins/.ansible/tmp/ansible-tmp-1424337493.09-167968274609306/ec2", line 1203, in main<br>
(tagged_instances, instance_dict_array, new_instance_ids, changed) = enforce_count(module, ec2)<br>
File "/var/lib/jenkins/.ansible/tmp/ansible-tmp-1424337493.09-167968274609306/ec2", line 682, in enforce_count<br>
= create_instances(module, ec2, override_count=to_create)<br>
File "/var/lib/jenkins/.ansible/tmp/ansible-tmp-1424337493.09-167968274609306/ec2", line 817, in create_instances<br>
params['tenancy'] = tenancy<br>
NameError: global name 'tenancy' is not defined</p>
<p dir="auto">Same recipe in the 1.8.2 works ok.</p>
<p dir="auto"><strong>Issue Type:</strong><br>
Bug Report</p>
<p dir="auto"><strong>Ansible Version:</strong><br>
1.8.3</p>
<p dir="auto"><strong>Environment:</strong><br>
Ubuntu 14.04  kernel: 3.13.0-45-generic</p>
<p dir="auto"><strong>Summary:</strong><br>
Cannot to create new AWS EC2 instance using ec2 module, the following failure is raised:<br>
NameError: global name 'tenancy' is not defined</p>
<p dir="auto"><strong>Steps To Reproduce:</strong></p>
<ol dir="auto">
<li>Have playbook like:</li>
</ol>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- hosts: localhost
  connection: local
  gather_facts: False
  tasks:
    # security groups, VPCs, and so on

    - ec2:
        region: &quot;{{ aws_region }}&quot;
        aws_secret_key: &quot;{{ aws_secret_key }}&quot;
        aws_access_key: &quot;{{ aws_access_key }}&quot;
        key_name: &quot;{{ aws_key_name }}&quot;
        instance_type: &quot;{{ item.instance_type }}&quot;
        instance_tags:
          Name: &quot;{{ item.name }}&quot;
        image: &quot;{{ item.image }}&quot;
        wait: yes
        group: &quot;{{ item.name }}&quot;
        exact_count: 1
        count_tag:
          Name: &quot;{{ item.name }}&quot;
        vpc_subnet_id: &quot;{{ vpc_subnet_id }}&quot;
        assign_public_ip: yes
      with_items:
        - name: existing_server1
          image: ami-f0b11187
          instance_type: t2.micro
        - name: existing_server2
          image: ami-f0b11187
          instance_type: t2.micro
        - name: new-server
          image: ami-f0b11187
          instance_type: t2.micro"><pre class="notranslate">- <span class="pl-ent">hosts</span>: <span class="pl-s">localhost</span>
  <span class="pl-ent">connection</span>: <span class="pl-s">local</span>
  <span class="pl-ent">gather_facts</span>: <span class="pl-c1">False</span>
  <span class="pl-ent">tasks</span>:
    <span class="pl-c"><span class="pl-c">#</span> security groups, VPCs, and so on</span>

    - <span class="pl-ent">ec2</span>:
        <span class="pl-ent">region</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ aws_region }}<span class="pl-pds">"</span></span>
        <span class="pl-ent">aws_secret_key</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ aws_secret_key }}<span class="pl-pds">"</span></span>
        <span class="pl-ent">aws_access_key</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ aws_access_key }}<span class="pl-pds">"</span></span>
        <span class="pl-ent">key_name</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ aws_key_name }}<span class="pl-pds">"</span></span>
        <span class="pl-ent">instance_type</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ item.instance_type }}<span class="pl-pds">"</span></span>
        <span class="pl-ent">instance_tags</span>:
          <span class="pl-ent">Name</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ item.name }}<span class="pl-pds">"</span></span>
        <span class="pl-ent">image</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ item.image }}<span class="pl-pds">"</span></span>
        <span class="pl-ent">wait</span>: <span class="pl-s">yes</span>
        <span class="pl-ent">group</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ item.name }}<span class="pl-pds">"</span></span>
        <span class="pl-ent">exact_count</span>: <span class="pl-c1">1</span>
        <span class="pl-ent">count_tag</span>:
          <span class="pl-ent">Name</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ item.name }}<span class="pl-pds">"</span></span>
        <span class="pl-ent">vpc_subnet_id</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ vpc_subnet_id }}<span class="pl-pds">"</span></span>
        <span class="pl-ent">assign_public_ip</span>: <span class="pl-s">yes</span>
      <span class="pl-ent">with_items</span>:
        - <span class="pl-ent">name</span>: <span class="pl-s">existing_server1</span>
          <span class="pl-ent">image</span>: <span class="pl-s">ami-f0b11187</span>
          <span class="pl-ent">instance_type</span>: <span class="pl-s">t2.micro</span>
        - <span class="pl-ent">name</span>: <span class="pl-s">existing_server2</span>
          <span class="pl-ent">image</span>: <span class="pl-s">ami-f0b11187</span>
          <span class="pl-ent">instance_type</span>: <span class="pl-s">t2.micro</span>
        - <span class="pl-ent">name</span>: <span class="pl-s">new-server</span>
          <span class="pl-ent">image</span>: <span class="pl-s">ami-f0b11187</span>
          <span class="pl-ent">instance_type</span>: <span class="pl-s">t2.micro</span></pre></div>
<p dir="auto">2)run this playbook</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="ansible-playbook  stack.yml"><pre class="notranslate">ansible-playbook  stack.yml</pre></div>
<p dir="auto"><strong>Expected Results:</strong><br>
EC2 instance with tag Name: new-server is successfully created</p>
<p dir="auto"><strong>Actual Results:</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ok: [localhost] =&gt; (item={'instance_type': 't2.micro', 'image': 'ami-f0b11187', 'name': 'existing_server1'})
ok: [localhost] =&gt; (item={'instance_type': 't2.micro', 'image': 'ami-f0b11187', 'name': 'existing_server2'})
failed: [localhost] =&gt; (item={'instance_type': 't2.micro', 'image': 'ami-f0b11187', 'name': 'new-server'}) =&gt; {&quot;failed&quot;: true, &quot;item&quot;: {&quot;image&quot;: &quot;ami-f0b11187&quot;, &quot;instance_type&quot;: &quot;t2.micro&quot;, &quot;name&quot;: &quot;new-server&quot;}, &quot;parsed&quot;: false}
Traceback (most recent call last):
  File &quot;/home/provectus/.ansible/tmp/ansible-tmp-1424268793.19-187172363730612/ec2&quot;, line 2998, in &lt;module&gt;
    main()
  File &quot;/home/provectus/.ansible/tmp/ansible-tmp-1424268793.19-187172363730612/ec2&quot;, line 1203, in main
    (tagged_instances, instance_dict_array, new_instance_ids, changed) = enforce_count(module, ec2)
  File &quot;/home/provectus/.ansible/tmp/ansible-tmp-1424268793.19-187172363730612/ec2&quot;, line 682, in enforce_count
    = create_instances(module, ec2, override_count=to_create)
  File &quot;/home/provectus/.ansible/tmp/ansible-tmp-1424268793.19-187172363730612/ec2&quot;, line 817, in create_instances
    params['tenancy'] = tenancy
NameError: global name 'tenancy' is not defined"><pre lang="plain" class="notranslate"><code class="notranslate">ok: [localhost] =&gt; (item={'instance_type': 't2.micro', 'image': 'ami-f0b11187', 'name': 'existing_server1'})
ok: [localhost] =&gt; (item={'instance_type': 't2.micro', 'image': 'ami-f0b11187', 'name': 'existing_server2'})
failed: [localhost] =&gt; (item={'instance_type': 't2.micro', 'image': 'ami-f0b11187', 'name': 'new-server'}) =&gt; {"failed": true, "item": {"image": "ami-f0b11187", "instance_type": "t2.micro", "name": "new-server"}, "parsed": false}
Traceback (most recent call last):
  File "/home/provectus/.ansible/tmp/ansible-tmp-1424268793.19-187172363730612/ec2", line 2998, in &lt;module&gt;
    main()
  File "/home/provectus/.ansible/tmp/ansible-tmp-1424268793.19-187172363730612/ec2", line 1203, in main
    (tagged_instances, instance_dict_array, new_instance_ids, changed) = enforce_count(module, ec2)
  File "/home/provectus/.ansible/tmp/ansible-tmp-1424268793.19-187172363730612/ec2", line 682, in enforce_count
    = create_instances(module, ec2, override_count=to_create)
  File "/home/provectus/.ansible/tmp/ansible-tmp-1424268793.19-187172363730612/ec2", line 817, in create_instances
    params['tenancy'] = tenancy
NameError: global name 'tenancy' is not defined
</code></pre></div>