无法更新 Prometheus Ansible 角色中的属性

问题描述 投票:0回答:1

我正在尝试使用 Prometheus 角色:https://github.com/prometheus-community/ansible

我创建了一个剧本 - playbook.yaml,包含以下内容:

---
- hosts: prometheus-server
  become: true
  roles:
    - role: prometheus.prometheus.prometheus
      prometheus_version: "2.43.0"  
      prometheus_config_dir: "/sites/prometheus"
      prometheus_web_listen_address: "0.0.0.0:9090"  
      prometheus_global: {"evaluation_interval": "1m5s", "scrape_interval": "1m", "scrape_timeout": "59s"}
      prometheus_external_labels: {"environment": "env1"}
      prometheus_alert_rules_files: ["/sites/prometheus/rules.d/rules.yml"]
      prometheus_alertmanager_config: 
        - scheme: http
          static_configs:
          - targets:
            - alertmanager-1.xxx:9093
            

库存还可以:

all:
  hosts:
    prometheus-server:
      ansible_host: x.x.x.x  
  vars:
    ansible_user: ubuntu
    ansible_ssh_private_key_file: ~/.ssh/id_rsa_test
    ansible_ssh_common_args: '-o ProxyCommand="ssh -W %h:%p -i ~/.ssh/id_rsa [email protected]"'

我更改了所有这些值以使用规则。d:

在角色/prometheus/templates/prometheus.yml.j2中:

{% if not prometheus_agent_mode and prometheus_alert_rules_files != [] %}
rule_files:
  - {{ prometheus_config_dir }}/rules.d/*.rules
{% endif %}

在roles/prometheus/tasks/configure.yml中

src: "{{ item }}"
dest: "{{ prometheus_config_dir }}/rules.d/"
owner: root

在 ansible/roles/prometheus/meta/argument_specs.yml 中,无需更改:

  prometheus_alert_rules:
    description:
      - "Full list of alerting rules which will be copied to C({{ prometheus_config_dir }}/rules.d/ansible_managed.rules)."
      - "Alerting rules can be also provided by other files located in C({{ prometheus_config_dir }}/rules.d/) which have C(*.rules) extension"
      - "Please see default values in role defaults/main.yml"
    type: "list"
    elements: "dict"

运行剧本时,它仍然返回默认路由(即使更改并保存)。

我还尝试在任务中手动添加其他未执行的任务:

https://github.com/prometheus-community/ansible/tree/9fd1b0f52954b3f6e1338ef1466a0cb8fd30fd9f/roles/prometheus/tasks

但是什么都没有...

在我的服务器中,我手动更改了值并重新启动了普罗米修斯,以运行剧本并检查它是否再次更改为“规则”路由(以查看剧本是否有效)。

不知道我能做什么...

帮助排除故障:

  • 目标服务器中的权限是相同的。
  • 我什至创建了一些未在角色中执行的任务。
  • 剧本中触发了SCP警告(我认为这与问题无关)。

我收到的一些警告: 添加警告:

[WARNING]: sftp transfer mechanism failed on [X.X.X.X]. Use ANSIBLE_DEBUG=1 to see detailed information
[WARNING]: scp transfer mechanism failed on [X.X.X.X]. Use ANSIBLE_DEBUG=1 to see detailed information
ansible yaml prometheus roles
1个回答
0
投票

您需要使用

role.var
来设置变量,但您将它们直接放置为
role
的键。例如:

- hosts: prometheus-server
  become: true
  roles:
    - role: prometheus.prometheus.prometheus
      # Correct use of variables for your role
      vars:
        prometheus_version: "2.43.0"  
        prometheus_config_dir: "/sites/prometheus"
        # ...

但是你使用了这样的东西:

- hosts: prometheus-server
  become: true
  roles:
    - role: prometheus.prometheus.prometheus
      # WON'T WORK AS NOT UNDER role.var 
      prometheus_version: "2.43.0"  
      prometheus_config_dir: "/sites/prometheus"
      # ...

请参阅 https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_reuse_roles.html#using-roles

© www.soinside.com 2019 - 2024. All rights reserved.