aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--.ansible-lint80
-rw-r--r--.pre-commit-config.yaml23
-rw-r--r--.yamllint52
-rw-r--r--LICENSE21
-rw-r--r--defaults/main.yml54
-rw-r--r--handlers/main.yml28
-rw-r--r--tasks/lineinfile.yml15
-rw-r--r--tasks/main.yml4
8 files changed, 277 insertions, 0 deletions
diff --git a/.ansible-lint b/.ansible-lint
new file mode 100644
index 0000000..2e09147
--- /dev/null
+++ b/.ansible-lint
@@ -0,0 +1,80 @@
+# https://ansible-lint.readthedocs.io
+---
+exclude_paths: []
+
+use_default_rules: true
+
+enable_list:
+ # Ansible `min` profile
+ - internal-error
+ - load-failure
+ - parser-error
+ - syntax-check
+
+ # Ansible `basic` profile
+ - command-instead-of-module
+ - command-instead-of-shell
+ - deprecated-bare-vars
+ - deprecated-local-action
+ - deprecated-module
+ - inline-env-var
+ - key-order
+ - literal-compare
+ - jinja
+ - no-free-form
+ - no-jinja-when
+ - no-tabs
+ - partial-become
+ - playbook-extension
+ - role-name
+ - schema
+ - name
+ - var-naming
+ - yaml
+
+ # Ansible `moderate` profile
+ - name[template]
+ - name[imperative]
+ - name[casing]
+ - spell-var-name
+
+ # Ansible `safety` profile
+ - avoid-implicit
+ - latest
+ - package-latest
+ - risky-file-permissions
+ - risky-octal
+ - risky-shell-pipe
+
+ # Ansible `shared` profile
+ - galaxy
+ - ignore-errors
+ - layout
+ - meta-incorrect
+ - meta-no-tags
+ - meta-video-links
+ - meta-version
+ - meta-runtime
+ - no-changed-when
+ - no-handler
+ - no-relative-paths
+ - max-block-depth
+ - max-tasks
+ - unsafe-loop
+
+ # Ansible `production` profile
+ - avoid-dot-notation
+ - sanity
+ - fqcn
+ - import-task-no-when
+ - meta-no-dependencies
+ - single-entry-point
+ - use-loop
+
+ # Custom rules
+ - args
+ - empty-string-compare
+ - fqcn-builtins
+ - loop-var-prefix
+ - no-log-password
+ - no-same-owner
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 0000000..0204c17
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,23 @@
+---
+default_stages: [commit, push]
+
+repos:
+ - repo: https://github.com/pre-commit/pre-commit-hooks
+ rev: v4.0.1
+ hooks:
+ - id: check-added-large-files
+ - id: check-yaml
+ - id: trailing-whitespace
+ - id: double-quote-string-fixer
+ - id: end-of-file-fixer
+
+ - repo: https://github.com/ansible-community/ansible-lint.git
+ rev: v6.15.0
+ hooks:
+ - id: ansible-lint
+ files: \.(yaml|yml)$
+
+ - repo: https://github.com/markdownlint/markdownlint
+ rev: v0.12.0
+ hooks:
+ - id: markdownlint
diff --git a/.yamllint b/.yamllint
new file mode 100644
index 0000000..8551271
--- /dev/null
+++ b/.yamllint
@@ -0,0 +1,52 @@
+# https://yamllint.readthedocs.io/en/stable/rules.html
+---
+rules:
+ quoted-strings:
+ quote-type: single
+ required: only-when-needed
+
+ colons:
+ max-spaces-before: 0
+ max-spaces-after: 1
+
+ commas:
+ max-spaces-before: 0
+ min-spaces-after: 1
+ max-spaces-after: 1
+
+ comments:
+ require-starting-space: true
+ ignore-shebangs: true
+ min-spaces-from-content: 1
+
+ document-end:
+ present: false
+
+ document-start:
+ present: true
+
+ empty-lines:
+ max: 2
+ max-start: 0
+ max-end: 0
+
+ empty-values:
+ forbid-in-block-mappings: true
+ forbid-in-flow-mappings: true
+
+ float-values:
+ require-numeral-before-decimal: true
+
+ hyphens:
+ max-spaces-after: 1
+
+ indentation:
+ spaces: 2
+ indent-sequences: true
+ check-multi-line-strings: true
+
+ trailing-spaces: {}
+
+ truthy:
+ allowed-values: ['true', 'false']
+ check-keys: true
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..1a38188
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2023 Colin Wilk
+
+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:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/defaults/main.yml b/defaults/main.yml
new file mode 100644
index 0000000..034ca13
--- /dev/null
+++ b/defaults/main.yml
@@ -0,0 +1,54 @@
+---
+prometheus_target_host: prometheus # FIXME: Non default argument_spec
+
+prometheus_target_strategy: lineinfile
+
+
+################################################################################
+# handler configuration
+################################################################################
+
+prometheus_target_handler_command_enabled: false
+prometheus_target_handler_command_become: true
+# prometheus_target_handler_command_argv:
+# prometheus_target_handler_command_chdir:
+# prometheus_target_handler_command_cmd:
+# prometheus_target_handler_command_creates:
+# prometheus_target_handler_command_free_form:
+# prometheus_target_handler_command_removes:
+# prometheus_target_handler_command_stdin:
+# prometheus_target_handler_command_stdin_add_newline:
+
+prometheus_target_handler_shell_enabled: false
+prometheus_target_handler_shell_become: true
+# prometheus_target_handler_shell_chdir:
+# prometheus_target_handler_shell_cmd:
+# prometheus_target_handler_shell_creates:
+# prometheus_target_handler_shell_executable:
+# prometheus_target_handler_shell_free_form:
+# prometheus_target_handler_shell_removes:
+# prometheus_target_handler_shell_stdin:
+# prometheus_target_handler_shell_stdin_add_newline:
+
+################################################################################
+# lineinfile strategy configuration
+################################################################################
+
+prometheus_target_strategy_lineinfile_prefix: ' - '
+prometheus_target_strategy_lineinfile_suffix: ''
+
+################################################################################
+# Exporter configuration
+################################################################################
+
+prometheus_target_exporter_defaults:
+ node_exporter:
+ path: /opt/prometheus/targets.yml
+ host: '{{ inventory_hostname }}'
+
+prometheus_target_exporter: []
+ # - id: node_exporter
+ # path: asd
+ # hosts: ['{{ inventory_hostname }}']
+
+default_hostname: '{{ inventory_hostname }}' # TODO: Implement
diff --git a/handlers/main.yml b/handlers/main.yml
new file mode 100644
index 0000000..4b1aebb
--- /dev/null
+++ b/handlers/main.yml
@@ -0,0 +1,28 @@
+---
+- name: Run command hook # noqa inline-env-var
+ ansible.builtin.command:
+ argv: '{{ prometheus_target_handler_command_argv | default(omit) }}'
+ chdir: '{{ prometheus_target_handler_command_chdir | default(omit) }}'
+ cmd: '{{ prometheus_target_handler_command_cmd | default(omit) }}'
+ creates: '{{ prometheus_target_handler_command_creates | default(omit) }}'
+ free_form: '{{ prometheus_target_handler_command_free_form | default(omit) }}'
+ removes: '{{ prometheus_target_handler_command_removes | default(omit) }}'
+ stdin: '{{ prometheus_target_handler_command_stdin | default(omit) }}'
+ stdin_add_newline: '{{ prometheus_target_handler_command_stdin_add_newline | default(omit) }}'
+ become: '{{ prometheus_target_handler_command_become }}'
+ delegate_to: '{{ prometheus_target_host }}'
+ when: prometheus_target_handler_command_enabled
+
+- name: Run shell hook
+ ansible.builtin.shell:
+ chdir: '{{ prometheus_target_handler_shell_chdir | default(omit) }}'
+ cmd: '{{ prometheus_target_handler_shell_cmd | default(omit) }}'
+ creates: '{{ prometheus_target_handler_shell_creates | default(omit) }}'
+ executable: '{{ prometheus_target_handler_shell_executable | default(omit) }}'
+ free_form: '{{ prometheus_target_handler_shell_free_form | default(omit) }}'
+ removes: '{{ prometheus_target_handler_shell_removes | default(omit) }}'
+ stdin: '{{ prometheus_target_handler_shell_stdin | default(omit) }}'
+ stdin_add_newline: '{{ prometheus_target_handler_shell_stdin_add_newline | default(omit) }}'
+ become: '{{ prometheus_target_handler_shell_become }}'
+ delegate_to: '{{ prometheus_target_host }}'
+ when: prometheus_target_handler_shell_enabled
diff --git a/tasks/lineinfile.yml b/tasks/lineinfile.yml
new file mode 100644
index 0000000..c90e823
--- /dev/null
+++ b/tasks/lineinfile.yml
@@ -0,0 +1,15 @@
+---
+- name: Make sure targets are deployed
+ ansible.builtin.lineinfile:
+ path: '{{ item.0.path if item.0.path is defined else prometheus_target_exporter_defaults[item.0.id].path }}'
+ line: '{{ prometheus_target_strategy_lineinfile_prefix ~
+ (item.1 if item.1 != "" else prometheus_target_exporter_defaults[item.0.id].host) ~
+ prometheus_target_strategy_lineinfile_suffix }}'
+ state: present
+ become: true
+ delegate_to: '{{ prometheus_target_host }}'
+ loop: '{{ (prometheus_target_exporter | selectattr("hosts", "defined") | subelements("hosts"))
+ + (prometheus_target_exporter | selectattr("hosts", "undefined") | product([""])) }}'
+ notify:
+ - Run command hook
+ - Run shell hook
diff --git a/tasks/main.yml b/tasks/main.yml
new file mode 100644
index 0000000..158191d
--- /dev/null
+++ b/tasks/main.yml
@@ -0,0 +1,4 @@
+---
+- name: Select strategy
+ ansible.builtin.include_tasks:
+ file: '{{ prometheus_target_strategy }}.yml'