Ansible:尝试使用 influxdb_write 时无法在本地主机上导入所需的 Python 库 (influxdb)
Ansible: Failed to import the required Python library (influxdb) on localhost when trying to use influxdb_write
我在本地机器上安装了以下 ansible 剧本和 influxdb 运行ning。
我只是想尝试使用 ansible 向我的本地 influxdb 写入一些内容。这里的想法是创建一个名为 connections 的 table,包含主机、区域和时间列。
---
- name: Influx test
hosts: PE
gather_facts: false
tasks:
- name: Write points into database
influxdb_write:
hostname: "localhost"
database_name: "test"
data_points:
- measurement: connections
tags:
host: "{{inventory_hostname}}"
region: test-region
time: "test time"
PE 看起来像这样:
[PE]
local ansible_host=localhost ansible_connection=local hostname=Lab_R1 ansible_python_interpreter=/usr/bin/python3
事实证明,当我 运行 我的剧本时,我得到:
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_influxdb_write_payload_v07tkyyd/ansible_influxdb_write_payload.zip/ansible/module_utils/influxdb.py", line 23, in <module>
from influxdb import InfluxDBClient
ModuleNotFoundError: No module named 'influxdb'
fatal: [local]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"data_points": [
{
"measurement": "connections",
"tags": {
"host": "local",
"region": "test-region"
},
"time": "test time"
}
],
"database_name": "test",
"hostname": "localhost",
"password": "root",
"port": 8086,
"proxies": {},
"retries": 3,
"ssl": false,
"timeout": null,
"udp_port": 4444,
"use_udp": false,
"username": "root",
"validate_certs": true
}
},
"msg": "Failed to import the required Python library (influxdb) on localhost.localdomain's Python /usr/bin/python3. Please read module documentation and install 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"
}
如 influxdb_write
module requirements 中所述,python 库 influxdb >= 0.9 是必需的。
任务的目标需要此要求,在您的情况下localhost
。
因此您需要install influxdb python library使用您选择的方法(系统包或pip
)。
我在本地机器上安装了以下 ansible 剧本和 influxdb 运行ning。 我只是想尝试使用 ansible 向我的本地 influxdb 写入一些内容。这里的想法是创建一个名为 connections 的 table,包含主机、区域和时间列。
---
- name: Influx test
hosts: PE
gather_facts: false
tasks:
- name: Write points into database
influxdb_write:
hostname: "localhost"
database_name: "test"
data_points:
- measurement: connections
tags:
host: "{{inventory_hostname}}"
region: test-region
time: "test time"
PE 看起来像这样:
[PE]
local ansible_host=localhost ansible_connection=local hostname=Lab_R1 ansible_python_interpreter=/usr/bin/python3
事实证明,当我 运行 我的剧本时,我得到:
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_influxdb_write_payload_v07tkyyd/ansible_influxdb_write_payload.zip/ansible/module_utils/influxdb.py", line 23, in <module>
from influxdb import InfluxDBClient
ModuleNotFoundError: No module named 'influxdb'
fatal: [local]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"data_points": [
{
"measurement": "connections",
"tags": {
"host": "local",
"region": "test-region"
},
"time": "test time"
}
],
"database_name": "test",
"hostname": "localhost",
"password": "root",
"port": 8086,
"proxies": {},
"retries": 3,
"ssl": false,
"timeout": null,
"udp_port": 4444,
"use_udp": false,
"username": "root",
"validate_certs": true
}
},
"msg": "Failed to import the required Python library (influxdb) on localhost.localdomain's Python /usr/bin/python3. Please read module documentation and install 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"
}
如 influxdb_write
module requirements 中所述,python 库 influxdb >= 0.9 是必需的。
任务的目标需要此要求,在您的情况下localhost
。
因此您需要install influxdb python library使用您选择的方法(系统包或pip
)。