Json 如何获取ansible中嵌套变量的值

Json 如何获取ansible中嵌套变量的值,json,ansible,yaml,Json,Ansible,Yaml,我正在尝试从下面的文件中逐个获取警报值,以执行某些操作。有没有办法做到这一点 apiVersion: monitoring.coreos.com/v1 kind: PrometheusRule metadata: labels: prometheus: k8s role: alert-rules app: prometheus-operator

我正在尝试从下面的文件中逐个获取警报值,以执行某些操作。有没有办法做到这一点

        apiVersion: monitoring.coreos.com/v1
        kind: PrometheusRule
        metadata:
          labels:
            prometheus: k8s
            role: alert-rules
            app: prometheus-operator
            release: prometheus-operator
          annotations:
            exclude.release.openshift.io/internal-openshift-hosted: "true"
          creationTimestamp: "2020-04-22T09:22:14Z"
          generation: 1
          name: free-memory-percentage
          namespace: openshift-monitoring
          selfLink: /apis/monitoring.coreos.com/v1/namespaces/openshift-cloud-credential-operator/prometheusrules/cloud-credential-operator-alerts
        spec:
          groups:
          - name: free-memory
            rules:
            - alert: node_mem_free_Percentage
              annotations:
                description: Node memory is under pressure
              expr: 100 - (100 * node_memory_MemFree_bytes / node_memory_MemTotal_bytes) < 50
              for: 2m
          - name: High-CPU-Usage
            rules:
            - alert: HighCPUUsage4test
              annotations:
                description: CPU usage is above the 0% threshold
              expr: (100 - (avg by (instance) (irate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)) > 0
              for: 2m
apiVersion:monitoring.coreos.com/v1 种类:普罗米修斯规则 元数据: 标签: 普罗米修斯:k8s 角色:警报规则 应用程序:普罗米修斯操作员 释放:普罗米修斯操作员 注释: exclude.release.openshift.io/internal-openshift-hosted:“true” creationTimestamp:“2020-04-22T09:22:14Z” 世代:1 名称:可用内存百分比 名称空间:openshift监视 selfLink:/api/monitoring.coreos.com/v1/namespace/openshift-cloud-credential-operator/prometheusrules/cloud-credential-operator-alerts 规格: 组: -名称:可用内存 规则: -警报:节点\内存\空闲\百分比 注释: 描述:节点内存处于压力下 表达式:100-(100*节点内存内存空闲字节/节点内存内存总字节)<50 费用:200万美元 -名称:高CPU使用率 规则: -警报:HighCPUUsage4test 注释: 说明:CPU使用率高于0%阈值 expr:(100-(实例的平均值)(irate(node_cpu_seconds_total{mode=“idle”}[5m])*100))>0 费用:200万美元 Q:“从文件中逐个获取警报值。”

A:使用。给定带有变量的
文件.yml
,下面的任务

-包括变量:
文件:file.yml
名称:my_数据
-设定事实:
my_alerts:“{my_data.spec.groups}json_查询('[].rules[].alert')}”
-调试:
var:my_警报
给予

my_警报:
-节点\内存\自由\百分比
-高CPUUSAGE4测试

到目前为止您尝试了什么?我会将警报硬编码到一个数组中,并将其存储在all.yml文件中,然后使用该数组。但是,我现在需要直接从文件中获取值,并在任务文件中执行操作。