local_action. Current working directory

20 views
Skip to first unread message

Алексей Глушков

unread,
Jun 20, 2023, 9:44:06 AM6/20/23
to Ansible Project
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?

Dick Visser

unread,
Jun 20, 2023, 12:34:55 PM6/20/23
to ansible...@googlegroups.com
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

Brian Coca

unread,
Jun 20, 2023, 12:43:58 PM6/20/23
to ansible...@googlegroups.com
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.


--
----------
Brian Coca

Reply all
Reply to author
Forward
0 new messages