Thought I’d share some gory details I just worked through. I was writing a self-check playbook and wanted to look at files in the playbook directory. Note that a module would probably solve my problem more effectively than PB code but here’s what I found…
- vars.playbook_dir=‘.’ - as you’ll see this doesn’t necessarily take you to the right location
- vars.inventory_dir= - this is better but only if inventory_dir=playbook_dir
So my attempts to use #1 went south until I discovered the following variations. As stated in the documentation, local_action is an alias for delegate_to: localhost or 127.0.0.1. What’s not stated is that “delegate_to localhost” is treated as a special case. delegate_to any-other-server will work the same as hosts: any-other-server
-
hosts: localhost
ssh_user: hi_there
tasks: -
name: pwd_localhost
command: pwd => /home/hi_there
register: pwd_localhost -
name: pwd_delegate_dns
command: pwd => /home/hi_there
delegate_to: dns_of_localhost
register: pwd_delegate_dns
- name: pwd_delegate_localhost
command: pwd =>
delegate_to: localhost
register: pwd_delegate_localhost
-
name: pwd_local_action
local_action: command pwd =>
register: pwd_local_action -
name: pwd_127
command: pwd =>
delegate_to: 127.0.0.1
register: pwd_127