Answers: <p>Looking at your code it seems you try to connect to a Windows host. Usually you connect windows via <code>WinRM</code> and not via ssh</p>
  
  <p>The user guide for this can be found here: <a href="https://docs.ansible.com/ansible/latest/user_guide/windows_winrm.html" rel="nofollow noreferrer">https://docs.ansible.com/ansible/latest/user_guide/windows_winrm.html</a></p>
  
  <blockquote>
    <p>For Ansible to communicate to a Windows host and use Windows modules, the Windows host must meet the following requirements:</p>
    
    <ul>
    <li>Ansible’s supported Windows versions generally match those under current and extended support from Microsoft. Supported desktop OSs include Windows 7, 8.1, and 10, and supported server OSs are Windows Server 2008, 2008 R2, 2012, 2012 R2, 2016, and 2019.</li>
    <li>Ansible requires PowerShell 3.0 or newer and at least .NET 4.0 to be installed on the Windows host.</li>
    <li>A WinRM listener should be created and activated. More details for this can be found below.</li>
    </ul>
  </blockquote>
  
  <p>Then you need to tell ansible to connect wia <code>winrm</code></p>
  
  <pre><code>...
  ansible_connection=winrm
  ...
  </code></pre>
  
  <p>Checkout the details here: <a href="https://www.ansible.com/blog/connecting-to-a-windows-host" rel="nofollow noreferrer">https://www.ansible.com/blog/connecting-to-a-windows-host</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2019-09-26T11:23:25.740Z
Answers: Yes your correct, in group_vars i mentioned  ansible_connection=winrm , but i don't no why it is trying to connect via ssh
Answers: G.vigneshwari
Answers: CC BY-SA 4.0
Answers: 2019-09-26T09:00:56.413Z
Answers: 2019-09-26T09:00:56.413Z
Answers: papanito
Body: <p><strong>Playbook.yml</strong></p>
  
  <pre><code>---
  - name: connectionTest
    hosts: Windows
    tasks:
    - name: "Windows Connect"
      win_command: hostname
      register: wincmd_out
  </code></pre>
  
  <p>Variable declared in Inventories <code>Project/inventories/XXX_Local/</code></p>
  
  <pre><code>[Windows]
  XXVMxxxxxxx
  </code></pre>
  
  <p>Error Message:</p>
  
  <pre><code>fatal: [XXVMxxxxxxx]: UNREACHABLE! =&gt; {
      "changed": false, 
      "msg": "Failed to connect to the host via ssh: OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 58: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug1: Control socket \"/tmp/awx_1636443_S7HHdB/cp/6b18046463\" does not exist\r\ndebug2: resolving \"XXVMxxxxxxx\" port 22\r\nssh: Could not resolve hostname XXVMxxxxxxx: Name or service not known", 
      "unreachable": true
  }
  </code></pre>
  
Tags: <ansible><windows>
Title: Unable to run the playbook in remote machine using Ansible job template. Connection Failed
UserDisplayName: G.vigneshwari
ThreadText: # Unable to run the playbook in remote machine using Ansible job template. Connection Failed
  
  (Asked by: username_0 on 2019-09-26)
  
  **Playbook.yml**
  
  ```
  ---
  - name: connectionTest
    hosts: Windows
    tasks:
    - name: "Windows Connect"
      win_command: hostname
      register: wincmd_out
  
  ```
  
  Variable declared in Inventories `Project/inventories/XXX_Local/`
  
  ```
  [Windows]
  XXVMxxxxxxx
  
  ```
  
  Error Message:
  
  ```
  fatal: [XXVMxxxxxxx]: UNREACHABLE! => {
      "changed": false, 
      "msg": "Failed to connect to the host via ssh: OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 58: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug1: Control socket \"/tmp/awx_1636443_S7HHdB/cp/6b18046463\" does not exist\r\ndebug2: resolving \"XXVMxxxxxxx\" port 22\r\nssh: Could not resolve hostname XXVMxxxxxxx: Name or service not known", 
      "unreachable": true
  }
  
  ```
  
  **Tags:** ansible, windows
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-09-26. Score: 1 | Accepted answer
  
  Looking at your code it seems you try to connect to a Windows host. Usually you connect windows via `WinRM` and not via ssh
  
  The user guide for this can be found here: <https://docs.ansible.com/ansible/latest/user_guide/windows_winrm.html>
  
  > For Ansible to communicate to a Windows host and use Windows modules, the Windows host must meet the following requirements:
  >
  > * Ansible’s supported Windows versions generally match those under current and extended support from Microsoft. Supported desktop OSs include Windows 7, 8.1, and 10, and supported server OSs are Windows Server 2008, 2008 R2, 2012, 2012 R2, 2016, and 2019.
  > * Ansible requires PowerShell 3.0 or newer and at least .NET 4.0 to be installed on the Windows host.
  > * A WinRM listener should be created and activated. More details for this can be found below.
  
  Then you need to tell ansible to connect wia `winrm`
  
  ```
  ...
  ansible_connection=winrm
  ...
  
  ```
  
  Checkout the details here: <https://www.ansible.com/blog/connecting-to-a-windows-host>
  
  > **Comments:**
  > **username_0**: Yes your correct, in group_vars i mentioned  ansible_connection=winrm , but i don't no why it is trying to connect via ssh  
  
  ---
  
  