美文网首页
ansible 查询 influxdb数据

ansible 查询 influxdb数据

作者: _fishman | 来源:发表于2020-06-08 14:55 被阅读0次

    原始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
    
    

    相关文章

      网友评论

          本文标题:ansible 查询 influxdb数据

          本文链接:https://www.haomeiwen.com/subject/gvhrtktx.html