local_action. Current working directory

I’m executing the same script at two different hosts. Script just returns current working directory:

tasks:

  • name: Get exec_path localaction
    local_action: command pwd
    register: res
  • debug: var=res.stdout_lines

At both hosts script is locted in /opt/test
In one host I’m getting script location:
TASK [debug] *************************************************************************************************************************************************************************************************
ok: [single] => {
“res.stdout_lines”: [
“/opt/test”
]
}

On another: /root

TASK [debug] *********************************************************************************************************************************************
ok: [ single ] => {
“res.stdout_lines”: [
“/root”
]
}

Why it is so? How to make on second host run local_action from scrit location?

I have no idea. Can be many things, home directory of the user account you’re using, for one.
But why do you want to rely on something that is (clearly) not stable?
I would just set a directory and make sure it’s there, and use that to do what needs to be done.
It’s also more according to the ansible philosophy, I think, to make things explicit rather than depending on things that may be different (for reasons that you don’t know, in this case).

Dick

The 'script' action would copy a script from the controller to the
target, run it and remove it, that way you can store it in a
predictable spot adjacent to playbook or in role.
Also you only need to ever update 1 copy of it.