Repository: ansible/ansible

Issue:
Got Error when provisioning ec2
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
Boto
```
boto (2.46.1)
boto3 (1.4.4)
botocore (1.5.46)
```

##### ANSIBLE VERSION
```
  config file = 
  configured module search path = [u'/Users/user/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.13 (default, Apr  4 2017, 08:47:57) [GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)]
```

##### CONFIGURATION


##### OS / ENVIRONMENT
Mac OS X Sierra 10.12.4

##### SUMMARY
When try run ec2 provision

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
- name: Create a EC2 instance
  hosts: local
  roles:
    - ec2
```

```yaml
- name: Launch EC2 instance
  ec2:
    ec2_access_key: "{{ ec2_access_key }}"
    ec2_secret_key: "{{ ec2_secret_key }}"
    instance_type: t2.micro
    image: "{{ image_id }}"
    assign_public_ip: true
    keypair: "{{instances_keypair}}"
    vpc_subnet_id: "{{vpc_subnet_id}}"
    zone: "{{zone}}"
    group: Security_Group
    ec2_url: "{{ec2_url}}"
    instance_tags:
        Name: "Demo"
    exact_count: 1
    count_tag:
      Name: Demo
    volumes:
      - device_name: /dev/sda1
        volume_type: gp2
        volume_size: 16
  register: ec2_out
  notify: Add new instance to host group
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible/module_utils/basic.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible/module_utils/ec2.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible/module_utils/six/__init__.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible/module_utils/_text.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible/module_utils/pycompat24.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible/module_utils/cloud.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible/module_utils/six/_six.py
Using module file /usr/local/lib/python2.7/site-packages/ansible/modules/cloud/amazon/ec2.py
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: root
<localhost> EXEC /bin/sh -c 'echo ~ && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /Users/matheus/.ansible/tmp/ansible-tmp-1494271535.47-249816046272594 `" && echo ansible-tmp-1494271535.47-249816046272594="` echo /Users/matheus/.ansible/tmp/ansible-tmp-1494271535.47-249816046272594 `" ) && sleep 0'
<localhost> PUT /tmp/tmpIM5bXL TO /Users/matheus/.ansible/tmp/ansible-tmp-1494271535.47-249816046272594/ec2.py
<localhost> EXEC /bin/sh -c 'chmod u+x /Users/matheus/.ansible/tmp/ansible-tmp-1494271535.47-249816046272594/ /Users/matheus/.ansible/tmp/ansible-tmp-1494271535.47-249816046272594/ec2.py && sleep 0'
<localhost> EXEC /bin/sh -c 'python /Users/matheus/.ansible/tmp/ansible-tmp-1494271535.47-249816046272594/ec2.py; rm -rf "/Users/matheus/.ansible/tmp/ansible-tmp-1494271535.47-249816046272594/" > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_nSZPD5/ansible_module_ec2.py", line 1673, in <module>
    main()
  File "/tmp/ansible_nSZPD5/ansible_module_ec2.py", line 1667, in main
    (tagged_instances, instance_dict_array, new_instance_ids, changed) = enforce_count(module, ec2, vpc)
  File "/tmp/ansible_nSZPD5/ansible_module_ec2.py", line 932, in enforce_count
    reservations, instances = find_running_instances_by_count_tag(module, ec2, count_tag, zone)
  File "/tmp/ansible_nSZPD5/ansible_module_ec2.py", line 638, in find_running_instances_by_count_tag
    reservations = get_reservations(module, ec2, tags=count_tag, state="running", zone=zone)
  File "/tmp/ansible_nSZPD5/ansible_module_ec2.py", line 697, in get_reservations
    results = ec2.get_all_instances(filters=filters)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/ec2/connection.py", line 585, in get_all_instances
    max_results=max_results)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/ec2/connection.py", line 681, in get_all_reservations
    [('item', Reservation)], verb='POST')
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/connection.py", line 1170, in get_list
    response = self.make_request(action, params, path, verb)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/connection.py", line 1116, in make_request
    return self._mexe(http_request)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/connection.py", line 913, in _mexe
    self.is_secure)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/connection.py", line 705, in get_http_connection
    return self.new_http_connection(host, port, is_secure)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/connection.py", line 729, in new_http_connection
    host = boto.utils.parse_host(host)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/utils.py", line 1086, in parse_host
    hostname = hostname.strip()
AttributeError: 'NoneType' object has no attribute 'strip'

fatal: [localhost]: FAILED! => {
    "changed": false, 
    "failed": true, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_nSZPD5/ansible_module_ec2.py\", line 1673, in <module>\n    main()\n  File \"/tmp/ansible_nSZPD5/ansible_module_ec2.py\", line 1667, in main\n    (tagged_instances, instance_dict_array, new_instance_ids, changed) = enforce_count(module, ec2, vpc)\n  File \"/tmp/ansible_nSZPD5/ansible_module_ec2.py\", line 932, in enforce_count\n    reservations, instances = find_running_instances_by_count_tag(module, ec2, count_tag, zone)\n  File \"/tmp/ansible_nSZPD5/ansible_module_ec2.py\", line 638, in find_running_instances_by_count_tag\n    reservations = get_reservations(module, ec2, tags=count_tag, state=\"running\", zone=zone)\n  File \"/tmp/ansible_nSZPD5/ansible_module_ec2.py\", line 697, in get_reservations\n    results = ec2.get_all_instances(filters=filters)\n  File \"/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/ec2/connection.py\", line 585, in get_all_instances\n    max_results=max_results)\n  File \"/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/ec2/connection.py\", line 681, in get_all_reservations\n    [('item', Reservation)], verb='POST')\n  File \"/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/connection.py\", line 1170, in get_list\n    response = self.make_request(action, params, path, verb)\n  File \"/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/connection.py\", line 1116, in make_request\n    return self._mexe(http_request)\n  File \"/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/connection.py\", line 913, in _mexe\n    self.is_secure)\n  File \"/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/connection.py\", line 705, in get_http_connection\n    return self.new_http_connection(host, port, is_secure)\n  File \"/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/connection.py\", line 729, in new_http_connection\n    host = boto.utils.parse_host(host)\n  File \"/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/utils.py\", line 1086, in parse_host\n    hostname = hostname.strip()\nAttributeError: 'NoneType' object has no attribute 'strip'\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE", 
    "rc": 0
}

```

Got Error when provisioning ec2
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
Boto
```
boto (2.46.1)
boto3 (1.4.4)
botocore (1.5.46)
```

##### ANSIBLE VERSION
```
  config file = 
  configured module search path = [u'/Users/user/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.13 (default, Apr  4 2017, 08:47:57) [GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)]
```

##### CONFIGURATION


##### OS / ENVIRONMENT
Mac OS X Sierra 10.12.4

##### SUMMARY
When try run ec2 provision

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
- name: Create a EC2 instance
  hosts: local
  roles:
    - ec2
```

```yaml
- name: Launch EC2 instance
  ec2:
    ec2_access_key: "{{ ec2_access_key }}"
    ec2_secret_key: "{{ ec2_secret_key }}"
    instance_type: t2.micro
    image: "{{ image_id }}"
    assign_public_ip: true
    keypair: "{{instances_keypair}}"
    vpc_subnet_id: "{{vpc_subnet_id}}"
    zone: "{{zone}}"
    group: Security_Group
    ec2_url: "{{ec2_url}}"
    instance_tags:
        Name: "Demo"
    exact_count: 1
    count_tag:
      Name: Demo
    volumes:
      - device_name: /dev/sda1
        volume_type: gp2
        volume_size: 16
  register: ec2_out
  notify: Add new instance to host group
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible/module_utils/basic.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible/module_utils/ec2.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible/module_utils/six/__init__.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible/module_utils/_text.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible/module_utils/pycompat24.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible/module_utils/cloud.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible/module_utils/six/_six.py
Using module file /usr/local/lib/python2.7/site-packages/ansible/modules/cloud/amazon/ec2.py
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: root
<localhost> EXEC /bin/sh -c 'echo ~ && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /Users/matheus/.ansible/tmp/ansible-tmp-1494271535.47-249816046272594 `" && echo ansible-tmp-1494271535.47-249816046272594="` echo /Users/matheus/.ansible/tmp/ansible-tmp-1494271535.47-249816046272594 `" ) && sleep 0'
<localhost> PUT /tmp/tmpIM5bXL TO /Users/matheus/.ansible/tmp/ansible-tmp-1494271535.47-249816046272594/ec2.py
<localhost> EXEC /bin/sh -c 'chmod u+x /Users/matheus/.ansible/tmp/ansible-tmp-1494271535.47-249816046272594/ /Users/matheus/.ansible/tmp/ansible-tmp-1494271535.47-249816046272594/ec2.py && sleep 0'
<localhost> EXEC /bin/sh -c 'python /Users/matheus/.ansible/tmp/ansible-tmp-1494271535.47-249816046272594/ec2.py; rm -rf "/Users/matheus/.ansible/tmp/ansible-tmp-1494271535.47-249816046272594/" > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_nSZPD5/ansible_module_ec2.py", line 1673, in <module>
    main()
  File "/tmp/ansible_nSZPD5/ansible_module_ec2.py", line 1667, in main
    (tagged_instances, instance_dict_array, new_instance_ids, changed) = enforce_count(module, ec2, vpc)
  File "/tmp/ansible_nSZPD5/ansible_module_ec2.py", line 932, in enforce_count
    reservations, instances = find_running_instances_by_count_tag(module, ec2, count_tag, zone)
  File "/tmp/ansible_nSZPD5/ansible_module_ec2.py", line 638, in find_running_instances_by_count_tag
    reservations = get_reservations(module, ec2, tags=count_tag, state="running", zone=zone)
  File "/tmp/ansible_nSZPD5/ansible_module_ec2.py", line 697, in get_reservations
    results = ec2.get_all_instances(filters=filters)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/ec2/connection.py", line 585, in get_all_instances
    max_results=max_results)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/ec2/connection.py", line 681, in get_all_reservations
    [('item', Reservation)], verb='POST')
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/connection.py", line 1170, in get_list
    response = self.make_request(action, params, path, verb)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/connection.py", line 1116, in make_request
    return self._mexe(http_request)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/connection.py", line 913, in _mexe
    self.is_secure)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/connection.py", line 705, in get_http_connection
    return self.new_http_connection(host, port, is_secure)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/connection.py", line 729, in new_http_connection
    host = boto.utils.parse_host(host)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/utils.py", line 1086, in parse_host
    hostname = hostname.strip()
