Question about variables.

  • name: Gather EC2 Snapshot Info
    ec2_snapshot_info:
    filters:
    “tag:Name”: fortune
    register: snap

  • name: AMI registration from EBS Snapshot
    ec2_ami:
    name: fortune
    state: present
    architecture: x86_64
    virtualization_type: hvm
    root_device_name: /dev/xvda
    device_mapping:

  • device_name: /dev/xvda
    volume_size: 8
    snapshot_id: “{{ snap.snapshot_id }}”
    volume_type: gp2
    delete_on_termination: true
    register: ami

I’m receiving this error.

The task includes an option with an undefined variable. The error was: ‘dict object’ has no attribute 'snapshot_id

I believe is has something to do with my variable. Anyone have an idea?

I’m not familiar with the ec2_snapshot info module, but the core problem is the registered variable “snap” - which is a dictionary - does not have a key ‘snapshot_id’.

What I often do in these cases is to add a debug task immediately after the task that registers the variable which simply dumps the value of “snap”. Something like this (not tested):
`

  • name: Debug Snap Task
    debug:
    msg: “ec2_ami results {{ snap }}”
    `

This should show you whether snapshot_id exists and how to access it.

-steve