aws ec2 attach snapshot ansible playbook error message

16 views
Skip to first unread message

Sandy Hung

unread,
Feb 11, 2020, 1:52:50 AM2/11/20
to Ansible Project
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}}"

Stefan Hornburg (Racke)

unread,
Feb 11, 2020, 3:37:25 AM2/11/20
to ansible...@googlegroups.com
On 2/11/20 7:52 AM, Sandy Hung wrote:
> 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

>
>
> - 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}}"
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/d9a813cb-04b7-4c6d-9d87-eedc8b65c8cd%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/d9a813cb-04b7-4c6d-9d87-eedc8b65c8cd%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc
Reply all
Reply to author
Forward
0 new messages