ansible/autoscaling-blog

Incorrect casting of "threshold" variable in infra role scale down alarm

Closed this issue · 2 comments

roles/infra/tasks/main.yml

- name: create scale down alarm
  ec2_metric_alarm:
    state: present
    region: "{{ region }}"
    name: "cpu-low"
    metric: CPUUtilization
    namespace: "AWS/EC2"
    statistic: Average
    comparison: "<="
    threshold: 5.0
    period: 300
    evaluation_periods: 3
    unit: "Percent"
    description: "This will alarm when cpu usage average is lower than 5% for 15 minutes "
    dimensions:
      AutoScalingGroupName: "{{ app_name }}"
    alarm_actions:
    - "{{ scale_down_policy.arn }}"
  tags: alarm

Attempting to run this playbook as-is results in the following error:

argument threshold is of invalid type: <type 'int'>, required: float

This is due to the threshold variable in the "create scale down alarm" play being cast automatically as "int" instead of float. This can be resolved by ensuring the value of threshold is in decimal form, i.e. "5.0"

I had to fork this and change it, I agree. I have other issues, like the callback not working and Debian not getting permissions to install a package.