mirror of
https://github.com/wickedyoda/public-setupfiles.git
synced 2026-11-16 13:31:56 -06:00
playbooks
This commit is contained in:
1 parent
69802266ae
commit
ef1efe26b2
36 files changed
+1770
No files matched your search
@@ -0,0 +1,86 @@
|
||||
- name: Install and configure Telegraf
|
||||
hosts: win-pc
|
||||
gather_facts: true
|
||||
vars:
|
||||
influxdb_url: "http://docker2.tail99133.ts.net:8086"
|
||||
influxdb_org: "homelab"
|
||||
influxdb_bucket: "telegraf"
|
||||
telegraf_version: "1.39.2"
|
||||
telegraf_install_dir: "C:\\Program Files\\Telegraf"
|
||||
telegraf_conf: "{{ telegraf_install_dir }}\\telegraf.conf"
|
||||
secret_search_paths:
|
||||
- "C:\\Program Files\\Telegraf\\secrets"
|
||||
- "C:\\secrets\\influxdb"
|
||||
- "\\\\nas\\public\\Hermes_Data\\telegraf-windows\\secrets"
|
||||
influxdb_token: ""
|
||||
|
||||
tasks:
|
||||
- name: Ensure temp directory exists
|
||||
win_file:
|
||||
path: C:\Temp
|
||||
state: directory
|
||||
|
||||
- name: Load InfluxDB token from secret paths
|
||||
win_shell: |
|
||||
$paths = {{ secret_search_paths | to_json }}
|
||||
foreach ($p in $paths) {
|
||||
$tokenFile = Join-Path $p "token"
|
||||
if (Test-Path $tokenFile) {
|
||||
Write-Output (Get-Content $tokenFile -Raw).Trim()
|
||||
exit 0
|
||||
}
|
||||
}
|
||||
exit 1
|
||||
register: influx_token_result
|
||||
changed_when: false
|
||||
failed_when: influx_token_result.rc not in [0, 1]
|
||||
when: influxdb_token | length == 0
|
||||
|
||||
- name: Set token fact from secrets if not provided
|
||||
set_fact:
|
||||
influxdb_token: "{{ influx_token_result.stdout }}"
|
||||
when:
|
||||
- influxdb_token | length == 0
|
||||
- influx_token_result.stdout | length > 0
|
||||
|
||||
- name: Ensure InfluxDB token is available
|
||||
assert:
|
||||
that:
|
||||
- influxdb_token | length > 0
|
||||
fail_msg: "Missing InfluxDB token. Pass influxdb_token or place secrets on the host."
|
||||
|
||||
- name: Download Telegraf {{ telegraf_version }} zip
|
||||
win_get_url:
|
||||
url: "https://dl.influxdata.com/telegraf/releases/telegraf-{{ telegraf_version }}_windows_amd64.zip"
|
||||
dest: C:\Temp\telegraf-{{ telegraf_version }}.zip
|
||||
|
||||
- name: Extract Telegraf
|
||||
win_unzip:
|
||||
src: C:\Temp\telegraf-{{ telegraf_version }}.zip
|
||||
dest: C:\Temp\telegraf
|
||||
creates: C:\Temp\telegraf\telegraf-{{ telegraf_version }}\telegraf.exe
|
||||
|
||||
- name: Copy Telegraf to Program Files
|
||||
win_command: cmd /c xcopy /E /I /Y "C:\Temp\telegraf\telegraf-{{ telegraf_version }}" "{{ telegraf_install_dir }}"
|
||||
|
||||
- name: Deploy telegraf.conf
|
||||
win_copy:
|
||||
src: ../templates/telegraf-windows.conf.j2
|
||||
dest: "{{ telegraf_conf }}"
|
||||
force: yes
|
||||
|
||||
- name: Install Telegraf service
|
||||
win_shell: "& '{{ telegraf_install_dir }}\\telegraf.exe' --service install --config '{{ telegraf_conf }}'"
|
||||
|
||||
- name: Configure Telegraf service auto-restart
|
||||
win_shell: |
|
||||
sc.exe failure telegraf reset= 86400 actions= restart/5000
|
||||
sc.exe start telegraf
|
||||
args:
|
||||
executable: cmd
|
||||
|
||||
- name: Ensure Telegraf service is running
|
||||
win_service:
|
||||
name: telegraf
|
||||
state: started
|
||||
start_mode: auto
|
||||
Reference in new issue
Block a user