amazon-web-services - Ansible 列表为空时有长度
问题描述
我正在做“aws rds describe-db-instances”:
- name: list recovery points by resource
shell: aws rds describe-db-instances --db-instance-identifier {{ item }} --query "DBInstances[?(LatestRestorableTime>'{{ time }}')].[DBInstanceIdentifier,LatestRestorableTime]" --output text
loop: "{{ db_identifier }}"
register: recovery_points
environment:
AWS_ACCESS_KEY_ID: "{{ aws_access_key }}"
AWS_SECRET_ACCESS_KEY: "{{ aws_secret_key }}"
AWS_SESSION_TOKEN: "{{ security_token }}"
-->until: (recovery_points.results|map(attribute='stdout')|list|length) > 0
-->retries: 20
-->delay: 30
when: db_identifier is defined
这应该检查早于“时间”的恢复点,还有 db_identifier|lenght = 2。
- debug:
msg: "{{ recovery_points.results | map(attribute='stdout') | list }}"
结果:
['', '']
我面临的问题是,当没有恢复点并且它返回这个空列表时,它说这个列表的长度是 2。
- debug:
msg: "{{ recovery_points.results | map(attribute='stdout') | list | length }}"
结果:
2
有了这个,我想在 shell 命令中包含“直到”条件(你可以看到前面有 -->),但由于这个长度,我不能这样做。
我该如何解决它?
解决方案
推荐阅读
- python - 我可以在数据框的列中使用模糊模糊来执行操作吗
- c# - Control.Invoke 不调用
- heroku - Heroku 无法部署 ENOENT
- javascript - 将纹理放在 obj 文件上
- apache-spark - 火花连接问题
- javascript - 使用自定义视图在 columnrange highcharts 中对类别进行分组
- angular - .detectChanges() not working within Angular test
- r - 如果变量名称的格式不一致,如何更正/标准化变量名称
- spring-integration - 用于在流程中存储和检索的弹簧集成 dsl 流程变量
- algorithm - 寻找复杂性的下限和上限