2016-06-08 42 views
0

创建CloudWatch的健康检查我有具有RDS端点作为一个清单文件:无法通过Ansible

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

我写了下面的戏书创建CloudWatch的警报:

--- 

    - 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 

这里有什么问题?我能做些什么来解决这个问题?我对此很陌生,但肯定这似乎与我一些语法问题或我正在采取清单端点拆分的方式。

+0

所以,恩,你是否与@ nishant-singh合作,[谁发布了类似的问题](https://stackoverflow.com/questions/37674377/creating-cloudwatch-alarm-metrics-using-ansible)? – tedder42

回答

1

从调试的变量没有被分配在第一个调试语句,但你可以,如果你将其更改为一条消息,并引号和双括号(未经测试)括起来:

- 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]}}" 

UPDATE:添加threshold: 80.0到最后一个任务,并且尺寸需要使用封装的双括号的实例ID。

+0

试过这个还是一样的错误,ps我在'localhost'上运行这个,我应该担心吗? – PythonFreak

+0

您是否尝试过set_fact或调试修改? – Theo

+0

Localhost不会有所作为,但set_fact的事实将设置为localhost。 – Theo