ansible - 如何使用 ansible 从 prometheus.yml 文件中删除特定的行块?
问题描述
我有一个 prometheus.yml 配置文件,其中配置了多个用于监控的 k8s 集群。由于服务器来来去去,我们需要使用 ansible 删除从我们的 peometheus.yml 配置文件中删除的服务器。
我尝试了以下方法,但没有奏效。
https://docs.ansible.com/ansible/2.5/modules/blockinfile_module.html
- hosts: blocks
tasks:
- name: Removing a line using blockinfile
blockinfile:
dest: /home/mdtutorials2/block_output.txt
marker: <!-- {mark} Adding IP address -->
state: absent
普罗米修斯.yml
# *************************************************************START-RAVVE*****************************************************************************************
# metrics for kubernetes scheduler and controller
- job_name: 'ravve.ntnxsherlock.com-scheduler-and-controller'
scrape_interval: 5s
static_configs:
- targets: ['ip-172-31-12-14.us-east-2.compute.internal:10251']
labels:
customer: 'RAVVE'
# metrics foom node exporter
- job_name: 'ravve.ntnxsherlock.com-nodes-exporter'
scrape_interval: 5s
static_configs:
- targets: ['ip-172-31-12-14.us-east-2.compute.internal:9100']
labels:
customer: 'RAVVE'
- targets: ['ip-172-31-13-200.us-east-2.compute.internal:9100']
labels:
customer: 'RAVVE'
# metrics from cadvisory
- job_name: 'ravve.ntnxsherlock.com-cadvisor'
scrape_interval: 10s
metrics_path: "/metrics/cadvisor"
static_configs:
- targets: ['ip-172-31-12-14.us-east-2.compute.internal:10255']
labels:
customer: 'RAVVE'
# metrics for default/kubernetes api's from the kubernetes master
- job_name: 'ravve.ntnxsherlock.com-apiservers'
kubernetes_sd_configs:
- role: endpoints
api_server: https://ip-172-31-12-14.us-east-2.compute.internal
tls_config:
insecure_skip_verify: true
basic_auth:
username: admin
password: XXXXXXXXXXXXXXXX
scheme: https
tls_config:
insecure_skip_verify: true
basic_auth:
username: admin
password: XXXXXXXXXXXXX
relabel_configs:
- source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name]
action: keep
regex: default;kubernetes;https
# **************************************************************END-RAVVE*****************************************************************************************
现在我需要删除开始和结束集群之间的线
Start *************************************************************START-RAVVE*****************************************************************************************
End
# **************************************************************END-RAVVE*****************************************************************************************
解决方案
推荐阅读
- r - 如何根据变量对数据进行分组?
- c++ - C++ 表达式树遍历以将表达式更改为 NNF
- python - 如何交换数组中的二维
- swift - 如何指定 UIViewController 一个 CXProviderDelegate 将在接听电话时打开?
- gradle - 运行“meteor add-platform android”时出现 Gradle 路径错误
- c# - C# Newtonsoft JSON:反序列化和跳过对象名称
- swift - Alamofire ssl 错误的证书 Swift
- python - Lambda - Python - “errorMessage”:“列表索引必须是整数,而不是 str”
- python - 将 Google colab 连接到 Google Compute Engine 实例上的运行时
- android - 如何在继续执行之前等待侦听器运行