Improve os detection

This commit is contained in:
Gašper Fele-Žorž 2025-08-13 23:54:56 +02:00
parent 9a2e67b2e1
commit 675378ba8a

View file

@ -1,31 +1,21 @@
- name: Try connecting to linux
ping:
register: lin_ping_data
ignore_unreachable: true
ignore_errors: true
- name: Send valid bash or ps command with different results
raw: |
echo \#\#
register: raw_result
- name: Set shell to powershell
- name: Set shell type
set_fact:
ansible_shell_type: powershell
when: lin_ping_data is undefined or lin_ping_data.unreachable is defined
- name: Try connecting to windows
win_ping:
register: win_ping_data
ignore_unreachable: true
ignore_errors: true
ansible_shell_type: "{% if raw_result['stdout'][-4] == '#' %}sh{% else %}powershell{%endif%}"
- name: Set connection parameters and paths for Windows
become: false
set_fact:
ansible_shell_type: powershell
ansible_connection: ssh
ansible_become_method: runas
ansible_become_flags: ""
ansible_become_user: "{{ windows_user }}"
logon_type: interactive
installers: \\ucilnicesmb.fri1.uni-lj.si\ucilnice_d\install
when: win_ping_data is defined and win_ping_data.ping is defined
when: ansible_shell_type == "powershell"
- name: Set connection parameters and paths for Ubuntu
set_fact:
@ -33,4 +23,4 @@
ansible_become_flags: ""
ansible_ssh_extra_args: '-o ForwardX11=yes'
installers: /mnt/ucilnice_d/install
when: lin_ping_data is defined and lin_ping_data.ping is defined
when: ansible_shell_type == "sh"