On 19.10.2017 21:28, Zimidar Boy wrote:
"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.
Just a tip, in this task you don't need to use the expect module.
If the host hurry-up-1 is in Ansible inventory you could just use the
archive module.
"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.
From this STDOUT your root@ response only need one exit.
Because after the "exit" you get "logout" and then "Connection to
192.168.3.40 closed"
And for the sftp prompt where you did get the "No remaining responses
for" message it also only need one exit to disconnect.
--
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/7170cc8b17e2c39f9ca28ce40359c9c4%40olstad.com.
For more options, visit https://groups.google.com/d/optout.