Difference between revisions of "Ansible Playbook"
Jump to navigation
Jump to search
| (3 intermediate revisions by the same user not shown) | |||
| Line 31: | Line 31: | ||
failed_when: result['exists'] == false | failed_when: result['exists'] == false | ||
- name: Uninstall SensuCore | - name: Uninstall SensuCore | ||
| − | throttle: | + | throttle: 50 |
ansible.builtin.script: ./uninstallSensuCore.ps1 | ansible.builtin.script: ./uninstallSensuCore.ps1 | ||
when: result is not failed | when: result is not failed | ||
| Line 44: | Line 44: | ||
``` | ``` | ||
| + | uninstallSensuCore.ps1 | ||
``` | ``` | ||
| − | + | $ErrorActionPreference = "Stop" | |
| + | Stop-Service sensu-client # you usually don't need to stop this but just in case | ||
| + | $64bitnode = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall' | ||
| + | $32bitnode = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall' | ||
| + | $Uninstaller = Get-ChildItem -Path $64bitnode,$32bitnode | Get-ItemProperty | Where-Object {$_.DisplayName -eq "Sensu" } | ||
| + | $Uninstaller | ForEach { Start-Process -FilePath MsiExec.exe -ArgumentList "/X$($PSItem.PSChildName) /Q" -Wait } | ||
| + | sc.exe delete "sensu-client" | ||
``` | ``` | ||
| + | |||
| + | ``` | ||
| + | /usr/bin/ansible-playbook -f 100 -i test1.inventory.yaml test2.inventory.yaml playbookUninstallSensuCore.yaml # fork -f default is usually 5 | ||
| + | ``` | ||
| + | |||
| + | throttle and serial are options in runbook to limit but not sure how well they work. | ||
Latest revision as of 03:23, 5 August 2021
Here is an example of removing old service no longer used on windows
Set your vars
vars.yaml
ansible_user: '' ansible_password: '' ansible_connection: winrm ansible_port: 5985 ansible_winrm_scheme: http # not recommended ansible_winrm_transport: ntlm ansible_winrm_server_cert_validation: ignore # not recommended
playbookUninstallSensuCore.yaml
---
- name: Checking Services on Windows
# connection: ansible.netcommon.network_cli
gather_facts: false
hosts: all
vars_files:
- vars.yaml
tasks:
- name: Sensucore service sensu-client exists on host
win_service:
name: sensu-client
register: result
failed_when: result['exists'] == false
- name: Uninstall SensuCore
throttle: 50
ansible.builtin.script: ./uninstallSensuCore.ps1
when: result is not failed
# If facts #when: result is not failed and ansible_facts['os_family'] == "Windows"
test.inventory.yaml
all:
hosts:
myhost.example.com:
uninstallSensuCore.ps1
$ErrorActionPreference = "Stop"
Stop-Service sensu-client # you usually don't need to stop this but just in case
$64bitnode = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
$32bitnode = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
$Uninstaller = Get-ChildItem -Path $64bitnode,$32bitnode | Get-ItemProperty | Where-Object {$_.DisplayName -eq "Sensu" }
$Uninstaller | ForEach { Start-Process -FilePath MsiExec.exe -ArgumentList "/X$($PSItem.PSChildName) /Q" -Wait }
sc.exe delete "sensu-client"
/usr/bin/ansible-playbook -f 100 -i test1.inventory.yaml test2.inventory.yaml playbookUninstallSensuCore.yaml # fork -f default is usually 5
throttle and serial are options in runbook to limit but not sure how well they work.