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?