# aws ec2 attach snapshot ansible playbook error  message

**URL:** <https://forum.ansible.com/t/aws-ec2-attach-snapshot-ansible-playbook-error-message/32197>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [February 11, 2020, 6:52am UTC](https://forum.ansible.com/t/aws-ec2-attach-snapshot-ansible-playbook-error-message/32197 "2020-02-11T06:52:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sandy.hung](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@sandy.hung](https://forum.ansible.com/u/sandy.hung)\
**Post date:** [February 11, 2020, 6:52am UTC](https://forum.ansible.com/t/aws-ec2-attach-snapshot-ansible-playbook-error-message/32197/1 "2020-02-11T06:52:50Z")

</div>

Dear all:

I have some problem I don’t know I attach ebs from snapshot but attach show error message please help thanks.

fatal: [localhost]: FAILED! =\> {  
“msg”: “The task includes an option with an undefined variable. The error was: list object has no element 0\n\nThe error appears to be in ‘/home/sandy/aws/create-EBS.yml’: line 74, column 6, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: attach ebs volume from snapshot\n ^ here\n”

- name: Get snapshot info  
ec2\_snapshot\_info:  
aws\_access\_key: “{{aws\_access\_key}}”  
aws\_secret\_key: “{{aws\_secret\_key}}”  
region: “{{ region }}”  
filters:  
“tag:Name”: snapshot  
register: ec2\_snapshot\_facts

"this error

- name: attach ebs volume from snapshot  
ec2\_vol:  
aws\_access\_key: “{{ aws\_access\_key }}”  
aws\_secret\_key: “{{ aws\_secret\_key }}”  
region: “{{ region }}”  
zone: “{{zone}}”  
instance: “{{ instance\_id }}”  
device\_name: “{{ device\_name }}”  
snapshot\_ids: ‘{{ec2\_snapshot\_facts.snapshots[0].snapshot\_id}}’  
with\_items: “{{instance\_id}}”

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [February 11, 2020, 8:36am UTC](https://forum.ansible.com/t/aws-ec2-attach-snapshot-ansible-playbook-error-message/32197/2 "2020-02-11T08:36:53Z")

</div>

> Dear all:
> 
> I have some problem I don't know I attach ebs from snapshot but attach show error message please help thanks.
> 
> fatal: [localhost]: FAILED! =\> {  
> "msg": "The task includes an option with an undefined variable. The error was: list object has no element 0\n\nThe  
> error appears to be in '/home/sandy/aws/create-EBS.yml': line 74, column 6, but may\nbe elsewhere in the file depending  
> on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: attach ebs volume from snapshot\n  
> ^ here\n"
> 
> - name: Get snapshot info  
> ec2\_snapshot\_info:  
> aws\_access\_key: "{{aws\_access\_key}}"  
> aws\_secret\_key: "{{aws\_secret\_key}}"  
> region: "{{ region }}"  
> filters:  
> "tag:Name": snapshot  
> register: ec2\_snapshot\_facts
> 
> "this error

There are no results in the ec2\_snapshot\_facts.snapshots, thus retrieving the first element of this list  
causing this error.

To see what is within ec2\_snapshot\_facts add a debug task:

- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;msg: "{{ ec2\_snapshot\_facts }}"

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke
