66 lines
2.2 KiB
YAML
66 lines
2.2 KiB
YAML
---
|
|
- name: Prepare target host
|
|
hosts: localhost
|
|
gather_facts: no
|
|
tasks:
|
|
- name: Add target host from survey
|
|
ansible.builtin.add_host:
|
|
name: "{{ target_ip }}"
|
|
groups: dynamic_windows
|
|
ansible_connection: winrm
|
|
ansible_port: "{{ winrm_port | default(5985) }}"
|
|
ansible_winrm_transport: "{{ winrm_transport | default('ntlm') }}"
|
|
ansible_winrm_server_cert_validation: ignore
|
|
ansible_user: "{{ win_user }}"
|
|
ansible_password: "{{ win_pass }}"
|
|
|
|
- name: Install Software from SMB
|
|
hosts: dynamic_windows
|
|
gather_facts: no
|
|
|
|
vars:
|
|
installer_args: "/S"
|
|
unc_file: "{{ smb_path | regex_replace('\\\\+$', '') }}\\{{ installer_file }}"
|
|
|
|
tasks:
|
|
- name: Check installer on share and list folder
|
|
ansible.windows.win_powershell:
|
|
parameters:
|
|
Share: "{{ smb_path }}"
|
|
User: "{{ smb_user }}"
|
|
Pass: "{{ smb_pass }}"
|
|
File: "{{ installer_file }}"
|
|
script: |
|
|
param($Share, $User, $Pass, $File)
|
|
$ErrorActionPreference = 'Stop'
|
|
net use $Share /delete /y 2>&1 | Out-Null
|
|
$out = net use $Share /user:$User $Pass 2>&1
|
|
if ($LASTEXITCODE -ne 0) { throw "net use failed: $out" }
|
|
$names = Get-ChildItem -LiteralPath $Share | Select-Object -ExpandProperty Name
|
|
$Ansible.Result = @{
|
|
exists = [bool]($names -contains $File)
|
|
files = $names
|
|
}
|
|
net use $Share /delete /y 2>&1 | Out-Null
|
|
register: share_check
|
|
no_log: true
|
|
|
|
- name: Show files on share
|
|
ansible.builtin.debug:
|
|
var: share_check.result.files
|
|
|
|
- name: Fail if installer not found
|
|
ansible.builtin.fail:
|
|
msg: "Файл {{ installer_file }} не найден в {{ smb_path }}"
|
|
when: not share_check.result.exists
|
|
|
|
- name: Install {{ installer_file }}
|
|
ansible.windows.win_package:
|
|
path: "{{ unc_file }}"
|
|
username: "{{ smb_user }}"
|
|
password: "{{ smb_pass }}"
|
|
state: present
|
|
arguments: "{{ installer_args }}"
|
|
product_id: "{{ product_id | default(omit) }}"
|
|
creates_path: "{{ creates_path | default(omit) }}"
|
|
no_log: true |