# SSH pseudo terminal zombied after ansible playbook exit

**URL:** <https://forum.ansible.com/t/ssh-pseudo-terminal-zombied-after-ansible-playbook-exit/29145>\
**Category:** Ansible Developer\
**Tags:** ubuntu, kubernetes\
**Created:** [November 28, 2018, 6:14pm UTC](https://forum.ansible.com/t/ssh-pseudo-terminal-zombied-after-ansible-playbook-exit/29145 "2018-11-28T18:14:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Geetanjali\_Gupta](https://avatars.discourse-cdn.com/v4/letter/g/6de8d8/32.png) [@Geetanjali\_Gupta](https://forum.ansible.com/u/Geetanjali_Gupta)\
**Post date:** [November 28, 2018, 6:14pm UTC](https://forum.ansible.com/t/ssh-pseudo-terminal-zombied-after-ansible-playbook-exit/29145/1 "2018-11-28T18:14:12Z")

</div>

I am running ansible-playbook inside docker container on kubernetes. It does copy task and executes a script. Uses private keys. I am invoking it using a java Process. Looks like the ssh pseudo terminals it might be opening stay behind once the playbook is finished executing. Any new playbook invocation adds on to the number of ssh processes. It sort of what [this](https://groups.google.com/forum/#!msg/ansible-project/IQoTNwDBIiA/qiHUTgg31lkJ)thread mentions i think, only that I don’t see -tt option being appended. I tried turning pty false(which is needed for sftp anyways i think) in ansible.cfg as well. Nothing improves. Once ansible-playbook process dies i will see bunch of defunct [ssh] around.  
Here are couple lines from the **“ps” output**

root 1627 1 0 00:00 ? 00:00:00 ssh: /root/.ansible/cp/c360b1d939 [mux]  
root 1629 1 0 00:00 ? 00:00:00 [ssh]   
root 1630 1 0 00:00 ? 00:00:00 ssh: /root/.ansible/cp/e8f6c354e2 [mux]  
root 1632 1 0 00:00 ? 00:00:00 [ssh]   
root 1633 1 0 00:00 ? 00:00:00 ssh: /root/.ansible/cp/edb897f2b6 [mux]  
root 1643 1641 0 00:00 ? 00:00:00 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o IdentityFile=“/opt/ansible/id\_rsa” -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User= -o ConnectTimeout=5 -o ControlPath=/root/.ansible/cp/b1739bcf8c /bin/sh -c ‘/usr/bin/python && sleep 0’  
root 1645 1644 0 00:00 ? 00:00:00 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o IdentityFile=“/opt/ansible/id\_rsa” -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User= -o ConnectTimeout=5 -o ControlPath=/root/.ansible/cp/d54b353787 /bin/sh -c ‘/usr/bin/python && sleep 0’

**Top output**

1 root 20 0 14.980g 1.487g 15156 S 1.3 0.9 4:17.71 java  
9377 root 20 0 38376 3440 1248 R 1.0 0.0 0:00.20 top  
449 root 20 0 0 0 0 Z 0.0 0.0 0:00.00 ssh  
450 root 20 0 0 0 0 Z 0.0 0.0 0:00.04 ssh  
453 root 20 0 0 0 0 Z 0.0 0.0 0:00.00 ssh  
454 root 20 0 0 0 0 Z 0.0 0.0 0:00.04 ssh  
456 root 20 0 0 0 0 Z 0.0 0.0 0:00.00 ssh

**Code to invoke playbook:**

String cmdPurge = { “ansible-playbook”, config.getPurgePlaybookPath(), “-i”, config.getInventoryLoc(),  
“–extra-vars”,  
“{"urls\_file":” + config.getUrlPath() + “,"type":"” + config.getType() + “","purge\_file":"” + config.getPurgeFile() + “"}” ,“–private-key”,config.getPrivateKeyFile()};  
Process pPurge = Runtime.getRuntime().exec(cmdPurge, null);  
BufferedReader in = new BufferedReader(new InputStreamReader(pPurge.getInputStream()));  
while ((line = in.readLine()) != null) {  
//process the console output  
}  
in.close();  
int exitcode = pPurge.waitFor();

**Ansible.cfg**

inventory = hosts  
remote\_user =   
host\_key\_checking = False  
timeout = 5  
pty=False  
pipelining = True

**Base Image:** Ubuntu:Xenial

**Ansible version** : ansible 2.7.2

using JDK8

I faced same issues using Alpine jdk image and then I switched to ubuntu.

---

<div class="post-metadata">

**Author:** ![Geetanjali\_Gupta](https://avatars.discourse-cdn.com/v4/letter/g/6de8d8/32.png) [@Geetanjali\_Gupta](https://forum.ansible.com/u/Geetanjali_Gupta)\
**Post date:** [November 28, 2018, 6:21pm UTC](https://forum.ansible.com/t/ssh-pseudo-terminal-zombied-after-ansible-playbook-exit/29145/2 "2018-11-28T18:21:23Z")

</div>

Adding the playbook code

```auto
- name: "copying URL file"
  copy: src="{{urls_file}}" dest="~/{{urls_file}}"

- name: "copying purge script"
  copy: src="{{purge_file}}" dest="~/{{purge_file}}" mode=0777

- name: "execute purge script"
  shell: ./"{{purge_file}}" "{{urls_file}}"
  register: machine

- debug: msg="{{machine.stdout_lines}}"

- name: "Clean up copied file"
  file:
    path: "{{item}}"
    state: absent
  with_items:
    - "{{urls_file}}"
    - "{{purge_file}}"

```
