having issues with finding AMI

ami_search_string: “amznamazon-ecs-optimized

ec2_ami_find:
name: “{{ ami_search_string }}”
region: “{{ region }}”
virtualization_type: hvm
owner: aws-marketplace
sort: creationDate
sort_order: descending
sort_end: 1
register: os_image
when:

  • lc_ami is not defined

failing to discover the ami from the following;

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html

launch configuration fails on ami.

Hullo Frank.

Full playbook and full output, please!

Also, what AMI is actually selected, if any, and if none is selected, which AMI specifically did you expect to be select ed (which AMI ID)?

Regards, K.

  • name: find an ami if none is given
    ec2_ami_find:
    name: “{{ ami_search_string }}”
    region: “{{ region }}”
    virtualization_type: hvm
    owner: aws-marketplace
    sort: creationDate
    sort_order: descending
    sort_end: 1
    register: os_image
    when:

  • lc_ami is not defined

  • name: set the ami
    set_fact:
    lc_ami: “{{ os_image.results[0].ami_id }}”
    when:

  • lc_ami is not defined

  • os_image is defined

  • name: Delete previous launch configuration and auto scaling group if they exist
    include: delete_previous.yml
    when: delete_previous

  • ec2_lc:
    assign_public_ip: “{{ assign_public_ip }}”
    name: “{{ lc_name }}”
    image_id: “{{ lc_ami }}”
    key_name: “{{ keypair }}”
    region: “{{ region }}”
    security_groups: “{{ asg_security_groups }}”
    instance_type: “{{ instance_type }}”
    volumes: “{{ volumes }}”
    instance_profile_name: “{{ instance_profile_name }}”
    user_data: “{{ lookup(‘file’, user_data_file )}}”

  • ec2_asg:
    name: “{{ asg_name }}”
    launch_config_name: “{{ lc_name }}”
    min_size: “{{ asg_min }}”
    max_size: “{{ asg_max }}”
    desired_capacity: “{{ asg_des }}”
    region: “{{ region }}”
    vpc_zone_identifier: “{{ vpc_zone_identifier }}”
    tags: “{{ asg_instances_tags }}”

TASK [aws/asg : set the ami] ***************************************************
13:41:56

22
efatal: [localhost]: FAILED! => {“failed”: true, “msg”: “the field ‘args’ has an invalid value, which appears to include a variable that is undefined. The error was: list object has no element 0\n\nThe error appears to have been in ‘/var/lib/awx/projects/_1067__production_us/roles/aws/asg/tasks/main.yml’: line 14, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: set the ami\n ^ here\n”}e

here are the extra vars being set;

account: prod
ami_search_string: amzn-ami-2018.03.i-amazon-ecs-optimized
asg_name: MiscServices
cluster_name: MiscServices
instance_type: m5.2xlarge
lc_name: MiscServices
region: us-west-2

which AMI were you expecting your script to find? Region, ID?

Hullo Frank.

What specific AMI did you expect your code to find?

Did you manually locate that AMI in the available AMIs for that region?

I.e., do you know for a fact that the AMI you seek does exist and does match that search string? Please tell us the specific AMI ID that you think matches your search string.

Also, you have provided two different search strings - which one is being used by your code?

Regards, K.

ami-0307f7ccf6ea35750

refer to this link for the latest https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI_launch_latest.html