How to we use a different ansible_connection for delegate host

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?

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

I have define the above variable in job template.

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.
1 Like

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

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!

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.

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

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 :slight_smile:

1 Like