HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //lib/python3.9/site-packages/ansible_collections/ansible/windows/plugins/modules/win_feature.ps1
#!powershell

# Copyright: (c) 2014, Paul Durivage <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

#Requires -Module Ansible.ModuleUtils.Legacy

Import-Module -Name ServerManager

$result = @{
    changed = $false
}

$params = Parse-Args $args -supports_check_mode $true
$check_mode = Get-AnsibleParam -obj $params -name "_ansible_check_mode" -type "bool" -default $false

$name = Get-AnsibleParam -obj $params -name "name" -type "list" -failifempty $true
$state = Get-AnsibleParam -obj $params -name "state" -type "str" -default "present" -validateset "present", "absent"

$include_sub_features = Get-AnsibleParam -obj $params -name "include_sub_features" -type "bool" -default $false
$include_management_tools = Get-AnsibleParam -obj $params -name "include_management_tools" -type "bool" -default $false
$source = Get-AnsibleParam -obj $params -name "source" -type "str"

$install_cmdlet = $false
if (Get-Command -Name Install-WindowsFeature -ErrorAction SilentlyContinue) {
    Set-Alias -Name Install-AnsibleWindowsFeature -Value Install-WindowsFeature
    Set-Alias -Name Uninstall-AnsibleWindowsFeature -Value Uninstall-WindowsFeature
    $install_cmdlet = $true
}
elseif (Get-Command -Name Add-WindowsFeature -ErrorAction SilentlyContinue) {
    Set-Alias -Name Install-AnsibleWindowsFeature -Value Add-WindowsFeature
    Set-Alias -Name Uninstall-AnsibleWindowsFeature -Value Remove-WindowsFeature
}
else {
    Fail-Json -obj $result -message "This version of Windows does not support the cmdlets Install-WindowsFeature or Add-WindowsFeature"
}

if ($state -eq "present") {
    $install_args = @{
        Name = $name
        IncludeAllSubFeature = $include_sub_features
        Restart = $false
        WhatIf = $check_mode
        ErrorAction = "Stop"
    }

    if ($install_cmdlet) {
        $install_args.IncludeManagementTools = $include_management_tools
        $install_args.Confirm = $false
        if ($source) {
            if (-not (Test-Path -LiteralPath $source)) {
                Fail-Json -obj $result -message "Failed to find source path $source for feature install"
            }
            $install_args.Source = $source
        }
    }

    try {
        $action_results = Install-AnsibleWindowsFeature @install_args
    }
    catch {
        Fail-Json -obj $result -message "Failed to install Windows Feature: $($_.Exception.Message)"
    }
}
else {
    $uninstall_args = @{
        Name = $name
        Restart = $false
        WhatIf = $check_mode
        ErrorAction = "Stop"
    }
    if ($install_cmdlet) {
        $uninstall_args.IncludeManagementTools = $include_management_tools
    }

    try {
        $action_results = Uninstall-AnsibleWindowsFeature @uninstall_args
    }
    catch {
        Fail-Json -obj $result -message "Failed to uninstall Windows Feature: $($_.Exception.Message)"
    }
}

# Loop through results and create a hash containing details about
# each role/feature that is installed/removed
# $action_results.FeatureResult is not empty if anything was changed
$feature_results = @()
foreach ($action_result in $action_results.FeatureResult) {
    $message = @()
    foreach ($msg in $action_result.Message) {
        $message += @{
            message_type = $msg.MessageType.ToString()
            error_code = $msg.ErrorCode
            text = $msg.Text
        }
    }

    $feature_results += @{
        id = $action_result.Id
        display_name = $action_result.DisplayName
        message = $message
        reboot_required = ConvertTo-Bool -obj $action_result.RestartNeeded
        skip_reason = $action_result.SkipReason.ToString()
        success = ConvertTo-Bool -obj $action_result.Success
        restart_needed = ConvertTo-Bool -obj $action_result.RestartNeeded
    }
    $result.changed = $true
}
$result.feature_result = $feature_results
$result.success = ConvertTo-Bool -obj $action_results.Success
$result.exitcode = $action_results.ExitCode.ToString()
$result.reboot_required = ConvertTo-Bool -obj $action_results.RestartNeeded
# controls whether Ansible will fail or not
$result.failed = (-not $action_results.Success)

Exit-Json -obj $result