FYI: What is PWD when executed as host:localhost vs delegate_to vs local_action ?

213 views
Skip to first unread message

Larry Fast

unread,
Jun 25, 2014, 6:27:04 PM6/25/14
to ansible...@googlegroups.com
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      

Michael DeHaan

unread,
Jun 25, 2014, 6:41:16 PM6/25/14
to ansible...@googlegroups.com
No offense intended, but care to relate what you found in words and what you mean by "a special case" ?

I also don't know what you mean by "vars.playbook_dir" with the dot notation, which is difficult because I wrote the program :)




--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
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.

Reply all
Reply to author
Forward
0 new messages