multiple commands in one ssh session (systems without python)

552 views
Skip to first unread message

Viktor Tsymbalyuk

unread,
Apr 22, 2015, 1:32:34 PM4/22/15
to ansible...@googlegroups.com
Hi,
There were already few topics related using playbooks on routers and switches (systems without python).
But I didn't find answer on next:
Does it possible with raw module send few command in one ssh session?
Unfortunately below code, create 3 connections
  - name: copy file
    raw
: "{{item}};"
    with_items
:
     
- conf t
     
- int gi0/0
     
- shutdown
To better understanding, I would like to get same behaviour such bash construction
cat file.txt | ssh user@host_name



Brian Coca

unread,
Apr 22, 2015, 1:36:40 PM4/22/15
to ansible...@googlegroups.com
with_ loops normally create a separate task/action per item. You'll
need to construct the the command list using | or > (YAML multiline
operators). Something liek the following:

- name: copy file
raw: |
conf t
int gi0/0
shutdown
--
Brian Coca

Viktor Tsymbalyuk

unread,
Apr 23, 2015, 2:39:03 AM4/23/15
to ansible...@googlegroups.com
Hi, Brian.
As I understood this (literal style | ) is a same replacement for 
raw: "conf t\n int gi0/0\n shutdow"
according yaml.org/spec  it's same
and it works like
ssh username@host "conf t\n int gi0/0\n shutdow"
ssh send "conf t\n int gi0/0\n shutdow" as one command, without \n sequences.
paramiko has same behaviour.
Reply all
Reply to author
Forward
0 new messages