Hey Kai,
First of all thanks for help. here is output:
changed: [localhost] => (item=hurry-up-1) => {
"changed": true,
"cmd": "ssh \"hurry-up-1\"",
"delta": "0:00:00.382495",
"end": "2017-10-19 15:18:03.301177",
"failed": false,
"invocation": {
"module_args": {
"chdir": null,
"command": "ssh \"hurry-up-1\"",
"creates": null,
"echo": false,
"removes": null,
"responses": {
"(?i)root": "tar cvf \"$HOSTNAME\"_`date
+\"%Y-%m-%d_%H.%M.%S\"`.tar test\nexit\n"
},
"timeout": 30
}
},
"item": "hurry-up-1",
"rc": 0,
"start": "2017-10-19 15:18:02.918682"
}
STDOUT:
Last login: Thu Oct 19 14:33:19 2017 from localhost
hurry-up-1 ~]# tar cvf "$HOSTNAME"_`date +"%Y-%m-%d_%H.%M.%S"`.tar
test/
[root@hurry-up-1 ~]# exit
logout
Connection to hurry-up-1 closed.
TASK [setup-sftp-session : crates sftp session to terastation]
******************************************************************************************************************************************************************************
task path: /etc/ansible/roles/setup-sftp-session/tasks/setup-sftp.yml:13
Using module file
/usr/lib/python2.6/site-packages/ansible-2.4.1.0-py2.6.egg/ansible/modules/commands/expect.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<127.0.0.1> EXEC /bin/sh -c 'echo ~ && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo
/root/.ansible/tmp/ansible-tmp-1508440683.35-276654372992574 `" && echo
ansible-tmp-1508440683.35-276654372992574="` echo
/root/.ansible/tmp/ansible-tmp-1508440683.35-276654372992574 `" ) && sleep
0'
<127.0.0.1> PUT /tmp/tmpTC63A9 TO
/root/.ansible/tmp/ansible-tmp-1508440683.35-276654372992574/expect.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x
/root/.ansible/tmp/ansible-tmp-1508440683.35-276654372992574/
/root/.ansible/tmp/ansible-tmp-1508440683.35-276654372992574/expect.py &&
sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python2.6
/root/.ansible/tmp/ansible-tmp-1508440683.35-276654372992574/expect.py; rm
-rf "/root/.ansible/tmp/ansible-tmp-1508440683.35-276654372992574/" >
/dev/null 2>&1 && sleep 0'
changed: [localhost] => {
"changed": true,
"cmd": "ssh 192.168.3.40",
"delta": "0:00:01.737366",
"end": "2017-10-19 15:18:05.204508",
"failed": false,
"invocation": {
"module_args": {
"chdir": null,
"command": "ssh 192.168.3.40",
"creates": null,
"echo": false,
"removes": null,
"responses": {
"(?i)Password": "jghsjd674783",
"(?i)root@": [
"sftp [email protected]",
"mkdir /tmp/backups",
"mv ltt-new*tar /tmp/backups",
"cd /tmp/backups",
"rm -rf $(ls -1t /tmp/backups | tail -n +3)",
"exit",
"exit",
"exit",
"exit",
" exit"
],
"(?i)sftp>": [
"cd a/b/c",
"put ltt-new*tar",
"exit"
]
},
"timeout": 30
}
},
"rc": 0,
"start": "2017-10-19 15:18:03.467142"
}
STDOUT:
Last login: Thu Oct 19 15:18:02 2017 from localhost
[root@hurry-up-1 ~]# sftp [email protected]
Connecting to 192.168.3.43...
mkdir /tmp/backups
Password:
sftp> cd a/b/c
sftp> put ltt-new*tar
Uploading hurry-up-1_2017-10-19_15.18.03.tar to
/mnt/a/b/c/hurry-up-1_2017-10-19_15.18.03.tar
hurry-up-1_2017-10-19_15.18.03.ta 100% 10KB 10.0KB/s 00:00
sftp> exit
[root@hurry-up-1 ~]# mv ltt-new*tar /tmp/backups
[root@hurry-up-1 ~]# cd /tmp/backups
)root@hurry-up-1 backups]# rm -rf $(ls -1t /tmp/backups | tail -n +3
[root@hurry-up-1 backups]# exit
logout
Connection to 192.168.3.40 closed.
On Thursday, October 19, 2017 at 2:58:33 PM UTC-4, Kai Stian Olstad wrote:
>
> On 19. okt. 2017 20:39, Zimidar Boy wrote:
> >
> > On Thursday, October 19, 2017 at 12:44:16 PM UTC-4, Kai Stian Olstad
> wrote:
> >>
> >> On 19. okt. 2017 17:02, Zimidar Boy wrote:
> >>>
> >>> Hello Kai,
> >>> As soon as i used your solution now i am
> getting
> >> this
> >>> error:
> >>>
> >>> "msg": "No remaining responses for '(?i)sftp>', output was ':
> >> \r\nsftp>'"
> >>>
> > Solved the issue but i have to add 5 exit i don't
> know
> > why. Do you think it has to do something with number of commands as i am
> > running 5 commands. new code:
> >
>
> I you previous message it says
> "No remaining responses for '(?i)sftp>'"
>
> So adding exit on the "root@" prompt shouldn't have any effect.
>
>
> > - name: crates sftp session to terastation
> > expect:
> > command: ssh user@host
> >
> >
> > responses:
> > (?i)root@: ['sftp user@host', 'mkdir /tmp/backups', 'mv
> lst*tar
> > /tmp/backups', 'cd /tmp/backups', 'rm -rf $(ls -1t /tmp/backups | tail
> -n
> > +3)', 'exit', 'exit', 'exit', 'exit',' exit']
> >
> > (?i)Password: 213gfdshaa
> > (?i)sftp>: ['cd a/o/h', 'put lst*tar', 'exit']
> >
> To understand what is happening you would need to provide a verbose output
> by running but
>
> ANSIBLE_STDOUT_CALLBACK=debug ansible-playbook -vvv your-playbook.yml
>
>
>
> --
> 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/e8318d89-b8ec-4209-8308-a11f383587e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.