The error message really looks like you don't have "/opt/backup_test" on 
your local system or possibly not writable by the account Ansible is using.

If you have Ansible 2.3 and you're just building a tar file, why not use 
the "archive" module?
    http://docs.ansible.com/ansible/latest/archive_module.html

 - name: make backup using archive module
   archive:
     dest:"{{ansible_hostname}}_{{ansible_facts.date}}.tar.gz"
     path: /opt/backup_test
     format: gz

DanL

On Thursday, October 12, 2017 at 9:26:45 AM UTC-5, Zimidar Boy wrote:
>
> Thanks for help i have another question so as i am running script as 
> localhost it is making backup on local host even though in ssh into another 
> node i tried by combining backup and ssh process together but it didn't 
> worked error says no such file directory.
>
>   - name: make backup
>      shell: |
>          ssh user@hostname
>          tar cvf "$HOSTNAME"_`date +"%Y-%m-%d"`.tar /opt/backup_test
>
> error:
>
>  TASK [make backup] 
> **************************************************************************************************************************************************************************************************************************
> fatal: [localhost]: FAILED! => {"changed": true, "cmd": "ssh user@hostname 
> \n tar cvf \"$HOSTNAME\"_`date +\"%Y-%m-%d\"`.tar /opt/backup_test", 
> "delta": "0:00:00.077642", "end": "2017-10-12 02:07:50.314514", "failed": 
> true, "msg": "non-zero return code", "rc": 2, "start": "2017-10-12 
> 02:07:50.236872", "stderr": "Pseudo-terminal will not be allocated because 
> stdin is not a terminal.\r\ntar: Removing leading `/' from member 
> names\ntar: /opt/backup_test: Cannot stat: No such file or directory\ntar: 
> Exiting with failure status due to previous errors", "stderr_lines": 
> ["Pseudo-terminal will not be allocated because stdin is not a terminal.", 
> "tar: Removing leading `/' from member names", "tar: /opt/backup_test: 
> Cannot stat: No such file or directory", "tar: Exiting with failure status 
> due to previous errors"], "stdout": "", "stdout_lines": []}
>
> PLAY RECAP 
> **********************************************************************************************************************************************************************************************************************************
> localhost                  : ok=1    changed=0    unreachable=0    failed=1
>
>
>
>
>
>
>
> On Thursday, October 12, 2017 at 9:42:06 AM UTC-4, Kai Stian Olstad wrote:
>>
>> On 12.10.2017 15:29, Zimidar Boy wrote: 
>> > 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"]} 
>>
>> It do login but just run and exit afterward, and exit is the last of you 
>> responses. 
>>
>>
>> > 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. 
>>
>> I think you only can have one unique question with the responses in a 
>> list like this. 
>>
>>    - name: Creates Sftp session to send files to terastation. 
>>      expect: 
>>        command: sftp user@hostname 
>>        responses: 
>>          (?i)Password: "1rfr2345" 
>>          (?i)sftp>: 
>>            - "cd abc/def/" 
>>            - "put "$HOSTNAME"_`date +"%Y-%m-%d"`.tar  " 
>>            - "exit" 
>>
>> -- 
>> Kai Stian Olstad 
>>
>

-- 
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/9b0ebe6f-f1d6-4728-82b8-cde9cc9c0b49%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to