ansible-community / ansible-community/molecule-plugins

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

Open
#45 3 comments 1 reaction 0 assignees View on GitHub
ec2
Dominant language
Python
Stars
164
Forks
113
Avg merge
4d 20h
Merged PRs (30d)
1

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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading the create.yml template at lines 138-147 and 220-221, focusing on how the AMI lookup is skipped and how platform_generated_image_id is evaluated. Done means passing an explicit platform image ID no longer evaluates the missing ami_info.results entry and successfully creates the EC2 image.

Written by the indexing model from the issue text.

Assessment

Domain
cloud
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.