AttributeError: 'NoneType' object has no attribute 'strip'

fatal: [localhost]: FAILED! => {
    "changed": false, 
    "failed": true, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_nSZPD5/ansible_module_ec2.py\", line 1673, in <module>\n    main()\n  File \"/tmp/ansible_nSZPD5/ansible_module_ec2.py\", line 1667, in main\n    (tagged_instances, instance_dict_array, new_instance_ids, changed) = enforce_count(module, ec2, vpc)\n  File \"/tmp/ansible_nSZPD5/ansible_module_ec2.py\", line 932, in enforce_count\n    reservations, instances = find_running_instances_by_count_tag(module, ec2, count_tag, zone)\n  File \"/tmp/ansible_nSZPD5/ansible_module_ec2.py\", line 638, in find_running_instances_by_count_tag\n    reservations = get_reservations(module, ec2, tags=count_tag, state=\"running\", zone=zone)\n  File \"/tmp/ansible_nSZPD5/ansible_module_ec2.py\", line 697, in get_reservations\n    results = ec2.get_all_instances(filters=filters)\n  File \"/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/ec2/connection.py\", line 585, in get_all_instances\n    max_results=max_results)\n  File \"/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/ec2/connection.py\", line 681, in get_all_reservations\n    [('item', Reservation)], verb='POST')\n  File \"/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/connection.py\", line 1170, in get_list\n    response = self.make_request(action, params, path, verb)\n  File \"/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/connection.py\", line 1116, in make_request\n    return self._mexe(http_request)\n  File \"/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/connection.py\", line 913, in _mexe\n    self.is_secure)\n  File \"/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/connection.py\", line 705, in get_http_connection\n    return self.new_http_connection(host, port, is_secure)\n  File \"/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/connection.py\", line 729, in new_http_connection\n    host = boto.utils.parse_host(host)\n  File \"/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/utils.py\", line 1086, in parse_host\n    hostname = hostname.strip()\nAttributeError: 'NoneType' object has no attribute 'strip'\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE", 
    "rc": 0
}

