# How to change remote hosts' terminal screen size/resolution in Ansible

**URL:** <https://forum.ansible.com/t/how-to-change-remote-hosts-terminal-screen-size-resolution-in-ansible/32724>\
**Category:** Ansible Project\
**Created:** [April 18, 2020, 9:15am UTC](https://forum.ansible.com/t/how-to-change-remote-hosts-terminal-screen-size-resolution-in-ansible/32724 "2020-04-18T09:15:18Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samir\_Kothawade](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@Samir\_Kothawade](https://forum.ansible.com/u/Samir_Kothawade)\
**Post date:** [April 18, 2020, 9:15am UTC](https://forum.ansible.com/t/how-to-change-remote-hosts-terminal-screen-size-resolution-in-ansible/32724/1 "2020-04-18T09:15:18Z")

</div>

Hi,

**Here is the brief about scenario:**

1. login to Debian host machine using ansible
2. Go to corresponding directory where the binary is and execute that binary. (This binary is written in c and C++. After execution it ask for the userid & password)
3. After login into that binary’s shell, it has several commands which displays statistics. Those stats are lengthy and does not fit in current screen resolution. For seen seeing all the stats we have to press Down arrow Key or Enter key multiple time until we reach to last stat line.

**How I am doing this:**

_-_ _hosts: sam_  
_gather\_facts: no_  
_tasks:_  
_- name: capture all stats_  
_ignore\_errors: yes_  
_expect:_  
_command: /opt/abc/xyz\_Platform/bin/go\_xyz\_cli_  
_responses:_  
_(.)Username:(.): “admin”_  
_(.)Password:(.): “admin”_  
_(.)xyz\_cli\>(.): display all debug stats_  
_**(.):(.): ‘’**_  
_register: stats_  
_- local\_action: copy content=“{{ stats.stdout}}” dest=“/home/sam/quickstats/stats.txt”_  
_ignore\_errors: yes_

**Issues Facing :**

1. Multiple similar line gets copied in stats.txt file when above reaches to ==\>\> _**(.):(.): ‘’**_ (See above code section marked in blue). Using this method to press key.
2. Actual stats counts are of line 500 hundred but above code returns 2k + stats with repetitive stats and some garbage values appended.
3. If i removes this portion _**(.):(.): ‘’**_ from code, then above script only copies 20-30 lines which currently are displayed on screen or which displayed in current screen size.

I guess I can achieve this by changing remote servers’ screen size. but I could not able to get any such way in ansible.

May I request you to help me in this ?

---

<div class="post-metadata">

**Author:** ![Samir\_Kothawade](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@Samir\_Kothawade](https://forum.ansible.com/u/Samir_Kothawade)\
**Post date:** [April 18, 2020, 9:50am UTC](https://forum.ansible.com/t/how-to-change-remote-hosts-terminal-screen-size-resolution-in-ansible/32724/2 "2020-04-18T09:50:34Z")

</div>

Also, There is a limitation on remote host - It does not have xrandr module. So, changing screen size with xrandr will not be available ☹

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [April 18, 2020, 10:02am UTC](https://forum.ansible.com/t/how-to-change-remote-hosts-terminal-screen-size-resolution-in-ansible/32724/3 "2020-04-18T10:02:44Z")

</div>

> Also, There is a limitation on remote host - It does not have xrandr module. So, changing screen size with xrandr will  
> not be available ☹

You need to configure the size of the remote terminal, so xrandr won't be the correct tool. So you can try  
to manipulate the terminal with shell commands (resize, stty).

But I wonder why you can't tell this binary to write output in a file.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [April 18, 2020, 10:15am UTC](https://forum.ansible.com/t/how-to-change-remote-hosts-terminal-screen-size-resolution-in-ansible/32724/4 "2020-04-18T10:15:37Z")

</div>

How exactly are the stats output on the host?

If the programs that produce them send them to standard output, then one option would be to run the commands and redirect their outputs to a file. When all the programs have been run, copy that file to wherever you need it. Remember to append for all but the first command.

Also, I don’t understand what you mean about _**(.):(.): ‘’**_

A better mechanism (IMHO) would be to write a shell script that generates all the stats in the order you want them, and either have that script write to a file or redirect its output to a file. Then just grab that file. If the stats are to be obtained from multiple machines you could copy the script to each with Ansible and then execute it. If it’s just one host, you could leave the script on that host. It depends on where would be the most appropriate place to maintain the script.

Regards, K.

---

<div class="post-metadata">

**Author:** ![Samir\_Kothawade](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@Samir\_Kothawade](https://forum.ansible.com/u/Samir_Kothawade)\
**Post date:** [April 18, 2020, 1:38pm UTC](https://forum.ansible.com/t/how-to-change-remote-hosts-terminal-screen-size-resolution-in-ansible/32724/5 "2020-04-18T13:38:32Z")

</div>

> How exactly are the stats output on the host?

**Actual Output received in stats.txt file though method which is I am using.**

“OPR\>display debug info PP ip 192.168.30.26 port 8686 data”,  
“\u001b[H\u001b[JSending command to get debug data from {192.168.30.26:8686} PP”,  
“”,  
" Current counters in PP:",  
“”,  
“Data Counters Summary:”,  
“\u001b[5GTotal Pkt Received\u001b[6;49H{ 10202784 PPS }”,  
“\u001b[7G3G pkt Rvcd\u001b[7;49H{ 5101392 PPS }”,  
“\u001b[7G4G pkt Rvcd\u001b[8;49H{ 0 PPS }”,  
“\u001b[7Gunknown rat type pkt Rvcd\u001b[9;49H{ 5101392 PPS }”,  
“\u001b[5GArp-Rsp Pkt Drop\u001b[10;49H{ 0 PPS }”,  
“\u001b[5GArp-Req Pkt process\u001b[11;49H{ 549683392 PPS }”,  
“\u001b[5GICMP-Req Pkt process\u001b[12;49H{ 32765 PPS }”,  
“”,

**Note: there are 2K lines below (as I described in my initial comment)**

**Expected results – or output displayed when we hit the command manually.**

```auto
 Current counters in PP:

Data Counters Summary:
    Total Pkt Received { 10202784 PPS }
      3G pkt Rvcd { 5101392 PPS }
      4G pkt Rvcd { 0 PPS }
      unknown rat type pkt Rvcd { 5101392 PPS }
    Arp-Rsp Pkt Drop { 0 PPS }
    Arp-Req Pkt process { 3508911440 PPS }
    ICMP-Req Pkt process { 32765 PPS }

  Pkt BB PP License Expired { 0 PPS }
 

```

Pkt BB Configuration not recieved { 5101392 PPS }

**Note : There are 500 lines below…not adding all here.**

---

<div class="post-metadata">

**Author:** ![Samir\_Kothawade](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@Samir\_Kothawade](https://forum.ansible.com/u/Samir_Kothawade)\
**Post date:** [April 18, 2020, 1:42pm UTC](https://forum.ansible.com/t/how-to-change-remote-hosts-terminal-screen-size-resolution-in-ansible/32724/6 "2020-04-18T13:42:16Z")

</div>

As shown, there is some garbage data coming that file, we can remove that using regex. My initial objective it to capture all 500 stats lines in variable - stats

---

<div class="post-metadata">

**Author:** ![Samir\_Kothawade](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@Samir\_Kothawade](https://forum.ansible.com/u/Samir_Kothawade)\
**Post date:** [April 18, 2020, 1:46pm UTC](https://forum.ansible.com/t/how-to-change-remote-hosts-terminal-screen-size-resolution-in-ansible/32724/7 "2020-04-18T13:46:56Z")

</div>

H[i, I tried with stty but that could not help. output remained the same.

Here is how i used that :

- hosts: opr  
gather\_facts: no  
tasks:
- name: set the winsize  
shell: stty cols 500 rows 500
- name: Get the debug status  
ignore\_errors: yes

…and kept rest script same.

---

<div class="post-metadata">

**Author:** ![Samir\_Kothawade](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@Samir\_Kothawade](https://forum.ansible.com/u/Samir_Kothawade)\
**Post date:** [April 18, 2020, 3:04pm UTC](https://forum.ansible.com/t/how-to-change-remote-hosts-terminal-screen-size-resolution-in-ansible/32724/8 "2020-04-18T15:04:35Z")

</div>

> > Could you please explain how can use xterm command : xterm --tn dumb -cm -dc -e this is your command  
> > Fustratigly, xterm is not present in remote machine and I am not allowed to install xterm utility on targeted remote machine. Still, is there any way to run it through ansible conroller?

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [April 18, 2020, 3:57pm UTC](https://forum.ansible.com/t/how-to-change-remote-hosts-terminal-screen-size-resolution-in-ansible/32724/9 "2020-04-18T15:57:25Z")

</div>

What shell are you using on the remote machine? And what kind of terminal is it running in? I have a suspicion that it is just running on a pty, and that your program is blindly putting out control sequences. If it is, then there’s nothing you can do about it except strip them using regexp or similar.

Is there any way to redirect the output from your program into a file? That bypasses the terminal stuff completely , though as I said, if your program is blindly colourising its output OR blindly waiting after every 24 lines, there’s nothing much you can do about it. The duplicate output is strange - can you provide a sample? It may be the program trying to output bold text or something.

Right about now I would be contacting the people responsible for a) the Debian host and b) this program you are trying to run to see if there is some way to solve this problem neatly.

Were you able to find out about possible additional command line controls on the program? Anything Ansible can do, you can do too, so try manually logging in and seeing what you can find out.

Regards, K.

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [April 18, 2020, 4:23pm UTC](https://forum.ansible.com/t/how-to-change-remote-hosts-terminal-screen-size-resolution-in-ansible/32724/10 "2020-04-18T16:23:14Z")

</div>

You _might_ be able to convince the console on the remote system to be a dumb terminal by doing this as your command:

TERM-dumb ; sh -c your\_command

This works in gnome-terminal as well - it seems to suppress most control sequences except CR/LF and similar.

Or in Ansible, setting the environment variable TERM to “dumb” then running your command in a new shell. In my experiments here, when I set TERM=dumb and ran sh from within a console or from within gnome-terminal, the colourisation went away. However the console still had a fixed number of lines.

Regards, K.

---

<div class="post-metadata">

**Author:** ![Samir\_Kothawade](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@Samir\_Kothawade](https://forum.ansible.com/u/Samir_Kothawade)\
**Post date:** [April 18, 2020, 4:34pm UTC](https://forum.ansible.com/t/how-to-change-remote-hosts-terminal-screen-size-resolution-in-ansible/32724/11 "2020-04-18T16:34:00Z")

</div>

bash: TERM-dumb: command not found.

gnome-terminal utility not available on remote machine

---

<div class="post-metadata">

**Author:** ![Samir\_Kothawade](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@Samir\_Kothawade](https://forum.ansible.com/u/Samir_Kothawade)\
**Post date:** [April 18, 2020, 4:40pm UTC](https://forum.ansible.com/t/how-to-change-remote-hosts-terminal-screen-size-resolution-in-ansible/32724/12 "2020-04-18T16:40:13Z")

</div>

Duplicate entries when I provide _**(.):(.): ‘’**_ _ **But this method atleast return complete data.** _  
When I comment-out _**(.):(.): ‘’ it shows 23 lines displayed on screen + garbage data + no duplicate lines/stats**_

 ![image.png](https://us1.discourse-cdn.com/ansible/original/2X/3/375795ca68b91d9216c969a53b2a9978fb557ef8.png)

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [April 18, 2020, 11:54pm UTC](https://forum.ansible.com/t/how-to-change-remote-hosts-terminal-screen-size-resolution-in-ansible/32724/13 "2020-04-18T23:54:23Z")

</div>

TERM=dumb

Sorry, I mistyped. The minus sign should have been an equals sign.

The idea is to set the environment variable TERM to the value “dumb” immediately before starting the shell in which your program will be run.

Also can you please answer the question about whether you can redirect the output of this program?

I strongly suggest you experiment manually rather than with Ansible. You need to find out how to achieve what you want, then duplicate that in Ansible. Doing both at once is very painful.

Regards, K.

---

<div class="post-metadata">

**Author:** ![Samir\_Kothawade](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@Samir\_Kothawade](https://forum.ansible.com/u/Samir_Kothawade)\
**Post date:** [April 19, 2020, 6:25am UTC](https://forum.ansible.com/t/how-to-change-remote-hosts-terminal-screen-size-resolution-in-ansible/32724/14 "2020-04-19T06:25:53Z")

</div>

> TERM=dumb

> Sorry, I mistyped. The minus sign should have been an equals sign.

> > > > Can you please help me where I can use this in my code and see the content in a text file ? Here is my anible code…pasting it here again  
> > > > _-_ _hosts: sam_  
> > > > _gather\_facts: no_  
> > > > _tasks:_  
> > > > _- name: capture all stats_  
> > > > _ignore\_errors: yes_  
> > > > _expect:_  
> > > > _command: /opt/abc/xyz\_Platform/bin/go\_xyz\_cli_  
> > > > _responses:_  
> > > > _(.)Username:(.): “admin”_  
> > > > _(.)Password:(.): “admin”_  
> > > > _(.)xyz\_cli\>(.): display all debug stats_  
> > > > _**(.):(.): ‘’**_  
> > > > _register: stats_  
> > > > _- local\_action: copy content=“{{ stats.stdout}}” dest=“/home/sam/quickstats/stats.txt”_  
> > > > _ignore\_errors: yes_

> The idea is to set the environment variable TERM to the value “dumb” immediately before starting the shell in which your program will be run.
> 
> Also can you please answer the question about whether you can redirect the output of this program?

> > NO. There no support on that binary to copy or to point the output to some file. Shell commads like " \>\>abc.txt " does not work.

> I strongly suggest you experiment manually rather than with Ansible. You need to find out how to achieve what you want, then duplicate that in Ansible. Doing both at once is very painful.

> > Yes. I have done this manually.  
> > **For collecting stats manually here is the procedure :**

1. I use mouse \> Select the area of stats appeared on screen (after selecting area, termius utility copy the selected area automatically) \>
2. Paste it manually by pressing ctr+v into sublime text editor
3. Again go to remote machine and press down key/Enter key to collect remaining stats and copy-paste the status in similarly way as mentioed in step 1 and 2.
4. I have to perform step 1,2,3 multiple times untill I copy all the status, as window can display only 25-30 lines/rows. Some times for doing it quickly, I use zoom-out (Ctr++), by this I can copy more lines.  
But I want to do this operation through automation.

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [April 19, 2020, 6:39am UTC](https://forum.ansible.com/t/how-to-change-remote-hosts-terminal-screen-size-resolution-in-ansible/32724/15 "2020-04-19T06:39:09Z")

</div>

> 

Hello Samir,

this is now really off topic. Try to figure out to wrangle the data out of this rather unhelpful binary  
by means of "expect" or similar software, but your problem is not related to Ansible.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [April 19, 2020, 7:00am UTC](https://forum.ansible.com/t/how-to-change-remote-hosts-terminal-screen-size-resolution-in-ansible/32724/16 "2020-04-19T07:00:44Z")

</div>

I’ve offered all the help I can. Your best bet is to contact the people who wrote the program you are trying to use.

You may find it easier to do things like set environment variables and redirect output using the shell module:

[https://docs.ansible.com/ansible/latest/modules/shell\_module.html#shell-module](https://docs.ansible.com/ansible/latest/modules/shell_module.html#shell-module)

Also, it would be a VERY good idea to test things out manually before trying to do them in Ansible.

Good luck, K.
