Обновить playbooks/install_software_win.yml
This commit is contained in:
1 parent
64316ed83c
commit
3f9e3fea12
1 file changed
+31
-50
@@ -1,69 +1,50 @@
|
|||||||
---
|
|
||||||
- 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
|
- name: Install Software from SMB
|
||||||
hosts: dynamic_windows
|
hosts: dynamic_windows
|
||||||
gather_facts: no
|
gather_facts: no
|
||||||
|
|
||||||
collections:
|
|
||||||
- community.windows
|
|
||||||
- ansible.windows
|
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
drive_letter: "Z"
|
installer_args: "/S"
|
||||||
# target_ip, installer_file приходят из Survey
|
unc_file: "{{ smb_path | regex_replace('\\\\+$', '') }}\\{{ installer_file }}"
|
||||||
# smb_user, smb_pass, smb_path, win_user, win_pass приходят из Environment
|
|
||||||
installer_args: "/S" # можно переопределить в Survey
|
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: Force unmount drive
|
- name: Check installer on share and list folder
|
||||||
community.windows.win_mapped_drive:
|
ansible.windows.win_powershell:
|
||||||
letter: "{{ drive_letter }}"
|
parameters:
|
||||||
state: absent
|
Share: "{{ smb_path }}"
|
||||||
ignore_errors: yes
|
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: Mount network drive
|
- name: Show files on share
|
||||||
community.windows.win_mapped_drive:
|
ansible.builtin.debug:
|
||||||
letter: "{{ drive_letter }}"
|
var: share_check.result.files
|
||||||
path: "{{ smb_path }}"
|
|
||||||
username: "{{ smb_user }}"
|
|
||||||
password: "{{ smb_pass }}"
|
|
||||||
state: present
|
|
||||||
|
|
||||||
- name: Check installer exists
|
|
||||||
ansible.windows.win_stat:
|
|
||||||
path: "{{ drive_letter }}:\\{{ installer_file }}"
|
|
||||||
register: file_info
|
|
||||||
|
|
||||||
- name: Fail if installer not found
|
- name: Fail if installer not found
|
||||||
ansible.builtin.fail:
|
ansible.builtin.fail:
|
||||||
msg: "Файл {{ installer_file }} не найден в {{ smb_path }}"
|
msg: "Файл {{ installer_file }} не найден в {{ smb_path }}"
|
||||||
when: not file_info.stat.exists
|
when: not share_check.result.exists
|
||||||
|
|
||||||
- name: Install {{ installer_file }}
|
- name: Install {{ installer_file }}
|
||||||
ansible.windows.win_package:
|
ansible.windows.win_package:
|
||||||
path: "{{ drive_letter }}:\\{{ installer_file }}"
|
path: "{{ unc_file }}"
|
||||||
|
username: "{{ smb_user }}"
|
||||||
|
password: "{{ smb_pass }}"
|
||||||
state: present
|
state: present
|
||||||
arguments: "{{ installer_args }}"
|
arguments: "{{ installer_args }}"
|
||||||
product_id: "{{ product_id | default(omit) }}"
|
product_id: "{{ product_id | default(omit) }}"
|
||||||
creates_path: "{{ creates_path | default(omit) }}"
|
creates_path: "{{ creates_path | default(omit) }}"
|
||||||
|
no_log: true
|
||||||
post_tasks:
|
|
||||||
- name: Unmount network drive
|
|
||||||
community.windows.win_mapped_drive:
|
|
||||||
letter: "{{ drive_letter }}"
|
|
||||||
state: absent
|
|
||||||
ignore_errors: yes
|
|
||||||
Reference in new issue
Block a user