ansible-community / ansible-community/molecule-plugins

FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: list object has no element 0

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

Description

When running a test in molecule I get the following error:

> TASK [Populate instance config dict] *******************************************
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/geoff/working/ansible/dynatrace-deploy/molecule/aws/create.yml': line 114, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Populate instance config dict\n ^ here\n"}

having looked through the create.yml file and debugged the result of `ec2-jobs` it looks like the instances object is empty

- name: Populate instance config dict
set_fact:
instance_conf_dict: {
'instance': "{{ item.instances[0].tags.instance }}",
'address': "{{ item.instances[0].public_ip }}",
'user': "{{ ssh_user }}",
'port': "{{ ssh_port }}",
'identity_file': "{{ key_pair_path }}",
'instance_ids': "{{ item.instance_ids }}", }
with_items: "{{ ec2_jobs.results }}"
register: instance_config_dict
when: server.changed | bool

It appears the data is now in the 'tagged_instances' object so have made the change.

- name: Populate instance config dict
set_fact:
instance_conf_dict: {
'instance': "{{ item.tagged_instances[0].tags.instance }}",
'address': "{{ item.tagged_instances[0].public_ip }}",
'user': "{{ ssh_user }}",
'port': "{{ ssh_port }}",
'identity_file': "{{ key_pair_path }}",
'instance_ids': "{{ item.instance_ids }}", }
with_items: "{{ ec2_jobs.results }}"
register: instance_config_dict
when: server.changed | bool

Whilst changing this locally fixed the issue, a further issue occurs later:
```
TASK [Dump instance config] ****************************************************
fatal: [localhost]: FAILED! => {"msg": "template error while templating string: no filter named 'molecule_header'. String: {{ instance_conf | to_json | from_json | molecule_to_yaml | molecule_header }}"}
```
I will be honest, this is where I start to get a little lost... I am not sure where any of those variables come from so I cannot check whether they are still valid...

Can anyone help?

>

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with molecule/aws/create.yml around line 114 and inspect the ec2-jobs results used by “Populate instance config dict,” including the tagged_instances data mentioned in the report. Then trace the “Dump instance config” task and its molecule_header filter, and run the affected Molecule scenario. Done means the scenario completes without either reported template error and the expected instance configuration is dumped.

Written by the indexing model from the issue text.

Assessment

Tech stack
ansible, aws, python
Domain
cloud, devops, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.