lookup("template") but only if template exists

18 views
Skip to first unread message

Bret Martin

unread,
Mar 23, 2015, 4:12:33 PM3/23/15
to ansible...@googlegroups.com
I used to be able to do this in order to construct EC2 instance user data from a template, but only if the template file existed -- otherwise, leave the user data empty.

- name: create {{ description }} instance
  ec2:
[...]
    user_data: '{{ lookup("template",
                          "../templates/user_data/" + instance + ".j2")
                   | default(None) }}'

I think I was actually taking advantage of the fact that the lookup plugin used to silently eat template errors (is that right?), but no longer does -- now I get

TASK: [aws-ec2 | create Data Importer instance] *********************************
fatal: [aws-vpc-hbi16058] => unable to read /Users/bam/dev/h3-ansible/roles/aws-ec2/templates/user_data/data-importer.j2

Is there another way I can accomplish this sort of lookup-template-but-only-if-it-exists?
Reply all
Reply to author
Forward
0 new messages