On Tue, May 14, 2019, at 8:20 PM, Kevin Kwon wrote:
>
>
> Hi..
>
> I want to change the current directory in remote host by Ansible.
> so, i have created the playbook like below. but, it is not working
> correctly.
>
What problem are you actually trying to solve? Maybe try `args: chdir=/mydir`
V/r,
James Cassell
> would you please let me know how can i do change the current directory in
> the remote host?
>
> Kevin
>
>
>
> =======================================================================================================================
>
> ---
> - name: Testing to change current direcotry
> hosts: Ansible-01
> tasks:
> - name: confirm current Directory in the switch
> become: yes
> become_method: sudo
> command: 'pwd'
> register: exec_result
> - debug: var=exec_result.stdout_lines
>
> - name: Go to "/tmp" Directory in the switch
> become: yes
> become_method: sudo
> command: ' cd /tmp '
>
> - name: confirm current Directory in the switch
> become: yes
> become_method: sudo
> command: 'pwd'
> register: exec_result
> - debug: var=exec_result.stdout_lines
>
>
> ======================================================================================================================
>
> admin@ubuntu-Ansible:~$ ansible-playbook Change-dir.yml
>
> PLAY [Testing to change current direcotry]
> *******************************************************************************************************************
>
> TASK [Gathering Facts]
> ***************************************************************************************************************************************
> ok: [Ansible-01]
>
> TASK [confirm current Directory in the switch]
> ***************************************************************************************************************
> changed: [Ansible-01]
>
> TASK [debug]
> *************************************************************************************************************************************************
> ok: [Ansible-01] => {
> "exec_result.stdout_lines": [
> *"/home/admin"*
> ]
> }
>
> TASK [Go to "/tmp" Directory in the switch]
> ****************************************************************************************************************
> fatal: [Ansible-01]: FAILED! => {"changed": false, "cmd": "cd /tmp",
> "msg":
> "[Errno 2] No such file or directory", "rc": 2}
> to retry, use: --limit @/home/admin/Change-dir.retry
>
> PLAY RECAP
> ***************************************************************************************************************************************************
> Ansible-01 : ok=3 changed=1 unreachable=0 failed=1
>
> admin@ubuntu-Ansible:~$
>
--
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/1557879876.1209629.1669197072.58A7B777%40webmail.messagingengine.com.
For more options, visit https://groups.google.com/d/optout.