原始influxdb数据
{
"results": [
{
"statement_id": 0,
"series": [
{
"name": "version",
"columns": [
"time",
"image_id"
],
"values": [
[
"2020-06-08T01:57:23.242796382Z",
"dev-xxx"
]
]
}
]
}
]
}
---
- name: Get influxdb value
hosts: all
vars:
profile: prd
product: pay
srv_name: demo
db_name: mydb
table: version
tasks:
- name: set query
set_fact:
query: >
SELECT image_id FROM "{{ table }}"
WHERE "profile"='{{ profile }}'
AND "product"='{{ product }}'
AND "srv_name"='{{ srv_name }}'
order by time desc limit 1
- name: get influxdb value
uri:
url: "http://localhost:8086/query?db={{ db_name }}&pretty=true&q={{ query | urlencode }}"
method: GET
register: result
- name: json get value
set_fact:
latestVersion: "{{ result.json | json_query( 'results[0].series[0].values[0][-1]' ) }}"
- debug: var=latestVersion
网友评论