Amazon web services Ansible找不到所需的boto3模块

Amazon web services Ansible找不到所需的boto3模块,amazon-web-services,ansible,boto3,Amazon Web Services,Ansible,Boto3,我很难解决一个看似简单的问题。在执行git存储库中的ansible playbook时,我丢失了一个插件。它试图从AWS boto3插件执行Ansible ec2_group_info命令。错误如下: [WARNING]: Skipping plugin (/home/user/git-repo-name/plugins/filters/kms_filters.py) as it seems to be invalid: No module named 'boto3' failed: [loc

我很难解决一个看似简单的问题。在执行git存储库中的ansible playbook时,我丢失了一个插件。它试图从AWS boto3插件执行Ansible ec2_group_info命令。错误如下:

[WARNING]: Skipping plugin (/home/user/git-repo-name/plugins/filters/kms_filters.py) as it seems to 
be invalid: No module named 'boto3'
failed: [localhost] (item=DEV) => {"ansible_loop_var": "item", "changed": false, "item":
"DEV", "msg": "boto3 required for this module"}
import boto3
import base64

kms = boto3.client('kms', region_name='region-name')

def kms_decrypt(ciphertext):
    return kms.decrypt(CiphertextBlob=base64.b64decode(ciphertext)).get('Plaintext')

def kms_encrypt(plaintext, key):
    return base64.b64encode(kms.encrypt(KeyId=key,Plaintext=plaintext).get('CiphertextBlob'))

class FilterModule(object):
    def filters(self):
        return { 'kms_encrypt': kms_encrypt, 'kms_decrypt': kms_decrypt }
我的ansible信息在本地使用repo文件夹中的ansible--version如下所示:

ansible 2.9.6
config file = /home/user-name/repo-name/ansible.cfg
configured module search path = ['/home/user-name/repo-name/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.8.2 (default, Apr 27 2020, 15:53:34) [GCC 9.3.0]
ansible 2.9.6
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/user-name/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.8.2 (default, Apr 27 2020, 15:53:34) [GCC 9.3.0]
在本地repo文件夹之外,它看起来如下所示:

ansible 2.9.6
config file = /home/user-name/repo-name/ansible.cfg
configured module search path = ['/home/user-name/repo-name/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.8.2 (default, Apr 27 2020, 15:53:34) [GCC 9.3.0]
ansible 2.9.6
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/user-name/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.8.2 (default, Apr 27 2020, 15:53:34) [GCC 9.3.0]
python3和boto3都是全局安装的,我可以使用python3正确地使用boto3。 我已经搜索了很多论坛页面,但我找不到一个令人满意的解决方案,我的问题

在我看来,它似乎没有搜索所有可能安装的插件选项全球范围内,但只限于选项的回购

在这个插件kms_filters.py中似乎也找不到模块。文件内容如下:

[WARNING]: Skipping plugin (/home/user/git-repo-name/plugins/filters/kms_filters.py) as it seems to 
be invalid: No module named 'boto3'
failed: [localhost] (item=DEV) => {"ansible_loop_var": "item", "changed": false, "item":
"DEV", "msg": "boto3 required for this module"}
import boto3
import base64

kms = boto3.client('kms', region_name='region-name')

def kms_decrypt(ciphertext):
    return kms.decrypt(CiphertextBlob=base64.b64decode(ciphertext)).get('Plaintext')

def kms_encrypt(plaintext, key):
    return base64.b64encode(kms.encrypt(KeyId=key,Plaintext=plaintext).get('CiphertextBlob'))

class FilterModule(object):
    def filters(self):
        return { 'kms_encrypt': kms_encrypt, 'kms_decrypt': kms_decrypt }

我需要如何配置它才能找到boto3插件?我需要在哪里添加使这成为可能的任何信息???如果可能的话,我更愿意在repo配置本身中使用插件。

在这种情况下,您可能有多个python版本,我猜您的python3软链接指向python3.6。请在/usr/bin目录中运行
ls-lrt python*
,以识别python3版本。您可能为不同的python版本安装了boto3


建议尝试使用ansible pre_任务运行boto3安装。这样,您的boto3将始终存在。

请记住,ansible模块取决于远程(目标)主机的Python安装,而不是本地主机。你的剧本是什么样子的?您的目标是远程主机吗?
bot3
安装在那里吗?larsks所说的是100%正确的,但除非你在远程机器上有凭证,90%的情况下,这些云任务的使用都是
委托给:localhost
,甚至整个剧本都是
hosts:localhost
,因为ssh进入一台机器只是为了运行云模块并没有什么神奇之处我不明白这是什么意思?我尝试使用ansible插件从AWS检索信息。我不尝试直接在远程主机上执行任何任务。这将如何影响我的脚本?它是否应该使用我自己机器的本地设置来执行此任务?那么,您的理解是错误的。正如@larsks所指出的,Ansible将任务作为Python可执行文件发送到远程节点,然后远程节点使用自己的Python解释器执行它们。所以,是的,在远程节点中确实需要这些依赖关系。好的方面是:在执行任何其他任务之前。这是否意味着在执行ec2_group_info之前,只需在ansible中添加一个通过pip安装boto3的任务就足够了,这样ansible就可以在执行过程中找到boto3了?安装boto3 Preor对我来说也很有用,非常感谢!