无法通过 Ansible 创建 CloudWatch Healthcheck [英] Unable to Create a CloudWatch Healthcheck via Ansible

查看:21
本文介绍了无法通过 Ansible 创建 CloudWatch Healthcheck的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个清单文件,它有一个 RDS 端点:

I have a inventory file which has a RDS endpoint as :

[ems_db]
syd01-devops.ce4l9ofvbl4z.ap-southeast-2.rds.amazonaws.com

我编写了以下剧本来创建 Cloudwatch 警报:

I wrote the following play book to create a Cloudwatch ALARM :

---

    - name: Get instance ec2 facts
      debug: var=groups.ems_db[0].split('.')[0]
      register: ems_db_name

    - name: Display
      debug: var=ems_db_name

    - name: Create CPU utilization metric alarm
      ec2_metric_alarm:
          state: present
          region: "{{aws_region}}"
          name: "{{ems_db_name}}-cpu-util"
          metric: "CPUUtilization"
          namespace: "AWS/RDS"
          statistic: Average
          comparison: ">="
          unit: "Percent"
          period: 300
          description: "It will be triggered when CPU utilization is more than 80% for 5 minutes"
          dimensions: { 'DBInstanceIdentifier' : ems_db_name }
          alarm_actions: arn:aws:sns:ap-southeast-2:493552970418:cloudwatch_test
          ok_actions: arn:aws:sns:ap-southeast-2:493552970418:cloudwatch_test

但这会导致

TASK: [cloudwatch | Get instance ec2 facts] *********************************** 
ok: [127.0.0.1] => {
    "var": {
        "groups.ems_db[0].split('.')[0]": "syd01-devops"
    }
}

TASK: [cloudwatch | Display] ************************************************** 
ok: [127.0.0.1] => {
    "var": {
        "ems_db_name": {
            "invocation": {
                "module_args": "var=groups.ems_db[0].split('.')[0]", 
                "module_complex_args": {}, 
                "module_name": "debug"
            }, 
            "var": {
                "groups.ems_db[0].split('.')[0]": "syd01-devops"
            }, 
            "verbose_always": true
        }
    }
}

TASK: [cloudwatch | Create CPU utilization metric alarm] ********************** 
failed: [127.0.0.1] => {"failed": true}
msg: BotoServerError: 400 Bad Request
<ErrorResponse xmlns="http://monitoring.amazonaws.com/doc/2010-08-01/">
  <Error>
    <Type>Sender</Type>
    <Code>MalformedInput</Code>
  </Error>
  <RequestId>f30470a3-2d65-11e6-b7cb-cdbbbb30b60b</RequestId>
</ErrorResponse>


FATAL: all hosts have already failed -- aborting

这里有什么问题?我能做些什么来解决这个问题?我对此很陌生,但肯定这对我来说似乎有些语法问题,或者我选择库存端点拆分的方式.

What is wrong here? What can i do to solve this ? I am new to this but surely this seems some syntax issue with me or the way i am picking up the inventory endpoint split.

推荐答案

debug 中的变量没有在第一个调试语句中赋值,不过如果你把它改成一条消息并用引号引起来,你也许可以和双大括号(未经测试):

The variable from debug isn't being assigned in the first debug statement, though you may be able to if you change it to a message and enclose it with quotes and double braces (untested):

 - name: Get instance ec2 facts
   debug: msg="{{groups.ems_db[0].split('.')[0]}}"
   register: ems_db_name

但是,我会在该任务中使用 set_fact 模块(而不是调试)并将该值分配给它.这样,您就可以在本次调用和后续调用中重用它.

However, I would use the set_fact module in that task (instead of debug) and assign that value to it. That way, you can reuse it in this and subsequent calls to a play.

 - name: Get instance ec2 facts
   set_fact: ems_db_name="{{groups.ems_db[0].split('.')[0]}}"

UPDATE:最后一个任务增加一个threshold: 80.0,维度需要使用双大括号封装的实例id.

UPDATE: Add a threshold: 80.0 to the last task, and the dimensions needs to use the instance id encapsulated with double braces.

这篇关于无法通过 Ansible 创建 CloudWatch Healthcheck的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