diff options
| -rw-r--r-- | .github/workflows/release.yml | 4 | ||||
| -rw-r--r-- | .pre-commit-config.yaml | 20 | ||||
| -rw-r--r-- | .yamllint | 63 | ||||
| -rw-r--r-- | CHANGELOG.md | 6 | ||||
| -rw-r--r-- | defaults/main.yml | 18 | ||||
| -rw-r--r-- | meta/argument_specs.yml | 2 | ||||
| -rw-r--r-- | meta/main.yml | 2 | ||||
| -rw-r--r-- | molecule/default/converge.yml | 42 | ||||
| -rw-r--r-- | molecule/default/molecule.yml | 11 | ||||
| -rw-r--r-- | molecule/default/tests/test_check_prometheus_targets.py | 87 | ||||
| -rw-r--r-- | tasks/handlers.yml | 52 | ||||
| -rw-r--r-- | tasks/main.yml | 4 | ||||
| -rw-r--r-- | tasks/process_exporter.yml | 2 | ||||
| -rw-r--r-- | tasks/strategy_lineinfile.yml | 8 | ||||
| -rw-r--r-- | tasks/strategy_yaml.yml | 28 |
15 files changed, 157 insertions, 192 deletions
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d71a70a..a5bd78c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,10 +1,10 @@ --- name: Release -'on': +"on": push: tags: - - '*' + - "*" defaults: run: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0d50a19..2b893f4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,24 +1,28 @@ --- -default_stages: [commit, push] - +default_stages: [pre-commit, pre-push] repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.0.1 + rev: v5.0.0 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 + rev: v25.5.0 hooks: - id: ansible-lint files: \.(yaml|yml)$ - - repo: https://github.com/markdownlint/markdownlint - rev: v0.12.0 + - repo: https://github.com/igorshubovych/markdownlint-cli + rev: v0.43.0 hooks: - id: markdownlint - args: [-s, .markdownlint.rb] + + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.15.20 + hooks: + - id: ruff-check + args: [--fix] + - id: ruff-format @@ -1,52 +1,19 @@ -# 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 +extends: default +rules: 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: false - - trailing-spaces: {} - - truthy: - allowed-values: ['true', 'false'] - check-keys: true + comments-indentation: false + document-start: disable + line-length: + max: 160 + braces: + min-spaces-inside: 0 + max-spaces-inside: 1 + octal-values: + forbid-implicit-octal: true + forbid-explicit-octal: true + quoted-strings: + quote-type: double + required: only-when-needed diff --git a/CHANGELOG.md b/CHANGELOG.md index b28f8f5..e05f6c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## [1.3.0] - 2026-02-09 -### Added +### Added: yaml strategy - Support for `yaml` strategy to read multiple targets per file (commit `049689c`). @@ -12,7 +12,7 @@ ## [1.2.0] - 2023-10-11 -### Added +### Added: run_once option - Add `run_once` option for command and shell handlers. @@ -23,7 +23,7 @@ ## [1.1.0] - 2023-06-15 -### Added +### Added: prefix option - Prefix option for target files (`579b168`). - Ability to define exporters without id (`232bdca`). diff --git a/defaults/main.yml b/defaults/main.yml index 795e3cb..2b62d46 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -95,8 +95,8 @@ prometheus_target_handler_shell_run_once: false # This configuration is mostly used for globally indenting all of your targets # in their target configuration and thus keeping this configuration away from # the exporter host variable. -prometheus_target_strategy_lineinfile_prefix: ' - ' -prometheus_target_strategy_lineinfile_suffix: '' +prometheus_target_strategy_lineinfile_prefix: " - " +prometheus_target_strategy_lineinfile_suffix: "" ################################################################################ @@ -109,9 +109,9 @@ prometheus_target_strategy_lineinfile_suffix: '' # you can define your remaining target files as just target.yml instead of # /opt/prometheus/target.yml # In case you have a few exporters that reside in different directories you may -# ignore the prefix by specifying `path_prefix: ''` in the exporter default +# ignore the prefix by specifying `path_prefix: ""` in the exporter default # or the enabled exporter config. -prometheus_target_exporter_target_prefix: '' +prometheus_target_exporter_target_prefix: "" # This will configure the default settings for specified exporters. # The key in this dict should map to the possible id in the specified exporter @@ -125,14 +125,14 @@ prometheus_target_exporter_target_prefix: '' prometheus_target_exporter_defaults: {} # node_exporter: # path: /opt/prometheus/targets.yml - # host: '{{ inventory_hostname }}:9100' + # host: "{{ inventory_hostname }}:9100" # labels: # Labels to match when using yaml strategy # severity: warning # job: external # blackbox_exporter: # path: /opt/targets/blackbox.yml - # host: 'https://{{ hostvars[inventory_hostname].ansible_host }}' - # path_prefix: '' + # host: "https://{{ hostvars[inventory_hostname].ansible_host }}" + # path_prefix: "" # labels: # severity: critical @@ -145,7 +145,7 @@ prometheus_target_exporter: [] # # overwrites prometheus_target_exporter_defaults.node_exporter.path # path: /path/to/targets/file/on/prometheus/host # # overwrites: prometheus_target_exporter_defaults.node_exporter.host - # host: '{{ inventory_hostname }}:9100' + # host: "{{ inventory_hostname }}:9100" # # labels to match the target group in the YAML file (yaml strategy only) # labels: # severity: warning @@ -157,7 +157,7 @@ prometheus_target_exporter: [] # ignored. prometheus_target_default_exporters: [] # - { id: node_exporter } - # - { id: blackbox_exporter, path: /path/to/target, path_prefix: '' } + # - { id: blackbox_exporter, path: /path/to/target, path_prefix: "' } # You can enable this variable to not add exporters defined in # prometheus_target_default_exporters diff --git a/meta/argument_specs.yml b/meta/argument_specs.yml index 1d960cf..f7b6c43 100644 --- a/meta/argument_specs.yml +++ b/meta/argument_specs.yml @@ -16,7 +16,7 @@ argument_specs: prometheus_target_exporter_target_prefix: type: str required: false - default: '' + default: "" prometheus_target_strategy: type: str diff --git a/meta/main.yml b/meta/main.yml index 985d07b..c629760 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -6,7 +6,7 @@ galaxy_info: author: kliwniloc description: Role for adding targets to prometheus instance license: license (MIT) - min_ansible_version: '2.4' + min_ansible_version: "2.4" platforms: - name: Debian versions: diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index cb6a281..98d7e8a 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -6,13 +6,13 @@ pre_tasks: - name: Create targets ansible.builtin.file: - path: '{{ item }}' + path: "{{ item }}" state: touch modification_time: preserve access_time: preserve - mode: '0644' + mode: "0644" become: true - delegate_to: '{{ prometheus_target_host }}' + delegate_to: "{{ prometheus_target_host }}" loop: - /opt/simple_target1.yml - /opt/simple_target2.yml @@ -24,10 +24,10 @@ prometheus_target_exporter_defaults: node_exporter: path: /opt/simple_target1.yml - host: '{{ inventory_hostname }}' + host: "{{ inventory_hostname }}" blackbox_exporter: path: /opt/simple_target2.yml - host: '{{ inventory_hostname }}_AA' + host: "{{ inventory_hostname }}_AA" roles: - role: kliwniloc.prometheus_target @@ -48,13 +48,13 @@ pre_tasks: - name: Create targets ansible.builtin.file: - path: '{{ item.path }}' - state: '{{ item.state }}' + path: "{{ item.path }}" + state: "{{ item.state }}" modification_time: preserve access_time: preserve - mode: '0644' + mode: "0644" become: true - delegate_to: '{{ prometheus_target_host }}' + delegate_to: "{{ prometheus_target_host }}" loop: - { state: touch, path: /opt/prefix_target1.yml } - { state: touch, path: /opt/prefix_target2.yml } @@ -67,17 +67,17 @@ prometheus_target_exporter_defaults: node_exporter: path: prefix_target1.yml - host: '{{ inventory_hostname }}' + host: "{{ inventory_hostname }}" blackbox_exporter: path: prefix_target_not_exist.yml - host: '{{ inventory_hostname }}' + host: "{{ inventory_hostname }}" path_prefix: /opt/prefix/ roles: - role: kliwniloc.prometheus_target prometheus_target_exporter: - id: node_exporter - - { id: node_exporter, path: /opt/prefix_target2.yml, path_prefix: '' } + - { id: node_exporter, path: /opt/prefix_target2.yml, path_prefix: "" } - { id: blackbox_exporter, path: prefix_target3.yml } ################################################################################ @@ -87,13 +87,13 @@ pre_tasks: - name: Create targets ansible.builtin.file: - path: '{{ item }}' + path: "{{ item }}" state: touch modification_time: preserve access_time: preserve - mode: '0644' + mode: "0644" become: true - delegate_to: '{{ prometheus_target_host }}' + delegate_to: "{{ prometheus_target_host }}" loop: - /opt/hook_target.yml - /opt/hook2 @@ -112,7 +112,7 @@ - role: kliwniloc.prometheus_target prometheus_target_exporter: - id: node_exporter - host: '{{ inventory_hostname }}' + host: "{{ inventory_hostname }}" path: /opt/hook_target.yml ################################################################################ @@ -124,14 +124,14 @@ ansible.builtin.user: name: prometheus become: true - delegate_to: '{{ prometheus_target_host }}' + delegate_to: "{{ prometheus_target_host }}" - name: Create target ansible.builtin.copy: dest: /opt/lineinfile.yml owner: prometheus group: prometheus - mode: '0600' + mode: "0600" force: false # yamllint disable rule:indentation content: | @@ -141,11 +141,11 @@ - existing:9100 # yamllint enable rule:indentation become: true - delegate_to: '{{ prometheus_target_host }}' + delegate_to: "{{ prometheus_target_host }}" vars: prometheus_target_host: prometheus - prometheus_target_strategy_lineinfile_prefix: ' - ' + prometheus_target_strategy_lineinfile_prefix: " - " prometheus_target_strategy_lineinfile_suffix: :9100 roles: @@ -153,4 +153,4 @@ prometheus_target_exporter: - id: node_exporter path: /opt/lineinfile.yml - host: '{{ inventory_hostname }}' + host: "{{ inventory_hostname }}" diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index de1ac40..3ffe0b8 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -2,15 +2,12 @@ dependency: name: galaxy - driver: name: docker - platforms: - - name: application - image: ${MOLECULE_DISTRO:-debian:10} + image: ${MOLECULE_DISTRO:-debian:12} dockerfile: Dockerfile.j2 pre_build_image: false docker_networks: @@ -23,7 +20,7 @@ platforms: groups: [application_group] - name: application2 - image: ${MOLECULE_DISTRO:-debian:10} + image: ${MOLECULE_DISTRO:-debian:12} dockerfile: Dockerfile.j2 pre_build_image: false networks: @@ -31,18 +28,16 @@ platforms: groups: [application_group] - name: prometheus - image: ${MOLECULE_DISTRO:-debian:10} + image: ${MOLECULE_DISTRO:-debian:12} dockerfile: Dockerfile.j2 pre_build_image: false networks: - name: molecule-container-net - provisioner: name: ansible playbooks: converge: ${MOLECULE_PLAYBOOK:-converge.yml} - verifier: name: testinfra diff --git a/molecule/default/tests/test_check_prometheus_targets.py b/molecule/default/tests/test_check_prometheus_targets.py index 2eeb21b..b9024b4 100644 --- a/molecule/default/tests/test_check_prometheus_targets.py +++ b/molecule/default/tests/test_check_prometheus_targets.py @@ -1,91 +1,90 @@ -testinfra_hosts = ['prometheus'] +testinfra_hosts = ["prometheus"] """ Test functionality of defining exporters and default fallbacks """ + + def test_check_hosts_added_simple(host): - t1 = host.file('/opt/simple_target1.yml') - t2 = host.file('/opt/simple_target2.yml') - t3 = host.file('/opt/simple_target3.yml') - t4 = host.file('/opt/simple_target4.yml') + t1 = host.file("/opt/simple_target1.yml") + t2 = host.file("/opt/simple_target2.yml") + t3 = host.file("/opt/simple_target3.yml") + t4 = host.file("/opt/simple_target4.yml") assert t1.exists assert t2.exists assert t3.exists assert t4.exists - assert t1.content_string == \ - ' - application\n' + assert t1.content_string == " - application\n" + assert t2.content_string == " - test1\n - test2\n" - assert t2.content_string == \ - ' - test1\n' \ - ' - test2\n' + assert t3.content_string == " - application_AA\n" - assert t3.content_string == \ - ' - application_AA\n' + assert t4.content_string == " - exporter_without_id\n" - assert t4.content_string == \ - ' - exporter_without_id\n' """ Test prefix functionality """ + + def test_check_hosts_added_prefix(host): - t1 = host.file('/opt/prefix_target1.yml') - t2 = host.file('/opt/prefix_target2.yml') - t3 = host.file('/opt/prefix/prefix_target3.yml') + t1 = host.file("/opt/prefix_target1.yml") + t2 = host.file("/opt/prefix_target2.yml") + t3 = host.file("/opt/prefix/prefix_target3.yml") assert t1.exists assert t2.exists assert t3.exists - assert t1.content_string == \ - ' - application\n' + assert t1.content_string == " - application\n" + assert t2.content_string == " - application\n" - assert t2.content_string == \ - ' - application\n' + assert t3.content_string == " - application\n" - assert t3.content_string == \ - ' - application\n' """ Test hook functionality """ + + def test_check_hosts_added_hooks(host): - t1 = host.file('/opt/hook_target.yml') - t2 = host.file('/opt/hook1') - t3 = host.file('/opt/hook2') + t1 = host.file("/opt/hook_target.yml") + t2 = host.file("/opt/hook1") + t3 = host.file("/opt/hook2") assert t1.exists assert t2.exists assert t3.exists - assert t1.content_string == \ - ' - application\n' \ - ' - application2\n' \ - or t1.content_string == \ - ' - application2\n' \ - ' - application\n' + assert ( + t1.content_string == " - application\n - application2\n" + or t1.content_string == " - application2\n - application\n" + ) + + assert t3.content_string == "hello\nhello\n" - assert t3.content_string == \ - 'hello\n' \ - 'hello\n' """ Test lineinfile strategy parameters """ + + def test_check_host_added_lineinfile(host): - t1 = host.file('/opt/lineinfile.yml') + t1 = host.file("/opt/lineinfile.yml") - assert t1.user == 'prometheus' - assert t1.group == 'prometheus' + assert t1.user == "prometheus" + assert t1.group == "prometheus" assert t1.mode == 0o600 - assert t1.content_string == \ - '- labels:\n' \ - ' my: label\n' \ - ' targets:\n' \ - ' - existing:9100\n' \ - ' - application:9100\n' + assert ( + t1.content_string == "- labels:\n" + " my: label\n" + " targets:\n" + " - existing:9100\n" + " - application:9100\n" + ) + diff --git a/tasks/handlers.yml b/tasks/handlers.yml index b1d9b59..35f946e 100644 --- a/tasks/handlers.yml +++ b/tasks/handlers.yml @@ -1,34 +1,34 @@ --- - 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 }}' - become_method: '{{ prometheus_target_handler_command_become_method | default(omit) }}' - become_user: '{{ prometheus_target_handler_command_become_user | default(omit) }}' - delegate_to: '{{ prometheus_target_host }}' - run_once: '{{ prometheus_target_handler_command_run_once }}' + 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 }}" + become_method: "{{ prometheus_target_handler_command_become_method | default(omit) }}" + become_user: "{{ prometheus_target_handler_command_become_user | default(omit) }}" + delegate_to: "{{ prometheus_target_host }}" + run_once: "{{ prometheus_target_handler_command_run_once }}" 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 }}' - become_method: '{{ prometheus_target_handler_shell_become_method | default(omit) }}' - become_user: '{{ prometheus_target_handler_shell_become_user | default(omit) }}' - delegate_to: '{{ prometheus_target_host }}' - run_once: '{{ prometheus_target_handler_shell_run_once }}' + 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 }}" + become_method: "{{ prometheus_target_handler_shell_become_method | default(omit) }}" + become_user: "{{ prometheus_target_handler_shell_become_user | default(omit) }}" + delegate_to: "{{ prometheus_target_host }}" + run_once: "{{ prometheus_target_handler_shell_run_once }}" when: prometheus_target_handler_shell_enabled diff --git a/tasks/main.yml b/tasks/main.yml index 5a184f8..10f54f7 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -2,8 +2,8 @@ - name: Process all exporters ansible.builtin.include_tasks: file: process_exporter.yml - loop: '{{ prometheus_target_exporter + - ([] if prometheus_target_skip_default_exporters else prometheus_target_default_exporters) }}' + loop: "{{ prometheus_target_exporter + + ([] if prometheus_target_skip_default_exporters else prometheus_target_default_exporters) }}" loop_control: loop_var: item diff --git a/tasks/process_exporter.yml b/tasks/process_exporter.yml index 2d13b29..b4f33ba 100644 --- a/tasks/process_exporter.yml +++ b/tasks/process_exporter.yml @@ -1,7 +1,7 @@ --- - name: Set exporter variables vars: - _defaults: '{{ prometheus_target_exporter_defaults[item.id] | default({}) if item.id is defined else {} }}' + _defaults: "{{ prometheus_target_exporter_defaults[item.id] | default({}) if item.id is defined else {} }}" ansible.builtin.set_fact: _target_path: >- {{ (item.path_prefix if item.path_prefix is defined else diff --git a/tasks/strategy_lineinfile.yml b/tasks/strategy_lineinfile.yml index a5dd01f..7656602 100644 --- a/tasks/strategy_lineinfile.yml +++ b/tasks/strategy_lineinfile.yml @@ -1,13 +1,13 @@ --- - name: Deploy target via lineinfile ansible.builtin.lineinfile: - path: '{{ _target_path }}' - line: '{{ prometheus_target_strategy_lineinfile_prefix ~ _target_host ~ prometheus_target_strategy_lineinfile_suffix }}' + path: "{{ _target_path }}" + line: "{{ prometheus_target_strategy_lineinfile_prefix ~ _target_host ~ prometheus_target_strategy_lineinfile_suffix }}" state: present - delegate_to: '{{ prometheus_target_host }}' + delegate_to: "{{ prometheus_target_host }}" become: true register: _lineinfile_result - name: Track changes ansible.builtin.set_fact: - changed: '{{ changed | default(false) or _lineinfile_result.changed }}' + changed: "{{ changed | default(false) or _lineinfile_result.changed }}" diff --git a/tasks/strategy_yaml.yml b/tasks/strategy_yaml.yml index 1d6df77..8a8e38b 100644 --- a/tasks/strategy_yaml.yml +++ b/tasks/strategy_yaml.yml @@ -1,15 +1,15 @@ --- - name: Check if target file exists ansible.builtin.stat: - path: '{{ _target_path }}' + path: "{{ _target_path }}" register: _target_file_stat - delegate_to: '{{ prometheus_target_host }}' + delegate_to: "{{ prometheus_target_host }}" - name: Read target file ansible.builtin.slurp: - src: '{{ _target_path }}' + src: "{{ _target_path }}" register: _target_file_content - delegate_to: '{{ prometheus_target_host }}' + delegate_to: "{{ prometheus_target_host }}" when: _target_file_stat.stat.exists - name: Parse YAML and add host to matching target group @@ -37,21 +37,21 @@ {%- set ns.found = true -%} {%- set _ = ns.result.append(group) -%} {%- else -%} - {%- set filtered_targets = group.targets | reject('equalto', _target_host) | list -%} + {%- set filtered_targets = group.targets | reject("equalto", _target_host) | list -%} {%- if filtered_targets | length > 0 -%} {%- if group_labels | length > 0 -%} - {%- set _ = ns.result.append({'labels': group_labels, 'targets': filtered_targets}) -%} + {%- set _ = ns.result.append({"labels": group_labels, "targets": filtered_targets}) -%} {%- else -%} - {%- set _ = ns.result.append({'targets': filtered_targets}) -%} + {%- set _ = ns.result.append({"targets": filtered_targets}) -%} {%- endif -%} {%- endif -%} {%- endif -%} {%- endfor -%} {%- if not ns.found -%} {%- if _target_labels | length > 0 -%} - {%- set new_group = {'labels': _target_labels, 'targets': [_target_host]} -%} + {%- set new_group = {"labels": _target_labels, "targets": [_target_host]} -%} {%- else -%} - {%- set new_group = {'targets': [_target_host]} -%} + {%- set new_group = {"targets": [_target_host]} -%} {%- endif -%} {%- set _ = ns.result.append(new_group) -%} {%- endif -%} @@ -59,13 +59,13 @@ - name: Write updated target file ansible.builtin.copy: - content: '{{ _updated_targets | to_nice_yaml(indent=2, width=1337) }}' - dest: '{{ _target_path }}' - mode: '0644' - delegate_to: '{{ prometheus_target_host }}' + content: "{{ _updated_targets | to_nice_yaml(indent=2, width=1337) }}" + dest: "{{ _target_path }}" + mode: "0644" + delegate_to: "{{ prometheus_target_host }}" become: true register: _yaml_result - name: Track changes ansible.builtin.set_fact: - changed: '{{ changed | default(false) or _yaml_result.changed }}' + changed: "{{ changed | default(false) or _yaml_result.changed }}" |