【发布时间】:2020-04-08 13:23:34
【问题描述】:
所以我遇到了 Ansible + AWS EC2 这个致命问题。
如果磁盘类型为“io1”,则应指定“iops”,否则不应指定。 如果我想让磁盘类型可配置,我必须在何时申请,但它不起作用:
- name: Provision AWS Instances
ec2:
instance_type: "{{ ec2_instance_type }}"
image: "{{ ec2_ami_id }}"
...
volumes:
- device_name: "{{ ec2_root_disk_name }}"
volume_type: "{{ ec2_root_disk_type }}"
volume_size: "{{ ec2_root_disk_size }}"
delete_on_termination: "{{ ec2_root_disk_delete_on_termination }}"
iops: "{{ ec2_root_disk_iops }}"
when: ec2_root_disk_type == 'io1'
- device_name: "{{ ec2_root_disk_name }}"
volume_type: "{{ ec2_root_disk_type }}"
volume_size: "{{ ec2_root_disk_size }}"
delete_on_termination: "{{ ec2_root_disk_delete_on_termination }}"
when: ec2_root_disk_type != 'io1'
但是,这个嵌套的“when”条件没有被处理,驱动器被添加了两次:
"volumes": [
{
"delete_on_termination": "true",
"device_name": "/dev/sda1",
"iops": "100",
"volume_size": "30",
"volume_type": "gp2",
"when": "ec2_root_disk_type == 'io1'"
},
{
"delete_on_termination": "true",
"device_name": "/dev/sda1",
"volume_size": "30",
"volume_type": "gp2",
"when": "ec2_root_disk_type != 'io1'"
},
]
我可以在整个命令中添加“何时”,但我最多可以有 5 个驱动器,所以这意味着复制它超过 32 次。
是否可以在嵌套列表上使 Ansible 进程“何时”?
是否可以将这个列表组装到一个变量中,在这个命令中引用它? Ansible 的文档对非字符串的结构化变量保持沉默。也许我可以以某种方式应用集合过滤?
这里推荐的行动方案是什么?我想每个人在尝试创建可配置类型的卷时都会遇到这个确切的问题。
【问题讨论】:
标签: amazon-ec2 scripting ansible