无法通过Ansible创建CloudWatch Healthcheck

时间:2016-06-08 10:49:49

标签: ansible boto ansible-playbook

我有一个库存文件,其RDS端点为:

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

我写了以下游戏书来创建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

这里有什么问题?我该怎么做才能解决这个问题?我是新手,但肯定这似乎是我的一些语法问题或我采取库存终端分裂的方式。

1 个答案:

答案 0 :(得分:0)

调试中的变量未在第一个调试语句中分配,但如果您将其更改为消息并用引号和双括号(未经测试)将其括起来,则可能是这样:

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

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

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

更新:在上一个任务中添加threshold: 80.0,尺寸需要使用用双括号封装的实例ID。