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:~$