ansibleansible-awx

Ansible delegate_to from Linux host to Windows host


My playbook runs in Linux and I want to run one particular uri task on a Windows machine. Below is my current task with delegate. It looks like delegate_to is trying to ssh to Windows and it fails.

- name: Send a notification to MS Teams
  uri:
    ## Send a notification to MS Teams Channel
    url: "https://abcd.webhook.office.com/webhookb2/xyz"
    method: POST
    body:
      title: "Test Title"
      text: "Test text"
  delegate_to: windowsVM
  

Solution

  • I managed to sort it.

    When we delegate_to from Linux to Windows, the play assumes all the variables incl connection variables of Linux Host. So in order to connect to Windows, we need to pass Windows connection vars under the delegate_to block.

    - name: Send a notification to MS Teams
      uri:
        ## Send a notification to MS Teams Channel
        url: "https://abcd.webhook.office.com/webhookb2/xyz"
        method: POST
        body:
          title: "Test Title"
          text: "Test text"
      delegate_to: windowsVM
      vars:
          ansible_port: 5986
          ansible_psrp_cert_validation: ignore
          ansible_psrp_ignore_proxy: yes
          ansible_psrp_negotiate_delegate: yes
          ansible_psrp_connection_timeout: 600
          ansible_psrp_read_timeout: 600
          ansible_psrp_reconnection_backoff: 5
          ansible_psrp_reconnection_retries: 7
          ansible_psrp_user: "{{ userame}}"
          ansible_password: "{{ pass}}"