aws ec2 attach snapshot ansible playbook error message

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}}”

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:
    msg: "{{ ec2_snapshot_facts }}"

Regards
        Racke