■ ■ ■ ■ ■ ■
ansible/roles/logs_windows/tasks/winlogbeat.yml
| 1 | + | --- |
| 2 | + | # from https://github.com/j91321/ansible-role-winlogbeat |
| 3 | + | - name: Create 64-bit install directory |
| 4 | + | win_file: |
| 5 | + | path: "{{ winlogbeat_service.install_path_64 }}" |
| 6 | + | state: directory |
| 7 | + | |
| 8 | + | - name: Check if winlogbeat service is installed |
| 9 | + | win_service: |
| 10 | + | name: winlogbeat |
| 11 | + | register: winlogbeat_installed |
| 12 | + | |
| 13 | + | - name: Check if winlogbeat is using current version |
| 14 | + | win_stat: |
| 15 | + | path: "{{ winlogbeat_service.install_path_64 }}\\winlogbeat-{{ winlogbeat_service.version }}-windows-x86_64" |
| 16 | + | register: winlogbeat_folder |
| 17 | + | |
| 18 | + | - name: Copy winlogbeat uninstall script |
| 19 | + | win_copy: |
| 20 | + | src: files/uninstall-service-winlogbeat.ps1 |
| 21 | + | dest: "{{ winlogbeat_service.install_path_64 }}\\uninstall-service-winlogbeat.ps1" |
| 22 | + | force: yes |
| 23 | + | when: winlogbeat_installed.exists and not winlogbeat_folder.stat.exists |
| 24 | + | |
| 25 | + | - name: Uninstall winlogbeat |
| 26 | + | win_shell: .\uninstall-service-winlogbeat.ps1 |
| 27 | + | args: |
| 28 | + | chdir: "{{ winlogbeat_service.install_path_64 }}" |
| 29 | + | when: winlogbeat_installed.exists and not winlogbeat_folder.stat.exists |
| 30 | + | |
| 31 | + | - name: Download winlogbeat |
| 32 | + | win_get_url: |
| 33 | + | url: "https://artifacts.elastic.co/downloads/beats/winlogbeat/winlogbeat-{{ winlogbeat_service.version }}-windows-x86_64.zip" |
| 34 | + | dest: "{{ winlogbeat_service.install_path_64 }}\\winlogbeat.zip" |
| 35 | + | when: winlogbeat_service.download and not winlogbeat_folder.stat.exists |
| 36 | + | |
| 37 | + | - name: Copy winlogbeat |
| 38 | + | win_copy: |
| 39 | + | src: "files/winlogbeat-{{ winlogbeat_service.version }}-windows-x86_64.zip" |
| 40 | + | dest: "{{ winlogbeat_service.install_path_64 }}\\winlogbeat.zip" |
| 41 | + | when: not winlogbeat_service.download and not winlogbeat_folder.stat.exists |
| 42 | + | |
| 43 | + | - name: Unzip winlogbeat |
| 44 | + | win_unzip: |
| 45 | + | src: "{{ winlogbeat_service.install_path_64 }}\\winlogbeat.zip" |
| 46 | + | dest: "{{ winlogbeat_service.install_path_64 }}\\" |
| 47 | + | delete_archive: yes |
| 48 | + | when: not winlogbeat_folder.stat.exists |
| 49 | + | |
| 50 | + | - name: Configure winlogbeat |
| 51 | + | win_copy: |
| 52 | + | src: winlogbeat.yml |
| 53 | + | dest: "{{ winlogbeat_service.install_path_64 }}\\winlogbeat-{{ winlogbeat_service.version }}-windows-x86_64\\winlogbeat.yml" |
| 54 | + | notify: restart-winlogbeat |
| 55 | + | |
| 56 | + | - name: Install winlogbeat |
| 57 | + | win_shell: .\install-service-winlogbeat.ps1 |
| 58 | + | args: |
| 59 | + | chdir: "{{ winlogbeat_service.install_path_64 }}\\winlogbeat-{{ winlogbeat_service.version }}-windows-x86_64\\" |
| 60 | + | when: not winlogbeat_folder.stat.exists |
| 61 | + | notify: restart-winlogbeat |
| 62 | + | |
| 63 | + | - name: Remove other winlogbeat installations |
| 64 | + | win_shell: | |
| 65 | + | $version="{{ winlogbeat_service.version }}" |
| 66 | + | Get-ChildItem -Path "{{ winlogbeat_service.install_path_64 }}" | Where-Object {$_.Name -CNotMatch $version} | Remove-Item -Recurse |
| 67 | + | when: not winlogbeat_folder.stat.exists |
| 68 | + | |