# issue with aws cli command to associate elastic ip to new instance

**URL:** <https://forum.ansible.com/t/issue-with-aws-cli-command-to-associate-elastic-ip-to-new-instance/19357>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [September 25, 2015, 1:47pm UTC](https://forum.ansible.com/t/issue-with-aws-cli-command-to-associate-elastic-ip-to-new-instance/19357 "2015-09-25T13:47:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adrian\_Black1](https://avatars.discourse-cdn.com/v4/letter/a/b5a626/32.png) [@Adrian\_Black1](https://forum.ansible.com/u/Adrian_Black1)\
**Post date:** [September 25, 2015, 1:47pm UTC](https://forum.ansible.com/t/issue-with-aws-cli-command-to-associate-elastic-ip-to-new-instance/19357/1 "2015-09-25T13:47:05Z")

</div>

Hi.  
We are not using v2 of ansible yet so the elastic ip association isnt available yet.

I was hoping i could do this via aws cli in the short term

I came across this post  
[http://engineering.ticketbis.com/how-to-use-aws-cli-from-ansible-tower/](http://engineering.ticketbis.com/how-to-use-aws-cli-from-ansible-tower/)

and added task assoicate with elastic ip below.

```auto

```

```auto
tasks:
    - name: Create vm
      ec2:
        key_name: "{{ aws_key_name }}"
        instance_type: "{{ cms_machine_type }}"
        image: "{{ aws_vm_image }}"
        wait: yes
        exact_count: 1
        count_tag: 
           role: cms
        group_id: "{{ aws_cms_security_group_id }}"
        region: "{{ aws_region }}"
        monitoring: yes
        assign_public_ip: yes
        vpc_subnet_id: "{{ aws_vpc_subnet_id }}"
        instance_tags:
           role: cms
           has_shared: true
      register: ec2
    - name: Add new instance to ansible in memory host group
      add_host: hostname={{item.public_ip}} groupname=cms
      with_items: ec2.instances
    - name: assoicate with elastic ip  
      local_action: 
         module: shell aws ec2 associate-address --instance-id={{ item.id }} --allocation-id eipalloc-xxxx

```

```auto

```

The error i get is

```auto

```

```auto
Traceback (most recent call last):
  File "/usr/bin/aws", line 15, in <module>
    import awscli.clidriver
  File "/usr/share/awscli/awscli/clidriver.py", line 16, in <module>
    import botocore.session
  File "/usr/lib/python3/dist-packages/botocore/session.py", line 37, in <module>
    import botocore.service
  File "/usr/lib/python3/dist-packages/botocore/service.py", line 25, in <module>
    from .endpoint import get_endpoint
  File "/usr/lib/python3/dist-packages/botocore/endpoint.py", line 32, in <module>
    import botocore.response
  File "/usr/lib/python3/dist-packages/botocore/response.py", line 26, in <module>
    from .hooks import first_non_none_response
  File "/usr/lib/python3/dist-packages/botocore/hooks.py", line 22, in <module>
    import inspect
  File "/usr/lib/python3.4/inspect.py", line 35, in <module>
    import importlib.machinery
ImportError: No module named 'importlib.machinery'

```

```auto

```

Anyone seen this or know the correct way to use aws cli from playbook.

I can run the command on the linux command line adn that works fine.

Thanks

```auto

```

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [September 25, 2015, 1:50pm UTC](https://forum.ansible.com/t/issue-with-aws-cli-command-to-associate-elastic-ip-to-new-instance/19357/2 "2015-09-25T13:50:07Z")

</div>

you are using python3 for a python2 app

---

<div class="post-metadata">

**Author:** ![Adrian\_Black1](https://avatars.discourse-cdn.com/v4/letter/a/b5a626/32.png) [@Adrian\_Black1](https://forum.ansible.com/u/Adrian_Black1)\
**Post date:** [September 28, 2015, 10:11am UTC](https://forum.ansible.com/t/issue-with-aws-cli-command-to-associate-elastic-ip-to-new-instance/19357/3 "2015-09-28T10:11:10Z")

</div>

Ah ok.  
I have changed it to

```auto
shell python3 -E /usr/bin/aws ec2 associate-address --instance-id={{ item.id }} --allocation-id eipalloc-b9df00dc

```

```auto

```

```auto
and get

```
