Ansible过滤器AWS AMI ID与日期


- name: gather information about all AMIs with tag key Name and value webapp
amazon.aws.ec2_ami_info:
filters:
"tag:Version": "*"
register: ec2ami_result 
- debug:
msg: "{{ ec2ami_result  }}"
- set_fact:
AMI_newid: "{{ ec2ami_result | json_query ('images[?(@.creation_date=='2020-06-30T05:17:36.000Z')].image_id') }}"

我正在获取带有一堆图像的ec2ami json数据,现在我想使用creation_date对它们进行过滤,然后获取其image_id。

我得到错误

致命:[localhost]:失败=>模板错误模板字符串:应为标记",",实际为"integer"。字符串:{{ec2ami_result|json_query('images[?(@.creation_date=='2020-06-30T05:17:36.000Z'(].image_id'(}}"}

有什么需要我修复的吗?还有一种方法,我只能在指定日期之前获得image_ids,比如说2020-05-20,所有在该日期之前创建的图像id?

修复:只需使用amazon.aws.ec2_ami_info:过滤器:创建日期:";2020年-";

这样你就可以得到属于那一年的任何ami。

要过滤ami一年,只需使用过滤器

amazon.aws.ec2_ami_info:过滤器:创建日期:"2020年-";

这将只返回创建日期的值

最新更新