```



Discussion:
Facing same issue while using ansible, boto :+1: 

boto version: boto (2.46.1)
python version: 2.7.5
ansible 2.3.0.0

The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_vdUaEk/ansible_module_ec2.py", line 1652, in <module>
    main()
  File "/tmp/ansible_vdUaEk/ansible_module_ec2.py", line 1643, in main
    (tagged_instances, instance_dict_array, new_instance_ids, changed) = enforce_count(module, ec2, vpc)
  File "/tmp/ansible_vdUaEk/ansible_module_ec2.py", line 909, in enforce_count
    reservations, instances = find_running_instances_by_count_tag(module, ec2, count_tag, zone)
  File "/tmp/ansible_vdUaEk/ansible_module_ec2.py", line 622, in find_running_instances_by_count_tag
    reservations = get_reservations(module, ec2, tags=count_tag, state="running", zone=zone)
  File "/tmp/ansible_vdUaEk/ansible_module_ec2.py", line 681, in get_reservations
    results = ec2.get_all_instances(filters=filters)
  File "/usr/lib/python2.7/site-packages/boto/ec2/connection.py", line 585, in get_all_instances
    max_results=max_results)
  File "/usr/lib/python2.7/site-packages/boto/ec2/connection.py", line 681, in get_all_reservations
    [('item', Reservation)], verb='POST')
  File "/usr/lib/python2.7/site-packages/boto/connection.py", line 1170, in get_list
    response = self.make_request(action, params, path, verb)
  File "/usr/lib/python2.7/site-packages/boto/connection.py", line 1116, in make_request
    return self._mexe(http_request)
  File "/usr/lib/python2.7/site-packages/boto/connection.py", line 913, in _mexe
    self.is_secure)
  File "/usr/lib/python2.7/site-packages/boto/connection.py", line 705, in get_http_connection
    return self.new_http_connection(host, port, is_secure)
  File "/usr/lib/python2.7/site-packages/boto/connection.py", line 729, in new_http_connection
    host = boto.utils.parse_host(host)
  File "/usr/lib/python2.7/site-packages/boto/utils.py", line 1086, in parse_host
    hostname = hostname.strip()
AttributeError: 'NoneType' object has no attribute 'strip'

fatal: [localhost]: FAILED! => {
    "changed": false, 
    "failed": true, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_vdUaEk/ansible_module_ec2.py\", line 1652, in <module>\n    main()\n  File \"/tmp/ansible_vdUaEk/ansible_module_ec2.py\", line 1643, in main\n    (tagged_instances, instance_dict_array, new_instance_ids, changed) = enforce_count(module, ec2, vpc)\n  File \"/tmp/ansible_vdUaEk/ansible_module_ec2.py\", line 909, in enforce_count\n    reservations, instances = find_running_instances_by_count_tag(module, ec2, count_tag, zone)\n  File \"/tmp/ansible_vdUaEk/ansible_module_ec2.py\", line 622, in find_running_instances_by_count_tag\n    reservations = get_reservations(module, ec2, tags=count_tag, state=\"running\", zone=zone)\n  File \"/tmp/ansible_vdUaEk/ansible_module_ec2.py\", line 681, in get_reservations\n    results = ec2.get_all_instances(filters=filters)\n  File \"/usr/lib/python2.7/site-packages/boto/ec2/connection.py\", line 585, in get_all_instances\n    max_results=max_results)\n  File \"/usr/lib/python2.7/site-packages/boto/ec2/connection.py\", line 681, in get_all_reservations\n    [('item', Reservation)], verb='POST')\n  File \"/usr/lib/python2.7/site-packages/boto/connection.py\", line 1170, in get_list\n    response = self.make_request(action, params, path, verb)\n  File \"/usr/lib/python2.7/site-packages/boto/connection.py\", line 1116, in make_request\n    return self._mexe(http_request)\n  File \"/usr/lib/python2.7/site-packages/boto/connection.py\", line 913, in _mexe\n    self.is_secure)\n  File \"/usr/lib/python2.7/site-packages/boto/connection.py\", line 705, in get_http_connection\n    return self.new_http_connection(host, port, is_secure)\n  File \"/usr/lib/python2.7/site-packages/boto/connection.py\", line 729, in new_http_connection\n    host = boto.utils.parse_host(host)\n  File \"/usr/lib/python2.7/site-packages/boto/utils.py\", line 1086, in parse_host\n    hostname = hostname.strip()\nAttributeError: 'NoneType' object has no attribute 'strip'\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE", 
    "rc": 0
@matheusvetor @chinni505
Do either of you get the same error if you use `region` instead of `ec2_url`? I'm having a hard time reproducing this error, but notice that ec2_url doesn't appear to be working right.
needs_info
Aha. Confirming this bug. To reproduce, unset your AWS_DEFAULT_REGION environment variable and use ec2_url in the playbook. Another error is generated if AWS_DEFAULT_REGION is set to another region than the one that corresponds with ec2_url. `ec2_url` is not taking precedence.
!needs_info
i used ec2_url:

ec2_url: "ec2.us-east-1.amazonaws.com"
while i tried with 
region: "us-east-1"
i am able to provision ec2 instance.
In general the ec2_uri parameter is intended for use with non-AWS clouds, such as Eucalyptus, so if you're on AWS I'd recommend sticking to the `region` or setting `AWS_REGION`. 

That said, this *shouldn't* be a problem, and it looks like it's coming from how we set up boto connections, but I'm not sure. Thanks for reporting!
Facing same issue while using ansible, boto :+1: 

boto version: boto (2.46.1)
python version: 2.7.5
ansible 2.3.0.0

The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_vdUaEk/ansible_module_ec2.py", line 1652, in <module>
    main()
  File "/tmp/ansible_vdUaEk/ansible_module_ec2.py", line 1643, in main
    (tagged_instances, instance_dict_array, new_instance_ids, changed) = enforce_count(module, ec2, vpc)
  File "/tmp/ansible_vdUaEk/ansible_module_ec2.py", line 909, in enforce_count
    reservations, instances = find_running_instances_by_count_tag(module, ec2, count_tag, zone)
  File "/tmp/ansible_vdUaEk/ansible_module_ec2.py", line 622, in find_running_instances_by_count_tag
    reservations = get_reservations(module, ec2, tags=count_tag, state="running", zone=zone)
  File "/tmp/ansible_vdUaEk/ansible_module_ec2.py", line 681, in get_reservations
    results = ec2.get_all_instances(filters=filters)
  File "/usr/lib/python2.7/site-packages/boto/ec2/connection.py", line 585, in get_all_instances
    max_results=max_results)
  File "/usr/lib/python2.7/site-packages/boto/ec2/connection.py", line 681, in get_all_reservations
    [('item', Reservation)], verb='POST')
  File "/usr/lib/python2.7/site-packages/boto/connection.py", line 1170, in get_list
    response = self.make_request(action, params, path, verb)
  File "/usr/lib/python2.7/site-packages/boto/connection.py", line 1116, in make_request
    return self._mexe(http_request)
  File "/usr/lib/python2.7/site-packages/boto/connection.py", line 913, in _mexe
    self.is_secure)
  File "/usr/lib/python2.7/site-packages/boto/connection.py", line 705, in get_http_connection
    return self.new_http_connection(host, port, is_secure)
  File "/usr/lib/python2.7/site-packages/boto/connection.py", line 729, in new_http_connection
    host = boto.utils.parse_host(host)
  File "/usr/lib/python2.7/site-packages/boto/utils.py", line 1086, in parse_host
    hostname = hostname.strip()
AttributeError: 'NoneType' object has no attribute 'strip'

fatal: [localhost]: FAILED! => {
    "changed": false, 
    "failed": true, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_vdUaEk/ansible_module_ec2.py\", line 1652, in <module>\n    main()\n  File \"/tmp/ansible_vdUaEk/ansible_module_ec2.py\", line 1643, in main\n    (tagged_instances, instance_dict_array, new_instance_ids, changed) = enforce_count(module, ec2, vpc)\n  File \"/tmp/ansible_vdUaEk/ansible_module_ec2.py\", line 909, in enforce_count\n    reservations, instances = find_running_instances_by_count_tag(module, ec2, count_tag, zone)\n  File \"/tmp/ansible_vdUaEk/ansible_module_ec2.py\", line 622, in find_running_instances_by_count_tag\n    reservations = get_reservations(module, ec2, tags=count_tag, state=\"running\", zone=zone)\n  File \"/tmp/ansible_vdUaEk/ansible_module_ec2.py\", line 681, in get_reservations\n    results = ec2.get_all_instances(filters=filters)\n  File \"/usr/lib/python2.7/site-packages/boto/ec2/connection.py\", line 585, in get_all_instances\n    max_results=max_results)\n  File \"/usr/lib/python2.7/site-packages/boto/ec2/connection.py\", line 681, in get_all_reservations\n    [('item', Reservation)], verb='POST')\n  File \"/usr/lib/python2.7/site-packages/boto/connection.py\", line 1170, in get_list\n    response = self.make_request(action, params, path, verb)\n  File \"/usr/lib/python2.7/site-packages/boto/connection.py\", line 1116, in make_request\n    return self._mexe(http_request)\n  File \"/usr/lib/python2.7/site-packages/boto/connection.py\", line 913, in _mexe\n    self.is_secure)\n  File \"/usr/lib/python2.7/site-packages/boto/connection.py\", line 705, in get_http_connection\n    return self.new_http_connection(host, port, is_secure)\n  File \"/usr/lib/python2.7/site-packages/boto/connection.py\", line 729, in new_http_connection\n    host = boto.utils.parse_host(host)\n  File \"/usr/lib/python2.7/site-packages/boto/utils.py\", line 1086, in parse_host\n    hostname = hostname.strip()\nAttributeError: 'NoneType' object has no attribute 'strip'\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE", 
    "rc": 0
@matheusvetor @chinni505
Do either of you get the same error if you use `region` instead of `ec2_url`? I'm having a hard time reproducing this error, but notice that ec2_url doesn't appear to be working right.
needs_info
Aha. Confirming this bug. To reproduce, unset your AWS_DEFAULT_REGION environment variable and use ec2_url in the playbook. Another error is generated if AWS_DEFAULT_REGION is set to another region than the one that corresponds with ec2_url. `ec2_url` is not taking precedence.
!needs_info
i used ec2_url:

ec2_url: "ec2.us-east-1.amazonaws.com"
while i tried with 
region: "us-east-1"
i am able to provision ec2 instance.
In general the ec2_uri parameter is intended for use with non-AWS clouds, such as Eucalyptus, so if you're on AWS I'd recommend sticking to the `region` or setting `AWS_REGION`. 

That said, this *shouldn't* be a problem, and it looks like it's coming from how we set up boto connections, but I'm not sure. Thanks for reporting!

Resolving patch:
diff --git a/lib/ansible/modules/cloud/amazon/ec2.py b/lib/ansible/modules/cloud/amazon/ec2.py
--- a/lib/ansible/modules/cloud/amazon/ec2.py
+++ b/lib/ansible/modules/cloud/amazon/ec2.py
@@ -615,18 +615,20 @@
 
 '''
 
+import traceback
 import time
 from ast import literal_eval
 from ansible.module_utils.six import get_function_code
 from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.ec2 import get_aws_connection_info, ec2_argument_spec, ec2_connect, connect_to_aws
+from ansible.module_utils.ec2 import get_aws_connection_info, ec2_argument_spec, ec2_connect
 from distutils.version import LooseVersion
 
 try:
     import boto.ec2
     from boto.ec2.blockdevicemapping import BlockDeviceType, BlockDeviceMapping
     from boto.exception import EC2ResponseError
-    from boto.vpc import VPCConnection
+    from boto import connect_ec2_endpoint
+    from boto import connect_vpc
     HAS_BOTO = True
 except ImportError:
     HAS_BOTO = False
@@ -1617,17 +1619,16 @@ def main():
     if not HAS_BOTO:
         module.fail_json(msg='boto required for this module')
 
-    ec2 = ec2_connect(module)
-
-    region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module)
+    try:
+        _, ec2_url, aws_connect_kwargs = get_aws_connection_info(module)
+        if module.params.get('region') or not module.params.get('ec2_url'):
+            ec2 = ec2_connect(module)
+        elif module.params.get('ec2_url'):
+            ec2 = connect_ec2_endpoint(ec2_url, **aws_connect_kwargs)
 
-    if region:
-        try:
-            vpc = connect_to_aws(boto.vpc, region, **aws_connect_kwargs)
-        except boto.exception.NoAuthHandlerFound as e:
-            module.fail_json(msg=str(e))
-    else:
-        vpc = None
+        vpc = connect_vpc(**aws_connect_kwargs)
+    except boto.exception.NoAuthHandlerFound as e:
+        module.fail_json(msg="Failed to get connection: %s" % e.message, exception=traceback.format_exc())
 
     tagged_instances = []
 


Test patch: