| --- |
| |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| # |
| |
| - hosts: localhost |
| connection: local |
| gather_facts: false |
| |
| |
| tasks: |
| - name: Load environment specific vars |
| include_vars: |
| file: "{{ lookup('env', 'PWD') }}/ansible/vars.yml" |
| |
| - name: Load environment specific vault |
| include_vars: |
| file: "{{ lookup('env', 'PWD') }}/ansible/vault" |
| no_log: true |
| |
| - name: Get TO Cookie |
| uri: |
| url: "{{ to_url }}/api/{{ to_api_version }}/user/login" |
| method: POST |
| body: '{ "u":"{{ tm_traffic_ops_username }}", "p":"{{ tmonitor_passwd }}" }' |
| headers: |
| Content-Type: "application/x-www-form-urlencoded" |
| validate_certs: no |
| follow_redirects: all |
| return_content: yes |
| timeout: 120 |
| body_format: json |
| register: mojo_token |
| no_log: true |
| |
| - name: Get All Servers |
| uri: |
| url: "{{ to_url }}/api/{{ to_api_version }}/servers" |
| method: GET |
| validate_certs: no |
| follow_redirects: all |
| return_content: yes |
| body_format: json |
| status_code: 200,400 |
| timeout: 120 |
| headers: |
| Cookie: "{{ mojo_token.set_cookie | default(omit) }}" |
| register: get_all_servers |
| |
| - name: Get a list of InfluxDB servers |
| set_fact: |
| servers_map: "{{ get_all_servers.json | to_json | from_json | json_query(server_query) }}" |
| influxdb_profiles: "{{ get_all_servers.json | to_json | from_json | json_query(profile_query) | unique | sort }}" |
| vars: |
| server_query: 'response[?contains(profile,`INFLUXDB`) == `true` && contains(profile,`RELAY`) == `false`].{profile: profile, fqdn: join(`.`,[hostName,domainName])}' |
| profile_query: 'response[?contains(profile,`INFLUXDB`) == `true` && contains(profile,`RELAY`) == `false`].profile' |
| |
| - hosts: influxrelay |
| gather_facts: yes |
| become: yes |
| |
| tasks: |
| - name: Load environment specific vars |
| include_vars: |
| file: "{{ lookup('env', 'PWD') }}/ansible/vars.yml" |
| |
| - name: Load environment specific vault |
| include_vars: |
| file: "{{ lookup('env', 'PWD') }}/ansible/vault" |
| no_log: true |
| |
| - name: Convert TO data to InfluxDB Relay configuration |
| set_fact: |
| influxdb_relay_data: "{% set base_port = 9085 %}[{% for p in hostvars['localhost'].influxdb_profiles %}{%- set outer_loop = loop -%}{'type':'http','conf_object':{'name': '{{ p }}', 'bindaddr': '0.0.0.0:{{ base_port + loop.index }}', 'output': [ {% for s in hostvars['localhost'].servers_map if s.profile == p %}{ 'name': '{{(s.fqdn.split('.'))[0]}}', 'location': 'http://{{s.fqdn}}:8086/write' }{% endfor %} ] } }{%- if not outer_loop.last %},{% endif -%}{% endfor %}]" |
| |
| - name: Deploy influxdb-relay |
| import_role: |
| name: influxdb_relay |
| vars: |
| install_influxdb_relay: true |
| influxdb_relay_conf: "{{ influxdb_relay_data }}" |