44jq:
55 pkg.installed
66
7+ {% if " remote" in influxdb % }
8+ {%- set base_url = " https://" ~ influxdb[' remote' ][' host' ] ~ " ':" ~ influxdb[' remote' ][' port' ] % }
9+ {%- set data = salt[' cmd.shell' ](" curl -v -s -f -H'Authorization: Token " ~ influxdb[' user' ][' admin' ][' token' ] ~ " ' '" ~ base_url ~ " /api/v2/orgs' &> /tmp/test_orgid.txt" ) % }
10+ {% endif % }
11+
712{%- if " bucket" in influxdb % }
813{%- for config in influxdb[" bucket" ] % }
914{% if " remote" not in influxdb % }
@@ -19,32 +24,37 @@ influxdb_bucket_{{ config['name'] }}:
1924 - pkg: jq
2025{%- set bucket = salt[' cmd.shell' ](" influx bucket list --json | jq -r '.[] | select(.name == \" " + config[' name' ] + " \" ).id'" ) % }
2126{% else % }
27+ {%- set orgID = salt[' cmd.shell' ](" curl -s -f -H'Authorization: Token " ~ influxdb[' user' ][' admin' ][' token' ] ~ " ' '" ~ base_url ~ " /api/v2/orgs' | jq -r '.orgs[0].id'" ) % }
28+
2229get_bucket_{{ config[' name' ] }}:
2330 http.query:
24- - name: ' https:// {{ influxdb[ ' remote ' ][ ' host ' ] }} /api/v2/buckets/{{ config[' name' ] }} '
31+ - name: ' {{ base_url }} /api/v2/buckets/{{ config[' name' ] }} '
2532 - status: 200
2633 - method: GET
2734 - header_dict:
2835 Authorization: Token {{ influxdb[' user' ][' admin' ][' token' ] }}
2936
3037{%- set bucket_data = {
31- name: config[' name' ],
32- description: config[' description' ] | default(' A bucket for ' + config[' name' ]),
33- orgID: config[' orgID' ],
34- retentionRules: [],
35- rp: config[' retention_policy' ]
38+ ' name' : config[' name' ],
39+ ' description' : config[' description' ] | default(' A bucket for ' + config[' name' ]),
40+ ' orgID' : orgID,
41+ ' rp' : config[' retention_policy' ] | default(' 0' ),
3642} % }
3743create_bucket_{{ config[' name' ] }}:
3844 http.query:
39- - name: ' https:// {{ influxdb[ ' remote ' ][ ' host ' ] }} /api/v2/buckets'
45+ - name: ' {{ base_url }} /api/v2/buckets'
4046 - status: 200
4147 - method: POST
4248 - data: ' {{ bucket_data | tojson }} '
4349 - header_dict:
4450 Authorization: Token {{ influxdb[' user' ][' admin' ][' token' ] }}
4551 - onfail:
4652 - http: get_bucket_{{ config[' name' ] }}
47- {%- set bucket = salt[' cmd.shell' ](" curl -s -f -H'Authorization: Token {{ influxdb['user']['admin']['token'] }} ' https://{{ influxdb['remote']['host'] }} /api/v2/buckets | jq -r '.[] | select(.name == \" " + config[' name' ] + " \" ).id'" ) % }
53+ {%- set bucket = salt[' cmd.shell' ](" curl -s -f -H'Authorization: Token " ~ influxdb[' user' ][' admin' ][' token' ] ~ " ' '" ~ base_url ~ " /api/v2/buckets' | jq -r '.buckets[] | select(.name == \" " + config[' name' ] + " \" ).id'" ) % }
54+
55+ testb_{{ config[' name' ] }}_{{ bucket }}:
56+ cmd.run:
57+ - name: echo {{ bucket }}
4858{% endif % }
4959
5060{%- if ' mapping' in config and bucket % }
0 commit comments