0

I'm trying to pass variable data from one value to another task in Ansible and it fails due to square brackets, I've tried to see how to remove them but nothing helped. My Playbook related part is:

- name:                       List Volumes
  ec2_vol_facts:
    region:                   "{{ region }}"
    filters:
      attachment.instance-id: "{{ ec2_id }}"
  register:                   vol_list

- name:                       Tagging XVDF
  ec2_vol:
    region:                   "{{ region }}"
    id:                       "{{ vol_list.volumes | json_query('[?attachment_set.device==`xvdf`].id')|list }}"
    instance:                 "{{ ec2_id }}"
    state:                    present
    tags:
      org_instance:           "{{  ec2_id }}"
      mapping:                "xvdf"

This eventually failed with the following error:

 "msg": "InvalidParameterValue: Value (['vol-0506598']) for parameter volumes is invalid. Expected: 'vol-...'."

Other parameters are passing correctly, so what is missing here? Thanks for the help.

Tomer Leibovich
  • 313
  • 5
  • 17
  • You are creating a list with `list` filter. `id` parameter is expected to be a string. You must pass the first element of that list. – techraf Jun 02 '18 at 19:58
  • Just tested it with the following code: id: "{{ vol_list.volumes | json_query('[?attachment_set.device==`xvdf`].id')}}" Got the same error. – Tomer Leibovich Jun 02 '18 at 20:35
  • assuming I know the where in the list is the ID - yes, it will work out. However, my goal is to retrieve the ID without knowing the exact place in the list. – Tomer Leibovich Jun 02 '18 at 20:40
  • Assuming I know which element number is the ID, I could get it as you've suggested in the linked post [0]...[3]... However, I need to get the vol-id only by filtering by device name. – Tomer Leibovich Jun 02 '18 at 20:45
  • Sorry if you've got impression.. So, how? – Tomer Leibovich Jun 02 '18 at 20:58
  • Add `| first` between `list` and `}}`, exactly as written in the answer. – techraf Jun 02 '18 at 20:59

0 Answers0