Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ansible 无法导入所需的Python库(botocore或boto3)_Ansible_Boto3 - Fatal编程技术网

Ansible 无法导入所需的Python库(botocore或boto3)

Ansible 无法导入所需的Python库(botocore或boto3),ansible,boto3,Ansible,Boto3,我在localhost上运行一个playbook,我已经安装了ansible和所需的打包软件,如boto3。playbook在远程主机上执行任务时工作正常,但在本地运行时输出以下错误 命令: ansible-playbook app.yaml 错误: fatal: [localhost]: FAILED! => {"changed": false, "msg": "Failed to import the required Python

我在localhost上运行一个playbook,我已经安装了ansible和所需的打包软件,如boto3。playbook在远程主机上执行任务时工作正常,但在本地运行时输出以下错误

命令:

ansible-playbook app.yaml
错误:

fatal: [localhost]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library (botocore or boto3) on DESKTOP-9NTDHK1's Python /usr/bin/python3. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter"}
可翻译版本:

ansible 2.10.3
  config file = /home/user/ansible/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/user/ansible/venv/lib/python3.8/site-packages/ansible
  executable location = /home/user/ansible/venv/bin/ansible
  python version = 3.8.5 (default, Jul 28 2020, 12:59:40) [GCC 9.3.0]
Boto3版本:

(venv) user@DESKTOP-9NTDHK1:~/ansible$ pip show boto3ersion"
Name: boto3
Version: 1.16.18
Summary: The AWS SDK for Python
Home-page: https://github.com/boto/boto3
Author: Amazon Web Services
Author-email: UNKNOWN
License: Apache License 2.0
Location: /home/user/ansible/venv/lib/python3.8/site-packages
Requires: s3transfer, botocore, jmespath
Required-by:
app.yaml

---
-主机:本地主机
连接:本地
收集事实:不
变量:
用户:*****
AWS_前缀:*****
任务:
#条款AWS
-名称:专有网络
ec2_vpc_网络:
cidr_区块:*****
地区:*****
姓名:*****
国家:现在
注册:vpc_数据

以下是剧本的摘录: 注意vars部分。 ansible不知道其发射的venv

- hosts: all
  connection: local
  become_user: tim
  vars: #local connection defaults to using the system python
    ansible_python_interpreter: /home/tim/pycharm_projects/django_api_sync/ansible/venv/bin/python3
  vars_files:
    - includes/secret_variables.yml

  tasks:
    - name: create a DigitalOcean Droplet
      community.digitalocean.digital_ocean_droplet:
        state: present
        name: "{{droplet_name}}"
        oauth_token: "{{digital_ocean_token}}"
        size: "s-2vcpu-2gb"
        region: SGP1
        monitoring: yes
        unique_name: yes
        image: ubuntu-20-04-x64
        wait_timeout: 500
        ssh_keys: [ "{{digital_ocean_ssh_fingerprint}}"]
      register: my_droplet

    - name: Print IP address
      ansible.builtin.debug:
        msg: Droplet IP address is {{ my_droplet.data.ip_address }}

以下是一本剧本的摘录: 注意vars部分。 ansible不知道其发射的venv

- hosts: all
  connection: local
  become_user: tim
  vars: #local connection defaults to using the system python
    ansible_python_interpreter: /home/tim/pycharm_projects/django_api_sync/ansible/venv/bin/python3
  vars_files:
    - includes/secret_variables.yml

  tasks:
    - name: create a DigitalOcean Droplet
      community.digitalocean.digital_ocean_droplet:
        state: present
        name: "{{droplet_name}}"
        oauth_token: "{{digital_ocean_token}}"
        size: "s-2vcpu-2gb"
        region: SGP1
        monitoring: yes
        unique_name: yes
        image: ubuntu-20-04-x64
        wait_timeout: 500
        ssh_keys: [ "{{digital_ocean_ssh_fingerprint}}"]
      register: my_droplet

    - name: Print IP address
      ansible.builtin.debug:
        msg: Droplet IP address is {{ my_droplet.data.ip_address }}

请仔细阅读=>
执行此模块的主机上需要以下要求。
您向我们展示了lib安装在您的控制器上,它必须安装在您的目标上,即使它是本地主机,即用于“远程”wihch的python版本可能与控制器使用的版本不同。根据错误消息的建议,检查ansible_python上的文档_interpreter@Zeitounator这里的目标主机是localhost,如上所述,已满足所有要求。远程主机上未执行任何操作。您正在VirtualNV中执行ansible。这与连接到目标(本地主机)时使用的环境不同。您正在使用未安装lib的其他python环境/版本。只需将它和pip模块一起安装在您的剧本中,以检查您自己。现在就有意义了。我确实在使用虚拟环境。那么现在有没有办法将解释器设置为使用venv而不是它之外的(localhost)?
ansible\u python\u解释器:/path/to/your/venv/bin/python
。请阅读错误消息和我在第一条评论中建议的文档。请仔细阅读=>
执行此模块的主机上需要以下要求。
您向我们展示了lib安装在您的控制器上,它必须安装在您的目标上,即使它是本地主机,即,用于“远程”wihch的python版本可能与控制器使用的版本不同。根据错误消息的建议,检查ansible_python上的文档_interpreter@Zeitounator这里的目标主机是localhost,如上所述,已满足所有要求。远程主机上未执行任何操作。您正在VirtualNV中执行ansible。这与连接到目标(本地主机)时使用的环境不同。您正在使用未安装lib的其他python环境/版本。只需将它和pip模块一起安装在您的剧本中,以检查您自己。现在就有意义了。我确实在使用虚拟环境。那么现在有没有办法将解释器设置为使用venv而不是它之外的(localhost)?
ansible\u python\u解释器:/path/to/your/venv/bin/python
。请按照您的错误信息和我在第一条评论中的建议阅读文档。