locations for the "lookup('file'...)

Hi,

I’m trying to get through my “slow” day here - can’t figure out (or locate documetation explaining it) - where does “lookup(‘file’,…)” looks indeed.

I have a structure:

group_vars/all.yml
pgsql_key
pgsql_key.pub
roles/pgsql/tasks/main.yml
site.yml

under all.yml I have var defined:

pgsql_ssh_key=“pgsql_key”

inside of roles/pgsql/tasks/main.yml I have:


debug: var=pgsql_ssh_key
debug: msg={{ lookup(‘file’,pgsql_ssh_key) }}

site.yml is simple:

  • hosts: pgsql
    roles:
  • pgsql

however I get empty contents of lookup call while debug for the pgsql_ssh_key returns proper value. Seems like lookup wants to pick up my pgsql_ssh_key under roles/pgsql/files, but I’d like to keep it top-level (other roles will be using it). What did I miss?

It looks relative to the playbook root, and if in roles, will look in the “files/” dir of roles.

If you try it and it can’t find something, it will tell you where it looked.

It looks relative to the playbook root, and if in roles, will look in the “files/” dir of roles.

I’ve noticed that it does look in role’s “files” dir but apparently it doesn’t look at playbook root. Is there a parameter I tweaked someplace?

If you try it and it can’t find something, it will tell you where it looked.

tells me it can’t find it in roles/pgsql/files

It won’t look in the playbook root when inside a role, no. Sorry I mispoke on that one.

You can path the src as {{ lookup(‘file’, playbook_dir + ‘/filename’) }} if you want this, and it will find things there using the (derived) path of the playbook root.

Ansible will look in the root if you are not using roles.

Relative pathing would also find it.