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

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/

and added task assoicate with elastic ip below.


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

The error i get is


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'


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


you are using python3 for a python2 app

Ah ok.
I have changed it to

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

and get