尽管安装了Ansible,但找不到boto3和botocore

时间:2018-06-20 17:00:06

标签: python amazon-s3 ansible ansible-2.x

以下任务:

  - name: Fetch dump file from S3
      aws_s3:
        bucket: mybucket
        object: somedump.sql
        dest: /tmp/somedump.sql
        mode: get
      delegate_to: "{{ ec2_instance_ip }}"

失败:

  

致命:[localhost-> 22.33.111.88]:失败! => {“已更改”:false,“ msg”:“此模块需要boto3和botocore”}

$ ssh ubuntu@22.33.111.88
$ pip freeze
boto3==1.7.41
botocore==1.10.41

$ pip3 freeze
blinker==1.3
boto3==1.7.41
botocore==1.10.41

目标计算机是ubuntu/xenial,所以我也已经安装了python-minimal(假设开箱即用的机器只有python3

因此,在目标计算机上:

$(which python) --version
Python 2.7.12

我已经在有和没有追加的情况下进行了上述播放:

  vars:
    ansible_python_interpreter: /usr/bin/python3

任务结束时...

2 个答案:

答案 0 :(得分:3)

您可以尝试将“ boto3”软件包降级以查看是否没有问题吗?

获取可用版本:

pip install boto3==some_nonsense_word

然后:

pip uninstall boto3

最后:

pip install boto3==<VERSION>

基于以下GitHub问题评论的发现:

https://github.com/ansible/ansible-modules-core/issues/2014#issuecomment-144620598

答案 1 :(得分:0)

我在MacOS上也遇到了同样的问题,降级并不能解决问题。但是,将以下python路径添加到class Victim { static void foo() { System.out.println("original code"); } } public class InjectCode extends ClassVisitor { public static void main(String[] args) throws IOException, IllegalAccessException { ClassReader cr = new ClassReader( InjectCode.class.getResourceAsStream("Victim.class")); ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS); cr.accept(new InjectCode(cw), 0); byte[] code = cw.toByteArray(); MethodHandles.lookup().defineClass(code); // Java 9, for simplification Victim.foo(); } InsnList insnList; // to be filled public InjectCode(ClassVisitor target) { super(Opcodes.ASM5, target); // just an example insnList = new InsnList(); insnList.add(new FieldInsnNode(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;")); insnList.add(new LdcInsnNode("Hello World")); insnList.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/Object;)V")); } @Override public MethodVisitor visitMethod( int access, String name, String desc, String sign, String[] excp) { MethodVisitor target = super.visitMethod(access, name, desc, sign, excp); if(name.equals("foo")) { // fill your own trigger condition target = new InjectCodeMethodVisitor(api, target); } return target; } class InjectCodeMethodVisitor extends MethodVisitor { public InjectCodeMethodVisitor(int api, MethodVisitor methodVisitor) { super(api, methodVisitor); } @Override public void visitInsn(int opcode) { switch(opcode) { case Opcodes.RETURN: case Opcodes.ARETURN: case Opcodes.IRETURN: case Opcodes.LRETURN: case Opcodes.FRETURN: case Opcodes.DRETURN: case Opcodes.ATHROW: insnList.accept(mv); // inject exiting method } super.visitInsn(opcode); } } } 文件中可解决此问题:

hosts

然后,您可以使用以下主机运行您的ansible剧本:

[local]
localhost              ansible_connection=local     ansible_python_interpreter=/usr/local/bin/python3

或者在执行过程中将路径设置为python:

ansible-playbook -i ./hosts playbook.yml

如果您使用的是Mac,并且已通过自制软件安装了其他python副本,则可以运行以下命令将boto安装到系统python:

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

以下是该问题的更多解决方案: https://github.com/ansible/ansible/issues/15019