# having issues with finding AMI

**URL:** <https://forum.ansible.com/t/having-issues-with-finding-ami/29214>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [December 6, 2018, 8:45pm UTC](https://forum.ansible.com/t/having-issues-with-finding-ami/29214 "2018-12-06T20:45:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frank\_Dias](https://avatars.discourse-cdn.com/v4/letter/f/eada6e/32.png) [@Frank\_Dias](https://forum.ansible.com/u/Frank_Dias)\
**Post date:** [December 6, 2018, 8:45pm UTC](https://forum.ansible.com/t/having-issues-with-finding-ami/29214/1 "2018-12-06T20:45:21Z")

</div>

ami\_search\_string: “amzn_amazon-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](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html)

launch configuration fails on ami.

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [December 6, 2018, 9:17pm UTC](https://forum.ansible.com/t/having-issues-with-finding-ami/29214/2 "2018-12-06T21:17:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Frank\_Dias](https://avatars.discourse-cdn.com/v4/letter/f/eada6e/32.png) [@Frank\_Dias](https://forum.ansible.com/u/Frank_Dias)\
**Post date:** [December 7, 2018, 12:34am UTC](https://forum.ansible.com/t/having-issues-with-finding-ami/29214/3 "2018-12-07T00:34:01Z")

</div>

- 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

---

<div class="post-metadata">

**Author:** ![Frank\_Dias](https://avatars.discourse-cdn.com/v4/letter/f/eada6e/32.png) [@Frank\_Dias](https://forum.ansible.com/u/Frank_Dias)\
**Post date:** [December 7, 2018, 12:37am UTC](https://forum.ansible.com/t/having-issues-with-finding-ami/29214/4 "2018-12-07T00:37:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [December 7, 2018, 12:38am UTC](https://forum.ansible.com/t/having-issues-with-finding-ami/29214/5 "2018-12-07T00:38:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [December 8, 2018, 9:53am UTC](https://forum.ansible.com/t/having-issues-with-finding-ami/29214/6 "2018-12-08T09:53:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Frank\_Dias](https://avatars.discourse-cdn.com/v4/letter/f/eada6e/32.png) [@Frank\_Dias](https://forum.ansible.com/u/Frank_Dias)\
**Post date:** [December 11, 2018, 6:21pm UTC](https://forum.ansible.com/t/having-issues-with-finding-ami/29214/7 "2018-12-11T18:21:15Z")

</div>

ami-0307f7ccf6ea35750

refer to this link for the latest [https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized\_AMI\_launch\_latest.html](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI_launch_latest.html)
