Ansible ec2: “boto required for this module”

2020-02-28 02:04发布

When I run this simple Ansible playbook:

- name: EC2 Test Example
  hosts: localhost
  connection: local
  gather_facts: False

  tasks:
  - name: EC2 Instance
    ec2:
      # Amazon EC2 key pair name
      key_name: my-key-pair
      # Amazon EC2 Security Group
      group: my-security-group
      instance_type: t2.micro
      # Latest from https://wiki.debian.org/Cloud/AmazonEC2Image/Jessie
      image: ami-221ea342
      wait: yes
    register: ec2

I run with venv/bin/ansible-playbook -i localhost, playbook.yml:

PLAY [EC2 Test Example] ********************************************************

TASK [EC2 Instance] ************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "boto required for this module"}
    to retry, use: --limit @/Users/admin/temp/ansec2/playbook.retry

PLAY RECAP *********************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1

So obviously, I have boto installed in the venv that I'm using as well as my default system Python:

➜  ansec2 venv/bin/pip list
Package         Version 
--------------- --------
ansible         2.2.1.0 
boto            2.45.0  
boto3           1.4.4   
botocore        1.5.4   
...

I've read a few similar posts and I don't see a working solution.

标签: ansible boto
1条回答
放我归山
2楼-- · 2020-02-28 02:37

The root cause of your problem is the -i localhost, hack. You don't need to use it anymore in Ansible.

You can just run:

ansible-playbook playbook.yml

And with connection: local in the play Ansible will use the Python executable set by venv.


When you use the -i localhost, hack, Ansible calls its default /usr/bin/python.

In this case you still can add the ansible_python_interpreter parameter to tell Ansible to use this specific environment:

ansible-playbook -i localhost, playbook.yml --extra-vars "ansible_python_interpreter=/Users/admin/temp/ansec2/venv/bin/python" 

But I think you should avoid it and use the first method.

查看更多
登录 后发表回答