When we run a playbook, with verbose output enabled, in the ansible logs we can see something like this:
2016-02-03 12:51:58,235 p=4105 u=root | PLAY RECAP
You can define the PID for localhost using the set_fact module with a lookup filter.
set_fact
lookup
- hosts: localhost tasks: - set_fact: pid: "{{ lookup('pipe', 'echo $PPID') }}"
And later on you can reference the PID via the hostvars dictionary.
PID
hostvars
- hosts: remote tasks: - debug: var=hostvars.localhost.pid