with_first_found and templates

We've got a task like this:

  - name: template TrustedHosts
    template: dest=/etc/opendkim/TrustedHosts src={{ item }} backup=yes
    with_first_found:
      - TrustedHosts.{{ stack }}
      - TrustedHosts.default

There are three hosts that use the playbook this is in, and when Ansible
gets to this task, it says

   TASK: [../../shared/roles/opendkim | template TrustedHosts] *******************
    fatal: [host3] => {'msg': 'unable to read /home/jsmift/ansible/shared/roles/opendkim/templates', 'failed': True}
    fatal: [host2] => {'msg': 'unable to read /home/jsmift/ansible/shared/roles/opendkim/templates', 'failed': True}
    fatal: [host3] => {'msg': 'One or more items failed.', 'failed': True, 'changed': False, 'results': [{'msg': 'unable to read /home/jsmift/ansible/shared/roles/opendkim/templates', 'failed': True}]}
    fatal: [host2] => {'msg': 'One or more items failed.', 'failed': True, 'changed': False, 'results': [{'msg': 'unable to read /home/jsmift/ansible/shared/roles/opendkim/templates', 'failed': True}]}
    fatal: [hos1] => {'msg': 'unable to read /home/jsmift/ansible/shared/roles/opendkim/templates', 'failed': True}
    fatal: [host1] => {'msg': 'One or more items failed.', 'failed': True, 'changed': False, 'results': [{'msg': 'unable to read /home/jsmift/ansible/shared/roles/opendkim/templates', 'failed': True}]}

(Hostnames changed to protect the innocent.)

It works fine if I change it to

  - name: template TrustedHosts
    template: dest=/etc/opendkim/TrustedHosts src={{ item }} backup=yes
    with_first_found:
      - ../templates/TrustedHosts.{{ stack }}
      - ../templates/TrustedHosts.default

That suggests to me that it's searching relative to the 'files' directory
of this role; I had expected it to search relative to the 'templates'
directory, since this task uses the template module.

Should the initial task work as written (i.e. is this a bug)? If not, is
there a better way to do this, or is "../templates" the right answer?

                                      -Josh (jbs@care.com)

This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.

Hi Josh,

The various “with_” operators in ansible are generic so this shouldn’t be specific to the template module, but that does seem a bit curious.

I amw ondering if it’s because with_first_found is not returning an os.path.abspath or has some weird logic in there.

Can you please file a bug on this one so we can look at it?

Thanks!

Can you please file a bug on this one so we can look at it?

Done: https://github.com/ansible/ansible/issues/8879 (from my personal
account, I don't have a work-related Github account at the moment).

Thanks!

                                      -Josh (jbs@care.com)

This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.

Thanks, I’ve prioritized this one up a bit, will reply on the ticket as this progresses. Thanks!