Hi guys,
I am working on project to in which I am trying to backup some files from one server and than transfer that files to NAS terastation. So from my ansible box i do ssh into node. Then i make backup of some files at same node and create sftp session to transfer files to NAS and i am putting current day date and host name as name of files. The problem is that this (sftp ) command prompts me to enter password and to enter password i am trying to build a script which automatically enters password and continue the process. Even i have no error when i ran my playbook but i don’t get my files at tera station. But when i ran my playbook with level 1 verbose like -v it shows something like this but in yellow colour so not like error:
TASK [Creates Sftp session to send files to terastation.] ****************************************************************************************************************************************************************************************************************************
changed: [localhost] => {“changed”: true, “cmd”: “sftp user@hostname”, “delta”: “0:00:01.136744”, “end”: “2017-10-11 05:14:25.224441”, “failed”: false, “rc”: 0, “start”: “2017-10-11 05:14:24.087697”, “stdout”: “Connecting to terastation…\r\nPassword: \r\nsftp> exit”, “stdout_lines”: [“Connecting to terastation…”, "Password: ", “sftp> exit”]}
Here is sample of my script:
-
hosts: localhost
sudo: true
tasks: -
name: Log into node
shell: ssh user@hostname -
name: make backup of files
shell: tar cvf “$HOSTNAME”_date +"%Y-%m-%d"
.tar /etc/ansible/playbooks -
name: Creates Sftp session to send files to terastation.
expect:
command: sftp user@hostname
responses:
(?i)Password: “1rfr2345”
(?i)sftp>: “cd abc/def/”
(?i)sftp>: "put “$HOSTNAME”_date +"%Y-%m-%d"
.tar "
(?i)sftp>: “exit”
If more info needed pls let me know. Thanks in advance.