From a64df1bba104b9befada0f8f8100ddb38487ec1b Mon Sep 17 00:00:00 2001 From: L3D Date: Thu, 26 Oct 2023 17:26:46 +0200 Subject: [PATCH] initialize ansible role --- LICENSE | 2 +- README.md | 3 ++- defaults/main.yml | 2 ++ tasks/get_exporter_version.yml | 33 +++++++++++++++++++++++++++++++++ tasks/main.yml | 3 +++ vars/main.yml | 2 ++ 6 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 defaults/main.yml create mode 100644 tasks/get_exporter_version.yml create mode 100644 tasks/main.yml create mode 100644 vars/main.yml diff --git a/LICENSE b/LICENSE index 3bfab2b..bca5f10 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 win_ansible +Copyright (c) 2023 L3D Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/README.md b/README.md index 9b44eb8..2334184 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ # ansible_role_win_exporter -Ansible role to install a prometheus exporter on windows \ No newline at end of file +Ansible role to install a prometheus exporter on windows +https://github.com/prometheus-community/windows_exporter/releases diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..ca6a195 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,2 @@ +--- +win_exporter__version: 'latest' diff --git a/tasks/get_exporter_version.yml b/tasks/get_exporter_version.yml new file mode 100644 index 0000000..777edfc --- /dev/null +++ b/tasks/get_exporter_version.yml @@ -0,0 +1,33 @@ +--- +- name: "Determine 'latest' version release" + when: win_exporter__version == "latest" + block: + - name: "Get latest windows_exporter release metadata" + ansible.builtin.uri: + url: "{{ win_exporter__repo_api }}" + return_content: true + register: win_exporter__remote_metadata + become: false + when: not ansible_check_mode + + - name: "Fail if running in check mode without versions set." + ansible.builtin.fail: + msg: | + "You are running this playbook in check mode: + Please set the desired version with the variable 'win_exporter__version', + because the URI module cannot detect the latest version in this mode." + when: ansible_check_mode and (win_exporter__version == 'latest') + + - name: "Set fact latest windows_exporter release" + ansible.builtin.set_fact: + win_exporter__version_target: "{{ win_exporter__remote_metadata.json.tag_name[1:] }}" + when: not ansible_check_mode + +- name: "Set windows_exporter version target {{ win_exporter__version }}" + ansible.builtin.set_fact: + win_exporter__version_target: "{{ win_exporter__version }}" + when: win_exporter__version != "latest" + +- name: "Generate windows_exporter download URL" + ansible.builtin.debug: + msg: "{{ win_exporter__version_target }}" diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..e73bdfa --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,3 @@ +--- +- name: Get latest windows_exporter version + ansible.builtin.include_tasks: get_exporter_version.yml diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..782e6a4 --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,2 @@ +--- +win_exporter__repo_api: 'https://api.github.com/repos/prometheus-community/windows_exporter/releases/latest'