community.general.influxdb_query module – Query data points from InfluxDB

Note

This module is part of the community.general collection (version 9.5.1).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.general. You need further requirements to be able to use this module, see Requirements for details.

To use it in a playbook, specify: community.general.influxdb_query.

Synopsis

  • Query data points from InfluxDB.

Requirements

The below requirements are needed on the host that executes this module.

  • influxdb >= 0.9

Parameters

Parameter

Comments

database_name

string / required

Name of the database.

hostname

string

The hostname or IP address on which InfluxDB server is listening.

Default: "localhost"

password

aliases: login_password

string

Password that will be used to authenticate against InfluxDB server.

Default: "root"

path

string

added in community.general 0.2.0

The path on which InfluxDB server is accessible.

Only available when using python-influxdb >= 5.1.0.

Default: ""

port

integer

The port on which InfluxDB server is listening.

Default: 8086

proxies

dictionary

HTTP(S) proxy to use for Requests to connect to InfluxDB server.

Default: {}

query

string / required

Query to be executed.

retries

integer

Number of retries client will try before aborting.

0 indicates try until success.

Only available when using python-influxdb >= 4.1.0.

Default: 3

ssl

boolean

Use https instead of http to connect to InfluxDB server.

Choices:

  • false ← (default)

  • true

timeout

integer

Number of seconds Requests will wait for client to establish a connection.

udp_port

integer

UDP port to connect to InfluxDB server.

Default: 4444

use_udp

boolean

Use UDP to connect to InfluxDB server.

Choices:

  • false ← (default)

  • true

username

aliases: login_username

string

Username that will be used to authenticate against InfluxDB server.

Default: "root"

validate_certs

boolean

If set to false, the SSL certificates will not be validated.

This should only set to false used on personally controlled sites using self-signed certificates.

Choices:

  • false

  • true ← (default)

Attributes

Attribute

Support

Description

check_mode

Support: full

Can run in check_mode and return changed status prediction without modifying target.

diff_mode

Support: none

Will return details on what has changed (or possibly needs changing in check_mode), when in diff mode.

Examples

- name: Query connections
  community.general.influxdb_query:
    hostname: "{{ influxdb_ip_address }}"
    database_name: "{{ influxdb_database_name }}"
    query: "select mean(value) from connections"
  register: connection

- name: Query connections with tags filters
  community.general.influxdb_query:
    hostname: "{{ influxdb_ip_address }}"
    database_name: "{{ influxdb_database_name }}"
    query: "select mean(value) from connections where region='zue01' and host='server01'"
  register: connection

- name: Print results from the query
  ansible.builtin.debug:
    var: connection.query_results

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

query_results

list / elements=string

Result from the query

Returned: success

Sample: [{"mean": 1245.5333333333333, "time": "1970-01-01T00:00:00Z"}]

Authors

  • René Moser (@resmo)