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...
1. vars.playbook_dir='.' - as you'll see this doesn't necessarily take you
to the right location
2. vars.inventory_dir= <fullpath> - 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 => <fullpath to playbook directory>
delegate_to: localhost
register: pwd_delegate_localhost
- name: pwd_local_action
local_action: command pwd => <fullpath to playbook directory>
register: pwd_local_action
- name: pwd_127
command: pwd => <fullpath to playbook directory>
delegate_to: 127.0.0.1
register: pwd_127
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/929f2e1f-d768-4c55-a22e-9a742c448a24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.