How to delete old launch configuration using ansible code

时间:2016-06-07 11:28:57

标签: amazon-web-services ansible-playbook

I am working on autoscaling ansible project can somebody tell me how I can delete old launch configuration using ansible playbooks.

Thanks

1 个答案:

答案 0 :(得分:1)

不久前,I've created a pull request用于新的Ansible模块,您可以使用它来查找旧的启动配置并删除它们。

例如,如果您希望保留前10个最新的启动配置,并删除旧配置,则可以执行以下任务:

---

- name: "Find old Launch Configs"
  ec2_lc_find:
    profile: "{{ boto_profile }}"
    region: "{{ aws_region }}"
    name_regex: "*nameToFind*"
    sort: true
    sort_end: -10
  register: old_launch_config

- name: "Remove old Launch Configs"
  ec2_lc:
    profile: "{{ boto_profile }}"
    region: "{{ aws_region }}"
    name: "{{ item.name }}"
    state: absent
  with_items: old_launch_config.results
  ignore_errors: yes