Skip to content

Error creating EC2 image if passing in an AMI id instead of having create.yml look it up #45

Open
@isuftin

Description

If I pass an image id along with the platform configuration, I get the following error:

The task includes an option with an undefined variable. The error was: {{ item.image or platform_generated_image_id }}: {{ (ami_info.results[index].images | sort(attribute='creation_date', reverse=True))[0].image_id }}: 'dict object' has no attribute 'images'

The problem seems to be that if I do pass in an image, the lookup play is skipped: https://github.com/ansible-community/molecule-ec2/blob/0.4/molecule_ec2/cookiecutter/%7B%7Bcookiecutter.molecule_directory%7D%7D/%7B%7Bcookiecutter.scenario_name%7D%7D/create.yml#L138-L147

As a result, Ansible hits this line: https://github.com/ansible-community/molecule-ec2/blob/0.4/molecule_ec2/cookiecutter/%7B%7Bcookiecutter.molecule_directory%7D%7D/%7B%7Bcookiecutter.scenario_name%7D%7D/create.yml#L221

platform_image_id: "{{ item.image or platform_generated_image_id }}"

And even though item.image exists, Ansible still tries to run the line above it: https://github.com/ansible-community/molecule-ec2/blob/0.4/molecule_ec2/cookiecutter/%7B%7Bcookiecutter.molecule_directory%7D%7D/%7B%7Bcookiecutter.scenario_name%7D%7D/create.yml#L220

platform_generated_image_id: "{{ (ami_info.results[index].images | sort(attribute='creation_date', reverse=True))[0].image_id }}"

And that's where the error happens.

If I set platform_image_id to just platform_image_id: "{{ item.image }}" everything works fine

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ec2Amazon EC2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions