aim-web2.1.0rc9
This commit is contained in:
@@ -1,82 +1,37 @@
|
||||
---
|
||||
- name: "Maintenance | Start stopped automatic services"
|
||||
hosts: all
|
||||
gather_facts: true
|
||||
|
||||
tasks:
|
||||
- name: "Windows | Start stopped automatic services"
|
||||
when: ansible_facts['os_family'] == 'Windows'
|
||||
ansible.windows.win_powershell:
|
||||
script: |
|
||||
$Ansible.Changed = $false
|
||||
$started = @()
|
||||
|
||||
Get-CimInstance Win32_Service |
|
||||
Where-Object {
|
||||
$_.StartMode -eq 'Auto' -and
|
||||
$_.State -ne 'Running'
|
||||
} |
|
||||
ForEach-Object {
|
||||
try {
|
||||
Start-Service -Name $_.Name -ErrorAction Stop
|
||||
$started += $_.Name
|
||||
$Ansible.Changed = $true
|
||||
}
|
||||
catch {
|
||||
Write-Warning "Could not start service $($_.Name): $($_.Exception.Message)"
|
||||
}
|
||||
}
|
||||
|
||||
$Ansible.Result = @{
|
||||
started_services = $started
|
||||
}
|
||||
register: started_services_windows
|
||||
|
||||
- name: "Windows | Show started services"
|
||||
when: ansible_facts['os_family'] == 'Windows'
|
||||
# PURPOSE: Start stopped automatic services
|
||||
# DESCRIPTION: Start eligible stopped services, apply optional include/exclude lists and report partial failures.
|
||||
# TARGETS: windows
|
||||
# INPUTS (omitted values inherit inventory / role defaults):
|
||||
# aim_debug [bool]: false
|
||||
# maintenance_service_include [list]: []
|
||||
# maintenance_service_exclude [list]: []
|
||||
# maintenance_service_fail_on_error [bool]: true
|
||||
# AUTH: existing inventory / Vault credentials; no embedded passwords.
|
||||
# EXAMPLE: ansible-playbook -i inventories/<customer>/hosts.yml
|
||||
# playbooks/maintenance_start_stopped_services.yml --limit <host> --vault-id <customer>@prompt
|
||||
- name: Maintenance | Start automatic services
|
||||
hosts: windows
|
||||
gather_facts: false
|
||||
pre_tasks:
|
||||
- name: AIM | Validate diagnostics option
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- (aim_debug | default(false)) is boolean or (aim_debug | default(false) | string | lower) in ['true',
|
||||
'false']
|
||||
fail_msg: aim_debug must be a YAML/JSON boolean.
|
||||
quiet: true
|
||||
- name: AIM | Reject mixed platform membership
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- (group_names | intersect(['linux', 'windows', 'sophosxgs', 'pfsense']) | length) <= 1
|
||||
fail_msg: This host belongs to incompatible platform groups. Use globally unique subgroups.
|
||||
quiet: true
|
||||
- name: AIM | Execution context
|
||||
ansible.builtin.debug:
|
||||
var: started_services_windows.result.started_services
|
||||
|
||||
- name: "Linux | Collect service facts"
|
||||
when: ansible_facts['os_family'] != 'Windows'
|
||||
ansible.builtin.service_facts:
|
||||
|
||||
- name: "Linux | Start stopped enabled systemd services"
|
||||
when:
|
||||
- ansible_facts['os_family'] != 'Windows'
|
||||
- ansible_facts['service_mgr'] == 'systemd'
|
||||
- item.value.status | default('') == 'enabled'
|
||||
- item.value.state | default('') != 'running'
|
||||
become: true
|
||||
ansible.builtin.systemd:
|
||||
name: "{{ item.key }}"
|
||||
state: started
|
||||
loop: "{{ ansible_facts.services | dict2items }}"
|
||||
loop_control:
|
||||
label: "{{ item.key }}"
|
||||
register: started_services_linux
|
||||
failed_when: false
|
||||
|
||||
- name: "Linux | Show services that were started"
|
||||
when:
|
||||
- ansible_facts['os_family'] != 'Windows'
|
||||
- ansible_facts['service_mgr'] == 'systemd'
|
||||
ansible.builtin.debug:
|
||||
msg: >-
|
||||
{{
|
||||
started_services_linux.results
|
||||
| default([])
|
||||
| selectattr('changed', 'defined')
|
||||
| selectattr('changed')
|
||||
| map(attribute='item.key')
|
||||
| list
|
||||
}}
|
||||
|
||||
- name: "Linux | Report unsupported service manager"
|
||||
when:
|
||||
- ansible_facts['os_family'] != 'Windows'
|
||||
- ansible_facts['service_mgr'] != 'systemd'
|
||||
ansible.builtin.debug:
|
||||
msg: >-
|
||||
Automatic stopped-service recovery currently supports systemd hosts only.
|
||||
Detected service manager: {{ ansible_facts['service_mgr'] }}
|
||||
msg:
|
||||
host: '{{ inventory_hostname }}'
|
||||
diagnostics: Enabled; secret values are never included by this task.
|
||||
when: aim_debug | default(false) | bool
|
||||
roles:
|
||||
- role: maintenance_start_stopped_services
|
||||
|
||||
Reference in New Issue
Block a user