首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >可能的"ansible_python_interpreter“错误

可能的"ansible_python_interpreter“错误
EN

Stack Overflow用户
提问于 2020-09-28 17:15:37
回答 2查看 6.1K关注 0票数 0

我想用ansible安装influxdb和配置。文件复制和influxdb配置正常,但创建数据库和用户创建部分给出了一个"ansible_python_interpreter“错误。

我搜索了这个错误并尝试了一些方法,但我不能自己解决这个问题

这是我的ansible主机文件

代码语言:javascript
复制
[loadbalancer]
lb      ansible_host=192.168.255.134

[loadbalancer:vars]
ansible_python_interpreter="/usr/bin/python3"
#ansible_python_interpreter="/usr/bin/env python"
#ansible_python_interpreter="/usr/libexec/platform-python"

这是我的yaml文件

代码语言:javascript
复制
# influxdb install and configuration

---
  - hosts: lb
    become: true
    tasks:
      - name: Copy Repo Files
        copy:
          src: ./files/influxdb.j2
          dest: /etc/yum.repos.d/influxdb.repo
          remote_src: no
      - name: Install Influxdb
        yum:
          name: influxdb
          state: latest
        notify:
             influxdb_ok
      - name: Crete Database
        community.general.influxdb_database:
          hostname: 192.168.255.134
          database_name: deneme
      - name: Create User
        community.general.influxdb_user:
          user_name: deneme_user
          user_password: deneme123

    handlers:
      - name: Start Influx Service
        service:
          name: influxdb
          state: started
          enabled: yes
        listen: influxdb_ok

我尝试安装python3 remote vm(lb)。我被试着改变解释器参数。我尝试用pip3安装requests模块。

代码语言:javascript
复制
[root@centos8 influx]# ansible-playbook influxdb.yaml -K
BECOME password:

PLAY [lb] ***********************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************
ok: [lb]

TASK [Copy Repo Files] **********************************************************************************************
ok: [lb]

TASK [Install Influxdb] *********************************************************************************************
ok: [lb]

TASK [Crete Database] ***********************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named 'requests'
fatal: [lb]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library (requests) on loadbalancer.servicepark.local'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"}

PLAY RECAP **********************************************************************************************************
lb                         : ok=3    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

我尝试安装requests模块,目前是ansible版本

现在我的ansible机器版本

代码语言:javascript
复制
[root@centos8 influx]# python3 --version
Python 3.6.8
[root@centos8 influx]# ansible --version
ansible 2.10.1
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.8 (default, Apr 16 2020, 01:36:27) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]

lb虚拟机的版本

代码语言:javascript
复制
[root@loadbalancer ~]# influx --version
InfluxDB shell version: 1.8.2
[root@loadbalancer ~]# python3 --version
Python 3.6.8
EN

回答 2

Stack Overflow用户

发布于 2021-09-06 06:36:43

这对我很有效。

代码语言:javascript
复制
- name: Install requests python package
  pip:
    name: requests
  vars:
    ansible_python_interpreter: /usr/bin/python3
票数 3
EN

Stack Overflow用户

发布于 2021-09-06 13:48:55

如果您在远程主机上遇到此问题,有3种方法可以解决它:

对于使用default

  • Install Python2使用Ansible的原始模块安装了python3的所有主机,

  • 将ansible_python_interpreter: /usr/bin/python3变量设置为/usr/bin/python3使用Ansible的原始模块

  • Symlink /usr/bin/python到/usr/bin/ Python。

所有3个选项都可以在Ansible中完成,而无需sshing到主机中。

示例

代码语言:javascript
复制
- name: misc task on ubuntu 18.04 instance
  hosts: "*"
  vars:
    ansible_python_interpreter: /usr/bin/python3
  tasks:
    - debug: var=ansible_host

选项3- Symlink /usr/bin/python -> /usr/bin/python3使用Ansible的原始模块与选项2类似的另一个选项是使用原始模块“symlink”/usr/bin/python -> /usr/bin/python3。

借助一些shell魔术,我们可以使用条件条件根据其中任何一个文件是否存在来设计一个有条件地执行此操作的命令:

代码语言:javascript
复制
if [ -f /usr/bin/python3 ] && [ ! -f /usr/bin/python ]; then 
  ln --symbolic /usr/bin/python3 /usr/bin/python; 
fi
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64099259

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档