问题描述
当我运行这个简单的Ansible剧本时:
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
我用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
很明显,我已经在我使用的venv中安装了boto以及默认系统Python:
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.
推荐答案
问题的根本原因是-i localhost,
黑客.您不再需要在Ansible中使用它.
The root cause of your problem is the -i localhost,
hack. You don't need to use it anymore in Ansible.
您可以运行:
ansible-playbook playbook.yml
并且在剧中的connection: local
中,Ansible将使用venv设置的Python可执行文件.
And with connection: local
in the play Ansible will use the Python executable set by venv.
使用-i localhost,
hack时,Ansible会调用其默认/usr/bin/python
.
When you use the -i localhost,
hack, Ansible calls its default /usr/bin/python
.
在这种情况下,您仍然可以添加ansible_python_interpreter
参数来告诉Ansible使用此特定环境:
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.
这篇关于Ansible ec2:“此模块需要Boto"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!