--- - 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 collections: - community.windows - ansible.windows vars: drive_letter: "Z" # target_ip, installer_file приходят из Survey # smb_user, smb_pass, smb_path, win_user, win_pass приходят из Environment installer_args: "/S" # можно переопределить в Survey tasks: - name: Force unmount drive community.windows.win_mapped_drive: letter: "{{ drive_letter }}" state: absent ignore_errors: yes - name: Mount network drive community.windows.win_mapped_drive: letter: "{{ drive_letter }}" 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 ansible.builtin.fail: msg: "Файл {{ installer_file }} не найден в {{ smb_path }}" when: not file_info.stat.exists - name: Install {{ installer_file }} ansible.windows.win_package: path: "{{ drive_letter }}:\\{{ installer_file }}" state: present arguments: "{{ installer_args }}" product_id: "{{ product_id | default(omit) }}" creates_path: "{{ creates_path | default(omit) }}" post_tasks: - name: Unmount network drive community.windows.win_mapped_drive: letter: "{{ drive_letter }}" state: absent ignore_errors: yes