salt.modules.win_dsc

Module for managing PowerShell modules

depends:
  • PowerShell 5.0

Support for PowerShell

salt.modules.win_dsc.apply_config(path, source=None, salt_env='base')

Run an compiled DSC configuration (a folder containing a .mof file). The folder can be cached from the salt master using the source option.

参数:path (str) -- Local path to the directory that contains the .mof

configuration file to apply. Required.

参数:source (str) -- Path to the directory that contains the .mof file on the

file_roots. The source directory will be copied to the path directory and then executed. If the path and source directories differ, the source directory will be applied. If source is not passed, the config located at path will be applied. Optional.

参数:salt_env (str) -- The salt environment to use when copying your source.

Default is 'base'

返回:True if successful, otherwise False
返回类型:bool

CLI Example:

To apply a config that already exists on the the system

salt '*' dsc.run_config C:\\DSC\\WebSiteConfiguration

To cache a configuration from the master and apply it:

salt '*' dsc.run_config C:\\DSC\\WebSiteConfiguration salt://dsc/configs/WebSiteConfiguration
salt.modules.win_dsc.avail_modules(desc=False)

List available modules in registered Powershell module repositories.

desc : False
If True, the verbose description will be returned.

CLI Example:

salt 'win01' dsc.avail_modules
salt 'win01' dsc.avail_modules desc=True
salt.modules.win_dsc.bootstrap()

Make sure that nuget-anycpu.exe is installed. This will download the official nuget-anycpu.exe from the internet.

CLI Example:

salt 'win01' dsc.bootstrap
salt.modules.win_dsc.compile_config(path, source=None, config=None, salt_env='base')

Compile a config from a powershell script (.ps1)

参数:path (str) -- Path (local) to the script that will create the .mof

configuration file. If no source is passed, the file must exist locally. Required.

参数:source (str) -- Path to the script on file_roots to cache at the

location specified by path. The source file will be cached locally and then executed. If source is not passed, the config script located at path will be compiled. Optional.

参数:config (str) -- The name of the Configuration within the script to apply.

If the script contains multiple configurations within the file a config must be specified. If the config is not specified, the name of the file will be used as the config to run. Optional.

参数:salt_env (str) -- The salt environment to use when copying the source.

Default is 'base'

返回:A dictionary containing the results of the compilation
返回类型:dict

CLI Example:

To compile a config from a script that already exists on the system:

salt '*' dsc.compile_config C:\\DSC\\WebsiteConfig.ps1

To cache a config script to the system from the master and compile it:

salt '*' dsc.compile_config C:\\DSC\\WebsiteConfig.ps1 salt://dsc/configs/WebsiteConfig.ps1
salt.modules.win_dsc.enable_scripts()

Enable Powershell Scripts

Allows all Powershell scripts to be run. Executes "Set-ExecutionPolicy Unrestricted" on the system.

CLI Example:

salt 'win01' dsc.enable_scripts
salt.modules.win_dsc.get_config()

Get the current DSC Configuration

返回:A dictionary representing the DSC Configuration on the machine
返回类型:dict

CLI Example:

salt '*' dsc.get_config
salt.modules.win_dsc.get_config_status()

Get the status of the current DSC Configuration

返回:A dictionary representing the status of the current DSC

Configuration on the machine :rtype: dict

CLI Example:

salt '*' dsc.get_config_status
salt.modules.win_dsc.get_lcm_config()

Get the current Local Configuration Manager settings

返回:A dictionary representing the Local Configuration Manager settings on the machine
返回类型:dict

CLI Example:

salt '*' dsc.get_lcm_config
salt.modules.win_dsc.install(name)

Install a Powershell DSC module on the system.

name
Name of a Powershell DSC module

CLI Example:

salt 'win01' dsc.install PowerPlan
salt.modules.win_dsc.list_modules(desc=False)

List currently installed DSC Modules on the system.

desc : False
If True, the verbose description will be returned.

CLI Example:

salt 'win01' dsc.list_modules
salt 'win01' dsc.list_modules desc=True
salt.modules.win_dsc.psversion()

Returns the Powershell version

CLI Example:

salt 'win01' dsc.psversion
salt.modules.win_dsc.remove(name)

Remove a Powershell DSC module from the system.

name
Name of a Powershell DSC module

CLI Example:

salt 'win01' dsc.remove PowerPlan
salt.modules.win_dsc.run_config(path, source=None, config=None, salt_env='base')

Compile a DSC Configuration in the form of a powershell script (.ps1) and apply it. The powershell script can be cached from the master using the source option. If there is more than one config within the powershell script, the desired configuration can be applied by passing the name in the config option.

This command would be the equivalent of running dsc.compile_config and dsc.apply_config separately.

参数:path (str) -- The local path to the powershell script that contains the

DSC Configuration. Required.

参数:source (str) -- The path to the script on file_roots to cache at the

location specified by path. The source file will be cached locally and then executed. If source is not passed, the config script located at path will be compiled. Optional.

参数:config (str) -- The name of the Configuration within the script to apply.

If the script contains multiple configurations within the file a config must be specified. If the config is not specified, the name of the file will be used as the config to run. Optional.

参数:salt_env (str) -- The salt environment to use when copying the source.

Default is 'base'

返回:True if successfully compiled and applied, False if not
返回类型:bool

CLI Example

To compile a config from a script that already exists on the system:

salt '*' dsc.compile_apply_config C:\\DSC\\WebsiteConfig.ps1

To cache a config script to the system from the master and compile it:

salt '*' dsc.compile_apply_config C:\\DSC\\WebsiteConfig.ps1 salt://dsc/configs/WebsiteConfig.ps1
salt.modules.win_dsc.set_lcm_config(config_mode=None, config_mode_freq=None, refresh_freq=None, reboot_if_needed=None, action_after_reboot=None, refresh_mode=None, certificate_id=None, configuration_id=None, allow_module_overwrite=None, debug_mode=False, status_retention_days=None)

For detailed descriptions of the parameters see: https://msdn.microsoft.com/en-us/PowerShell/DSC/metaConfig

参数:config_mode (str) -- How the LCM applies the configuration. Valid values

are: - ApplyOnly - ApplyAndMonitor - ApplyAndAutoCorrect

参数:config_mode_freq (int) -- How often, in minutes, the current

configuration is checked and applied. Ignored if config_mode is set to ApplyOnly. Default is 15.

参数:refresh_mode (str) -- How the LCM gets configurations. Valid values are:
  • Disabled
  • Push
  • Pull
参数:refresh_freq (int) -- How often, in minutes, the LCM checks for updated

configurations. (pull mode only) Default is 30.

注解

Either config_mode_freq or refresh_freq needs to be a multiple

of the other. See documentation on MSDN for more details.

参数:reboot_if_needed (bool) -- Reboot the machine if needed after a

configuration is applied. Default is False.

参数:action_after_reboot (str) -- Action to take after reboot. Valid values

are: - ContinueConfiguration - StopConfiguration

参数:certificate_id (guid) -- A GUID that specifies a certificate used to

access the configuration: (pull mode)

参数:configuration_id (guid) -- A GUID that identifies the config file to get

from a pull server. (pull mode)

参数:allow_module_overwrite (bool) -- New configs are allowed to overwrite old

ones on the target node.

参数:debug_mode (str) -- Sets the debug level. Valid values are:
  • None
  • ForceModuleImport
  • All
参数:status_retention_days (int) -- Number of days to keep status of the

current config.

Returns:

salt.modules.win_dsc.test_config()

Tests the current applied DSC Configuration

返回:True if successfully applied, otherwise False
返回类型:bool

CLI Example:

salt '*' dsc.test_config