# How to we use a different ansible\_connection for delegate host

**URL:** <https://forum.ansible.com/t/how-to-we-use-a-different-ansible-connection-for-delegate-host/2725>\
**Category:** Get Help\
**Tags:** windows, variables, collections, ansible-core\
**Created:** [December 4, 2023, 9:25am UTC](https://forum.ansible.com/t/how-to-we-use-a-different-ansible-connection-for-delegate-host/2725 "2023-12-04T09:25:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ku1918](https://avatars.discourse-cdn.com/v4/letter/k/278dde/32.png) [@ku1918](https://forum.ansible.com/u/ku1918)\
**Post date:** [December 4, 2023, 9:25am UTC](https://forum.ansible.com/t/how-to-we-use-a-different-ansible-connection-for-delegate-host/2725/1 "2023-12-04T09:25:36Z")

</div>

Hi all,

I am running a playbook against an inventory fo Windows Server.

However , there is a specific task I would like to delegate to a specific host but using ssh connection because it is a linux box.

How do I achieve this?

```auto
{
  "ansible_connection": "winrm",
  "ansible_winrm_transport": "ntlm",
  "ansible_port": 5985,
  "ansible_winrm_connection_timeout": 1200
}

```

I have define the above variable in job template.

---

<div class="post-metadata">

**Author:** ![jrglynn2](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jrglynn2](https://forum.ansible.com/u/jrglynn2)\
**Post date:** [December 5, 2023, 3:20pm UTC](https://forum.ansible.com/t/how-to-we-use-a-different-ansible-connection-for-delegate-host/2725/2 "2023-12-05T15:20:32Z")

</div>

I would presume that you could use `delegate_to`, maybe with some variables, but we would need a lot more information in order to help you:

Things like:

- what playbook looks like
- errors from playbook (expected/actual result)
- what you have found in searches and attempted
- etc.

---

<div class="post-metadata">

**Author:** ![ku1918](https://avatars.discourse-cdn.com/v4/letter/k/278dde/32.png) [@ku1918](https://forum.ansible.com/u/ku1918)\
**Post date:** [December 6, 2023, 2:06am UTC](https://forum.ansible.com/t/how-to-we-use-a-different-ansible-connection-for-delegate-host/2725/3 "2023-12-06T02:06:02Z")

</div>

I already try using delegate\_to.

I define a variable “ansible\_connection” under the task , but it still doesn’t work as it will always use winrm connectio that i have define in my job template

---

<div class="post-metadata">

**Author:** ![jrglynn2](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jrglynn2](https://forum.ansible.com/u/jrglynn2)\
**Post date:** [December 6, 2023, 2:28pm UTC](https://forum.ansible.com/t/how-to-we-use-a-different-ansible-connection-for-delegate-host/2725/4 "2023-12-06T14:28:49Z")

</div>

Okay.

Well, as stated, I don’t think anyone can help you without more information.

You need to provide things like:

- playbook
- errors from playbook (expected/actual result)
- what you have found in searches and attempted
- results of running playbook using `-vvv` and/or `-vvvv`
- etc.

Best of luck!

---

<div class="post-metadata">

**Author:** ![ku1918](https://avatars.discourse-cdn.com/v4/letter/k/278dde/32.png) [@ku1918](https://forum.ansible.com/u/ku1918)\
**Post date:** [December 7, 2023, 3:14am UTC](https://forum.ansible.com/t/how-to-we-use-a-different-ansible-connection-for-delegate-host/2725/5 "2023-12-07T03:14:49Z")

</div>

I found the problem.  
It seem like job template variable are overriding my playbook define variable for some reason.

I remove it and it works.

---

<div class="post-metadata">

**Author:** ![jbericat](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jbericat/32/627_2.png) [@jbericat](https://forum.ansible.com/u/jbericat)\
**Post date:** [December 8, 2023, 6:55pm UTC](https://forum.ansible.com/t/how-to-we-use-a-different-ansible-connection-for-delegate-host/2725/6 "2023-12-08T18:55:16Z")

</div>

Hello @ku1918

just be aware that in Ansible there is what we know as **variable precedence**. Check-out the docs for further info (there is an extensive precedence list, that’s most likely what you need to check from all the info on the docs):

[https://docs.ansible.com/ansible/latest/playbook\_guide/playbooks\_variables.html#variable-precedence-where-should-i-put-a-variable](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable)

In your case, since job templates extra vars have precedence over the playbook ones, then the former (extra vars) are overriding the latter (playbook vars).

Hope it helps 🙂
