Ansible ec2:“此模块需要 boto"; [英] Ansible ec2: "boto required for this module"

查看:22
本文介绍了Ansible ec2:“此模块需要 boto";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行这个简单的 Ansible playbook 时:

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 和默认系统 Python 中安装了 boto:

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, hack.您不再需要在 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";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