Hi.. All
Thank you so much your help!
After changed the my playbook like below, working directory is changed.
Kevin
* - name: Go to /cftmp Directory and check the Direcotry in the switch*
* become: yes*
* become_method: sudo*
* command: 'pwd'*
* args:*
* chdir: /cftmp*
* register: exec_result*
* - debug: var=exec_result.stdout_lines*
2019년 5월 15일 수요일 오전 9시 20분 2초 UTC+9, Kevin Kwon 님의 말:
>
>
>
> 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.
>
> 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/e0a45609-7e92-49c8-a531-2523952f64a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.