# Override ControlPersist per host?

**URL:** <https://forum.ansible.com/t/override-controlpersist-per-host/42335>\
**Category:** Get Help\
**Tags:** ssh\
**Created:** [May 1, 2025, 4:44pm UTC](https://forum.ansible.com/t/override-controlpersist-per-host/42335 "2025-05-01T16:44:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![devilkin](https://avatars.discourse-cdn.com/v4/letter/d/ba9def/32.png) [@devilkin](https://forum.ansible.com/u/devilkin)\
**Post date:** [May 1, 2025, 4:44pm UTC](https://forum.ansible.com/t/override-controlpersist-per-host/42335/1 "2025-05-01T16:44:06Z")

</div>

Hi,

I’m currently using sshpiper ([GitHub - tg123/sshpiper: The missing reverse proxy for ssh scp](https://github.com/tg123/sshpiper)) to reverse proxy SSH into different target machines. The reason for this is that I can easily create a user/key combo in sshpiper which will let anyone with the key use SSH straight to the target machine, which are on a private network.

Additionally, the SSH username connecting to sshpiper is different than the one in the target machine.

I want to also use this to allow me to manage certain things of the target machinery. I got it to work using

```auto
targets:
  hosts:
    host1.domain.bla:
      ansible_ssh_extra_args: -l host1
      ansible_port: 2222
      ansible_host: mainmachine.domain.bla
    host2.domain.bla:
      ansible_port: 2222
      ansible_host: mainmachine.domain.bla
      ansible_ssh_extra_args: -l host2
    host3.domain.bla:
      ansible_port: 2222
      ansible_host: mainmachine.domain.bla
      ansible_ssh_extra_args: -l host3

```

Unfortunately, this means that SSH will be using ControlPersist against the main host (mainmachine.domain.bla), without keeping in mind that there might be different sessions being proxied.

I was hoping that I could perhaps play with additional extra\_args to convince it not do do this specifically for these hosts, and not have to disable it for everything, but that doesn’t seem to work.

Is there a way to specify this?

---

<div class="post-metadata">

**Author:** ![wayt](https://avatars.discourse-cdn.com/v4/letter/w/3be4f8/32.png) [@wayt](https://forum.ansible.com/u/wayt)\
**Post date:** [May 1, 2025, 4:48pm UTC](https://forum.ansible.com/t/override-controlpersist-per-host/42335/2 "2025-05-01T16:48:16Z")

</div>

> **[ansible.builtin.ssh connection – connect via SSH client binary — Ansible...](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/ssh_connection.html#parameter-ssh_args)**

You’ll want to override `ansible_ssh_args` on the hosts you care about (or possibly for all in `all:vars`)

---

<div class="post-metadata">

**Author:** ![devilkin](https://avatars.discourse-cdn.com/v4/letter/d/ba9def/32.png) [@devilkin](https://forum.ansible.com/u/devilkin)\
**Post date:** [May 1, 2025, 5:02pm UTC](https://forum.ansible.com/t/override-controlpersist-per-host/42335/3 "2025-05-01T17:02:17Z")

</div>

Someone on Mastodon suggested reconfiguring the `control_path` in `ansible.cfg`.

> **[ansible.builtin.ssh connection – connect via SSH client binary — Ansible...](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/ssh_connection.html#parameter-control_path)**

I changed this to

```auto
[ssh_connection]
control_path = "%(directory)s/%%C"

```

Yet now all sessions fail with

```auto
TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************
[WARNING]: sftp transfer mechanism failed on [mainhost.domain.bla]. Use ANSIBLE_DEBUG=1 to see detailed information
[WARNING]: scp transfer mechanism failed on [mainhost.domain.bla]. Use ANSIBLE_DEBUG=1 to see detailed information

```

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [May 1, 2025, 11:37pm UTC](https://forum.ansible.com/t/override-controlpersist-per-host/42335/4 "2025-05-01T23:37:36Z")

</div>

Control path/dir are connection plugin configurations, you can configure it via any of the ways defined here:

> **[ansible.builtin.ssh connection – connect via SSH client binary — Ansible...](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/ssh_connection.html#parameter-control_path)**
