0

So the role is executing on a Windows host but the localhost in an AWX server (linux server) but when I try to execute this task:

- name: execute localhost
  command: echo "Hello, localhost!"
  delegate_to: localhost
  connection: local

My inventory looks like this:

[MyAPP]
Server1

[Windows:children]
MyApp

[WINDOWS:vars]
ansible_user=#{winrm_ansible_user}#
ansible_password=#{winrm_ansible_password}#
ansible_port=5985
ansible_connection=winrm
ansible_winrm_transport=basic

A main.yml calling a role

- hosts: all
  become: false
  roles:
    - role: pool_recycle

Example of role:

- name: Get win local IP
  ansible.windows.win_powershell:
    script: |
      (Test-Connection -ComputerName $env:ComputerName  -Count 1).IPV4Address.ToString()
  register: get_ip

- name: execute localhost
  command: echo "Hello, localhost!"
  delegate_to: localhost
  connection: local

So it will start the ansible playbook with the Server1 (windows) then I have to use the localhost to execute a specific task (where the localhost = awx server = linux machine)

But it won't execute in SSH but AWX tries to execute it as a Windows machine with WInRM:

fatal: [WINDOWS_SERVER_01 -> localhost]: UNREACHABLE! => {"changed": false, "msg": "basic: HTTPConnectionPool(host='localhost', port=5985): Max retries exceeded with url: /wsman (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fdb9e8acac0>: Failed to establish a new connection: [Errno 111] Connection refused'))", "unreachable": true}

Any help/idea please? How can I force it to use a ssh?

Raphyyy
  • 29
  • 4
  • have you set the `ansible_port` value to 5985 at the playbook level rather than at the host or group level. It looks like its set generally so is applied to all hosts including localhost. – Chris Doyle Jun 09 '23 at 10:36
  • Obviously it seems that your whole play is running a WinRM connection type and therefore the connection attempt back from a Windows Remote Node to the Linux Control Node fails as it would require SSH instead of the not available WinRM. What would be the use case for such attempt? Can you provide much much more information, details and description what you try to achieve here? – U880D Jun 09 '23 at 12:10
  • Wild guess: you have explicitly declared `localhost` in your inventory (rather than relying on the [implicit `localhost`](https://docs.ansible.com/ansible/latest/inventory/implicit_localhost.html#implicit-localhost)) and affected it to a group where you configured winrm as the connection plugin. Anyhow, please read [ask] and make the above a [mre] – Zeitounator Jun 09 '23 at 12:53
  • Probably from my inventory? I am using windows:var for windows machine where I am using ansible_port=5985 and ansible_connection=winrm What I am trying to do is : Get the ip from the windows machine then I need to execute a f5networks modules on the local machine (which has enough right to access to the f5 networks server) to stop/start the pools – @Zeitounator sorry, I have edited the initial post to make it reproducible – Raphyyy Jun 09 '23 at 14:17
  • And I did not declare localhost in my inventory :/ – Raphyyy Jun 09 '23 at 15:00
  • Since you are looking up the environment (`env`)on the Windows Remote Node, you may have a look into [How to lookup `env` when Managed Node is a Windows host?](https://stackoverflow.com/a/76325914/6771046). By gathering facts you'll also be able to get the IP addresses. Can you explain in more detail what would be the Use Case for your connection attempt back from a Windows Managed Node back to the Linux Control Node? – U880D Jun 09 '23 at 15:49
  • Yeah I need to deploy/update some application on windows server that use iis but before deploying/updating application, I need to set the pool (farmmanager) to offline mode from the machine's IP address. – Raphyyy Jun 09 '23 at 16:01
  • That doesn't explain anything for me, maybe someone else can get something out from it. Also it doesn't answer my questions, at least not for me. Nevertheless, you might take advantage from [Local playbooks](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_delegation.html#local-playbooks), "_Alternatively, a local connection can be used in a single playbook play, even if other plays in the playbook use the default remote connection type: ..._" – U880D Jun 09 '23 at 16:11

0 Answers0