Skip to content

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

Open
@geoffo-dev

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?

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