Behaviour of lookup in standalone playbook vs called playbook

17 views
Skip to first unread message

David Fetrow

unread,
Aug 4, 2015, 7:03:53 PM8/4/15
to Ansible Project

I have playbook that, when run by itself, looks up various values on the ansible host (e.g. the repository version of a roles directory) and writes them to a log on the ansible target.  

The idea being keeping a log of who ran what versions of what playbooks from where.  It's the kind of info you hope to never need but can be invaluable if you do.

Anyway; here's a snippet.

.....
  AnsibleGit:  "{{ lookup('pipe', 'git log  | head -1') }}"
.....
 - shell: echo "{{ EpochTime }}  git {{ AnsibleGit }}"               >>  {{ Log }}


When I include the playbook as one playbook among many in setting up a server (as opposed to running it standalone) the lookups run on
the target rather than the host. 

I can make something that gets that information by other means but I'd rather use lookup if I can. 

Any ideas how to get lookup to always run on the host?

  -david



Brian Coca

unread,
Aug 4, 2015, 7:06:23 PM8/4/15
to Ansible Project
lookups always run on the machine that executes the ansible-playbook
program (master), not sure what you mean by host or target.

The only way to run something other than on the master is through a
task. A lookup can query an API or some other remote resource (uri
lookup) but it runs on the master and the master must have access to
that remote resource.


--
Brian Coca
Reply all
Reply to author
Forward
0 new messages