此前已在Stack上回答过这个问题。
ansible get aws ebs volume id which already exist
Get volume id from newly created ebs volume using ansible
对于我的生活,我正在尝试ec2_vol.volume_id和其他一些jmespath查询位,但没有得到正确的输出帮助。我只想要卷号。没什么。
---
- hosts: localhost
connection: local
gather_facts: no
tasks:
- name: get associated vols
ec2_vol:
instance: i-xxxxxxxxxxxxx
state: list
profile: default
region: us-east-1
register: ec2_vol
- debug:
msg: "{{ ec2_vol.volume_id }}"
也不起作用
---
- hosts: localhost
connection: local
gather_facts: no
tasks:
- name: get associated vols
ec2_vol:
instance: i-xxxxxxxxxxxxxx
state: list
profile: default
region: us-east-1
register: ec2_vol
- debug: msg="{{ item.volume_id }}"
with_items: ec2_vol.results
Ansible 2.2和2.3测试
答案 0 :(得分:1)
从先前的答案中取出一些内容,您需要了解JMESPATH,例如过滤,以便从输出中获得您想要的内容。
以下是答案
---
- hosts: localhost
connection: local
gather_facts: no
tasks:
- name: get associated vols
ec2_vol:
instance: i-xxxxxxxxxxxxxx
state: list
profile: default
region: us-east-1
register: ec2_vol
- debug: msg="{{ ec2_vol.volumes | map(attribute='id') | list }}"