# multiple commands in one ssh session (systems without python)

**URL:** <https://forum.ansible.com/t/multiple-commands-in-one-ssh-session-systems-without-python/18055>\
**Category:** Ansible Project\
**Created:** [April 22, 2015, 5:32pm UTC](https://forum.ansible.com/t/multiple-commands-in-one-ssh-session-systems-without-python/18055 "2015-04-22T17:32:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Viktor\_Tsymbalyuk](https://avatars.discourse-cdn.com/v4/letter/v/76d3ee/32.png) [@Viktor\_Tsymbalyuk](https://forum.ansible.com/u/Viktor_Tsymbalyuk)\
**Post date:** [April 22, 2015, 5:32pm UTC](https://forum.ansible.com/t/multiple-commands-in-one-ssh-session-systems-without-python/18055/1 "2015-04-22T17:32:34Z")

</div>

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

`

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [April 22, 2015, 5:36pm UTC](https://forum.ansible.com/t/multiple-commands-in-one-ssh-session-systems-without-python/18055/2 "2015-04-22T17:36:37Z")

</div>

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:

&nbsp;&nbsp;- name: copy file  
&nbsp;&nbsp;&nbsp;&nbsp;raw: |  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conf t  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int gi0/0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;shutdown

---

<div class="post-metadata">

**Author:** ![Viktor\_Tsymbalyuk](https://avatars.discourse-cdn.com/v4/letter/v/76d3ee/32.png) [@Viktor\_Tsymbalyuk](https://forum.ansible.com/u/Viktor_Tsymbalyuk)\
**Post date:** [April 23, 2015, 6:39am UTC](https://forum.ansible.com/t/multiple-commands-in-one-ssh-session-systems-without-python/18055/3 "2015-04-23T06:39:02Z")

</div>

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](http://www.yaml.org/spec/1.2/spec.html#id2795688) 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.`
