I've got one of those situations where I could write a three task role to lookup, sort and extract a set of values like:
- name: Lookup available AMI instances
amazon.aws.ec2_ami_info:
filters: ...
register: _ami_info
- name: Sort by creation date to get latest
ansible.builtin.set_fact:
_amis: '{{ _ami_info.images | sort(attribute="creation_date", reverse=True) }}'
- name: Set my facts for the latest AMI
latest_ami_id: '{{ _amis[0].image_id }}
...
I need to do this sort of thing in a couple different playbooks, so I want code reuse. What seems cooler and more Anible-like would be to implement a Lookup plugin, but that's many more lines of Python with calls to Boto3 to effectively do the same thing (except returning the details as a dict).
Can't seem to find anything in best practices for roles that covers this, or more than likely I am missing something.