sqlserver
Version information
This version is compatible with:
- Puppet Enterprise 2023.2.x, 2023.1.x, 2023.0.x, 2021.7.x, 2021.6.x, 2021.5.x, 2021.4.x, 2021.3.x, 2021.2.x, 2021.1.x, 2021.0.x, 2019.8.x, 2019.7.x, 2019.5.x, 2019.4.x, 2019.3.x, 2019.2.x, 2019.1.x, 2019.0.x
- Puppet >=6.0.0 < 8.0.0
Tasks:
- get_sqlagent_jobs
- set_sql_logins
- start_sql_agent_job
- get_sql_logins
This module is licensed for use with Puppet Enterprise. You may also evaluate this module for up to 90 days.Learn More
Start using this module
Add this module to your Puppetfile:
mod 'puppetlabs-sqlserver', '3.0.0'
Learn more about managing modules with a PuppetfileDocumentation
sqlserver
Table of contents
- Overview
- Module Description - What the module does and why it is useful
- Setup - The basics of getting started with sqlserver
- Usage - Configuration options and additional functionality
- Reference - An under-the-hood peek at what the module is doing and how
- Limitations - OS compatibility, etc.
- Development - Guide for contributing to the module
Overview
The sqlserver module installs and manages Microsoft SQL Server 2012, 2014, 2016, 2017, 2019 on Windows systems.
Module Description
Microsoft SQL Server is a database platform for Windows. The sqlserver module lets you use Puppet to install multiple instances of SQL Server, add SQL features and client tools, execute TSQL statements, and manage databases, users, roles, and server configuration options.
Setup
Setup Requirements
The sqlserver module requires the following:
- .NET 3.5. (Installed automatically if not present. This might require an internet connection.)
- The contents of the SQL Server ISO file, mounted or extracted either locally or on a network share.
- Windows Server 2012, 2012 R2, or 2016.
Beginning with sqlserver
To get started with the sqlserver module, include in your manifest:
sqlserver_instance{ 'MSSQLSERVER':
features => ['SQL'],
source => 'E:/',
sql_sysadmin_accounts => ['myuser'],
}
This example installs MS SQL and creates an MS SQL instance named MSSQLSERVER. It also installs the base SQL feature set (Data Quality, FullText, Replication, and SQLEngine), specifies the location of the setup.exe, and creates a new SQL-only sysadmin, 'myuser'.
A more advanced configuration, including installer switches:
sqlserver_instance{ 'MSSQLSERVER':
source => 'E:/',
features => ['SQL'],
security_mode => 'SQL',
sa_pwd => 'p@ssw0rd!!',
sql_sysadmin_accounts => ['myuser'],
install_switches => {
'TCPENABLED' => 1,
'SQLBACKUPDIR' => 'C:\\MSSQLSERVER\\backupdir',
'SQLTEMPDBDIR' => 'C:\\MSSQLSERVER\\tempdbdir',
'INSTALLSQLDATADIR' => 'C:\\MSSQLSERVER\\datadir',
'INSTANCEDIR' => 'C:\\Program Files\\Microsoft SQL Server',
'INSTALLSHAREDDIR' => 'C:\\Program Files\\Microsoft SQL Server',
'INSTALLSHAREDWOWDIR' => 'C:\\Program Files (x86)\\Microsoft SQL Server',
}
}
This example creates the same MS SQL instance as shown above with additional options: security mode (requiring password to be set) and other optional install switches. This is specified using a hash syntax.
Usage
Note: For clarification on Microsoft SQL Server terminology, please see Microsoft SQL Server Terms below.
Install SQL Server tools and features not specific to a SQL Server instance
sqlserver_features { 'Generic Features':
source => 'E:/',
features => ['BC', 'Conn', 'SDK'],
}
Create a new database on an instance of SQL Server
sqlserver::database{ 'minviable':
instance => 'MSSQLSERVER',
}
Set up a new login
SQL Login
sqlserver::login{ 'vagrant':
instance => 'MSSQLSERVER',
password => 'Pupp3t1@',
}
# Windows Login
sqlserver::login{ 'WIN-D95P1A3V103\localAccount':
instance => 'MSSQLSERVER',
login_type => 'WINDOWS_LOGIN',
}
Create a new login and a user for a given database
sqlserver::login{ 'loggingUser':
password => 'Pupp3t1@',
}
sqlserver::user{ 'rp_logging-loggingUser':
user => 'loggingUser',
database => 'rp_logging',
require => Sqlserver::Login['loggingUser'],
}
Manage the above user's permissions
sqlserver::user::permissions{'INSERT-loggingUser-On-rp_logging':
user => 'loggingUser',
database => 'rp_logging',
permissions => 'INSERT',
require => Sqlserver::User['rp_logging-loggingUser'],
}
sqlserver::user::permissions{ 'Deny the Update as we should only insert':
user => 'loggingUser',
database => 'rp_logging',
permissions => 'UPDATE',
state => 'DENY',
require => Sqlserver::User['rp_logging-loggingUser'],
}
Run custom TSQL statements
Use sqlserver_tsql
to trigger other classes or defined types
sqlserver_tsql{ 'Query Logging DB Status':
instance => 'MSSQLSERVER',
onlyif => "IF (SELECT count(*) FROM myDb.dbo.logging_table WHERE
message like 'FATAL%') > 1000 THROW 50000, 'Fatal Exceptions in Logging', 10",
notify => Exec['Too Many Fatal Errors']
}
Clean up regular logs with conditional checks
sqlserver_tsql{ 'Cleanup Old Logs':
instance => 'MSSQLSERVER',
command => "DELETE FROM myDb.dbo.logging_table WHERE log_date < '${log_max_date}'",
onlyif => "IF exists(SELECT * FROM myDb.dbo.logging_table WHERE log_date < '${log_max_date}')
THROW 50000, 'need log cleanup', 10",
}
If you want your statement to always execute, leave out the onlyif
parameter
sqlserver_tsql{ 'Always running':
instance => 'MSSQLSERVER',
command => 'EXEC notified_executor()',
}
Advanced example
This advanced example:
-
Installs the basic SQL Server Engine from installation media mounted at 'D:\' with TCP Enabled and various directories set.
-
Uses only Windows-based authentication and installs with only the user that Puppet is executing as. Note that the 'sql_sysadmin_accounts' is only applicable during the instance installation and is not actively enforced.
-
Creates a
sqlserver::config
resource, which is used in later resources to connect to the newly created instance. As we support only Windows-based authentication, a username and password is not required. -
Creates a local group called 'DB Administrators' and ensures that it is SQL System Administrator (sysadmin role); also creates the account that Puppet uses to install and manage the instance.
-
Ensures that the advanced options for
sp_configure
are enabled, so that Puppet can manage themax memory
setting for the instance. -
Ensure that the
max memory
(MB) configuration item is set to 2048 megabytes.
$sourceloc = 'D:/'
# Install a SQL Server default instance
sqlserver_instance{'MSSQLSERVER':
source => $sourceloc,
features => ['SQLEngine'],
sql_sysadmin_accounts => [$facts['id']],
install_switches => {
'TCPENABLED' => 1,
'SQLBACKUPDIR' => 'C:\\MSSQLSERVER\\backupdir',
'SQLTEMPDBDIR' => 'C:\\MSSQLSERVER\\tempdbdir',
'INSTALLSQLDATADIR' => 'C:\\MSSQLSERVER\\datadir',
'INSTANCEDIR' => 'C:\\Program Files\\Microsoft SQL Server',
'INSTALLSHAREDDIR' => 'C:\\Program Files\\Microsoft SQL Server',
'INSTALLSHAREDWOWDIR' => 'C:\\Program Files (x86)\\Microsoft SQL Server'
}
}
# Resource to connect to the DB instance
sqlserver::config { 'MSSQLSERVER':
admin_login_type => 'WINDOWS_LOGIN'
}
# Enforce SQL Server Administrators
$local_dba_group_name = 'DB Administrators'
$local_dba_group_netbios_name = "${facts['hostname']}\\DB Administrators"
group { $local_dba_group_name:
ensure => present
}
-> sqlserver::login { $local_dba_group_netbios_name :
login_type => 'WINDOWS_LOGIN',
}
-> sqlserver::role { 'sysadmin':
ensure => 'present',
instance => 'MSSQLSERVER',
type => 'SERVER',
members => [$local_dba_group_netbios_name, $facts['id']],
}
# Enforce memory consumption
sqlserver_tsql {'check advanced sp_configure':
command => 'EXEC sp_configure \'show advanced option\', \'1\'; RECONFIGURE;',
onlyif => 'sp_configure @configname=\'max server memory (MB)\'',
instance => 'MSSQLSERVER'
}
-> sqlserver::sp_configure { 'MSSQLSERVER-max memory':
config_name => 'max server memory (MB)',
instance => 'MSSQLSERVER',
reconfigure => true,
restart => true,
value => 2048
}
Note: $facts['hostnane'] is only suitable for building login names for local machine logins. For building domain logins you will need the domain name instead. $facts['domain'] returns the full domain name which will usually not be what you need. Try instead:
$netbios_name = split($facts['domain'],'\.')[0]
$dba_group_netbios_name = "${netbios_name}\\DB Administrators"
sqlserver::role { 'sysadmin':
ensure => 'present',
instance => 'MSSQLSERVER',
type => 'SERVER',
members => [$dba_group_netbios_name, $facts['id']],
}
Reference
For information on the classes and types, see the REFERENCE.md
Limitations
SQL 2017 and 2019 detection support has been added. This support is limited to functionality already present for other versions. No new SQL 2017 or above specific functionality has been added in this release.
This module can manage only a single version of SQL Server on a given host (one and only one of SQL Server 2012, 2014, 2016, 2017, or 2019). The module is able to manage multiple SQL Server instances of the same version.
This module cannot manage the SQL Server Native Client SDK (also known as SNAC_SDK). The SQL Server installation media can install the SDK, but it is not able to uninstall the SDK. Note that the 'sqlserver_features' fact detects the presence of the SDK.
In SQL Server 2016 and newer, Microsoft separated the installation of SQL Server Management Studio (SSMS) from the installation of the SQL Server engine and other features. SSMS now has its own installer and can be installed and managed via Chocolatey. As such, specifying SSMS in the sqlserver
as a feature to install no longer works with SQL Server 2016 and newer. Instead, use package
resources with the Chocolatey provider to manage SSMS installation.
Development
This module was built by Puppet specifically for use with Puppet Enterprise (PE).
If you run into an issue with this module, or if you would like to request a feature, please file a ticket.
If you have problems getting this module up and running, please contact Support.
If you would like to contribute to this module, please follow the rules in the CONTRIBUTING.md. For more information, see our module contribution guide.
Reference
Table of Contents
Defined types
sqlserver::config
: Define Resource Type: sqlserver::configsqlserver::database
: Define Resource Type: sqlserver::databasesqlserver::login
: Define Resource Type: sqlserver::loginsqlserver::login::permissions
: Define Resource Type: sqlserver::login::permissions#sqlserver::role
: Define Resource Type: sqlserver::role::permissionssqlserver::role::permissions
: Define Resource Type: sqlserver::role::permissionssqlserver::sp_configure
: Defined Resource Type: sqlserver::sp_configuresqlserver::user
: Define Resource Type: sqlserver::usersqlserver::user::permissions
: Define Resource Type: sqlserver::user::permissions
Resource types
sqlserver_features
: Due to our prefetch and unaware of what name the user will provide we munge the value to meet our expecations.sqlserver_instance
: Namevarsqlserver_tsql
: Namevar
Functions
sqlserver_is_domain_or_local_user
sqlserver_upcase
sqlserver_validate_hash_uniq_values
sqlserver_validate_instance_name
sqlserver_validate_range
sqlserver_validate_size
Tasks
get_sql_logins
: Retrieve information about the logins configured for a SQL Server instance.get_sqlagent_jobs
: Return information about SQL Agent jobs and job steps.set_sql_logins
: Set IsDisabled, and Password properties of a SQL Loginstart_sql_agent_job
: Start SQL Agent jobs on a server. You can start at a specified job step number (zero based indexes), and you can either wait on the job to co
Defined types
sqlserver::config
Define Resource Type: sqlserver::config
Examples
sqlserver::config{'MSSQLSERVER':
admin_user => 'sa',
admin_pass => 'PuppetP@ssword1',
}
Parameters
The following parameters are available in the sqlserver::config
defined type:
instance_name
Data type: String[1,16]
The instance name you want to manage. Defaults to the $title when not defined explicitly.
Default value: $title
admin_user
Data type: Optional[String]
Only required for SQL_LOGIN type. A user/login who has sysadmin rights on the server
Default value: ''
admin_pass
Data type: Optional[String]
Only required for SQL_LOGIN type. The password in order to access the server to be managed.
Default value: ''
admin_login_type
Data type: Enum['SQL_LOGIN', 'WINDOWS_LOGIN']
The type of account use to configure the server. Valid values are SQL_LOGIN and WINDOWS_LOGIN, with a default of SQL_LOGIN The SQL_LOGIN requires the admin_user and admin_pass to be set The WINDOWS_LOGIN requires the adm_user and admin_pass to be empty or undefined
Default value: 'SQL_LOGIN'
sqlserver::database
Requirement/Dependencies: Requires defined type {sqlserver::config} in order to execute against the SQL Server instance
- See also
- http://msdn.microsoft.com/en-us/library/ff929071.aspx
- Contained Databases
- http://msdn.microsoft.com/en-us/library/ms176061.aspx
- CREATE DATABASE TSQL
- http://msdn.microsoft.com/en-us/library/ms174269.aspx
- ALTER DATABASE TSQL
- http://msdn.microsoft.com/en-us/library/ms190303.aspx
- System Languages
- http://msdn.microsoft.com/en-us/library/ff929071.aspx
Parameters
The following parameters are available in the sqlserver::database
defined type:
db_name
instance
ensure
compatibility
collation_name
filestream_non_transacted_access
filestream_directory_name
filespec_name
filespec_filename
filespec_size
filespec_maxsize
filespec_filegrowth
log_name
log_filename
log_size
log_maxsize
log_filegrowth
containment
default_fulltext_language
default_language
nested_triggers
transform_noise_words
two_digit_year_cutoff
db_chaining
trustworthy
db_name
Data type: String[1,128]
The database you would like to manage
Default value: $title
instance
Data type: String[1,16]
The name of the instance which to connect to, instance names can not be longer than 16 characters
Default value: 'MSSQLSERVER'
ensure
Data type: Enum['present', 'absent']
Defaults to 'present', valid values are 'present' | 'absent'
Default value: 'present'
compatibility
Data type: Integer
Numberic representation of what SQL Server version you want the database to be compatabible with.
Default value: 100
collation_name
Data type: Optional[String[1]]
Default value: undef
filestream_non_transacted_access
Data type: Optional[Enum['OFF', 'READ_ONLY', 'FULL']]
Value should be { OFF | READ_ONLY | FULL } Specifies the level of non-transactional FILESTREAM access to the database.
Default value: undef
filestream_directory_name
Data type: Optional[Pattern[/^[\w|\s]+$/]]
A windows-compatible directory name. This name should be unique among all the Database_Directory names in the SQL Server instance. Uniqueness comparison is case-insensitive, regardless of SQL Server collation settings. This option should be set before creating a FileTable in this database.
Default value: undef
filespec_name
Data type: Optional[String[1,128]]
Specifies the logical name for the file. NAME is required when FILENAME is specified, except when specifying one of the FOR ATTACH clauses. A FILESTREAM filegroup cannot be named PRIMARY.
Default value: undef
filespec_filename
Data type: Optional[Stdlib::Absolutepath]
Specifies the operating system (physical) file name.
Default value: undef
filespec_size
Data type: Optional[String[1]]
Specifies the size of the file. The kilobyte (KB), megabyte (MB), gigabyte (GB), or terabyte (TB) suffixes can be used. The default is MB. Values can not be greater than 2147483647
Default value: undef
filespec_maxsize
Data type: Optional[String[1]]
Specifies the maximum size to which the file can grow. MAXSIZE cannot be specified when the os_file_name is specified as a UNC path
Default value: undef
filespec_filegrowth
Data type: Optional[String[1]]
Specifies the automatic growth increment of the file. The FILEGROWTH setting for a file cannot exceed the MAXSIZE setting. FILEGROWTH cannot be specified when the os_file_name is specified as a UNC path. FILEGROWTH does not apply to a FILESTREAM filegroup.
Default value: undef
log_name
Data type: Optional[String[1,128]]
Specifies the logical name for the file. NAME is required when FILENAME is specified, except when specifying one of the FOR ATTACH clauses. A FILESTREAM filegroup cannot be named PRIMARY.
Default value: undef
log_filename
Data type: Optional[Stdlib::Absolutepath]
Specifies the operating system (physical) file name.
Default value: undef
log_size
Data type: Optional[String[1]]
Specifies the size of the file. The kilobyte (KB), megabyte (MB), gigabyte (GB), or terabyte (TB) suffixes can be used. The default is MB. Values can not be greater than 2147483647
Default value: undef
log_maxsize
Data type: Optional[String[1]]
Specifies the maximum size to which the file can grow. MAXSIZE cannot be specified when the os_file_name is specified as a UNC path
Default value: undef
log_filegrowth
Data type: Optional[String[1]]
Specifies the automatic growth increment of the file. The FILEGROWTH setting for a file cannot exceed the MAXSIZE setting. FILEGROWTH cannot be specified when the os_file_name is specified as a UNC path. FILEGROWTH does not apply to a FILESTREAM filegroup.
Default value: undef
containment
Data type: Enum['PARTIAL', 'NONE']
Defaults to 'NONE'. Other possible values are 'PARTIAL', see http://msdn.microsoft.com/en-us/library/ff929071.aspx
Default value: 'NONE'
default_fulltext_language
Data type: String[1]
Language name i.e. us_english which are documented at http://msdn.microsoft.com/en-us/library/ms190303.aspx
Default value: 'English'
default_language
Data type: String[1]
Language name i.e. us_english which are documented at http://msdn.microsoft.com/en-us/library/ms190303.aspx
Default value: 'us_english'
nested_triggers
Data type: Optional[Enum['ON', 'OFF']]
On | Off see http://msdn.microsoft.com/en-us/library/ms178101.aspx
Default value: undef
transform_noise_words
Data type: Optional[Enum['ON', 'OFF']]
ON | OFF
Default value: undef
two_digit_year_cutoff
Data type: Integer[1753, 9999]
Defaults to 2049 | <any year between 1753 and 9999>
Default value: 2049
db_chaining
Data type: Enum['ON', 'OFF']
ON | OFF When ON is specified, the database can be the source or target of a cross-database ownership chain. When OFF, the database cannot participate in cross-database ownership chaining. The default is OFF.
Default value: 'OFF'
trustworthy
Data type: Enum['ON', 'OFF']
When ON is specified, database modules that use an impersonation context can access resources outside the database. For example, views, user-defined functions, or stored procedures. When OFF, database modules in an impersonation context cannot access resources outside the database. The default is OFF.
Default value: 'OFF'
sqlserver::login
Requirement/Dependencies: Requires defined type {sqlserver::config} in order to execute against the SQL Server instance
- See also
- Puppet::Parser::Fucntions#sqlserver_validate_instance_name
- http://msdn.microsoft.com/en-us/library/ms186320(v=sql.110).aspx
- Server Role Members
- http://technet.microsoft.com/en-us/library/ms189751(v=sql.110).aspx
- Create Login
- http://technet.microsoft.com/en-us/library/ms189828(v=sql.110).aspx
- Alter Login
Parameters
The following parameters are available in the sqlserver::login
defined type:
login
instance
ensure
password
svrroles
login_type
default_database
default_language
check_expiration
check_policy
disabled
permissions
login
Data type: Any
The SQL or Windows login you would like to manage
Default value: $title
instance
Data type: String[1,16]
The name of the instance which to connect to, instance names can not be longer than 16 characters
Default value: 'MSSQLSERVER'
ensure
Data type: Enum['present', 'absent']
Defaults to 'present', valid values are 'present' | 'absent'
Default value: 'present'
password
Data type: Optional[String]
Plain text password. Only applicable when Login_Type = 'SQL_LOGIN'.
Default value: undef
svrroles
Data type: Optional[Hash]
A hash of preinstalled server roles that you want assigned to this login. sample usage would be { 'diskadmin' => 1, 'dbcreator' => 1, 'sysadmin' => 0, }
Default value: { }
login_type
Data type: Enum['SQL_LOGIN', 'WINDOWS_LOGIN']
Defaults to 'SQL_LOGIN', possible values are 'SQL_LOGIN' or 'WINDOWS_LOGIN'
Default value: 'SQL_LOGIN'
default_database
Data type: String
The database that when connecting the login should default to, the default value is 'master'
Default value: 'master'
default_language
Data type: String
The default language is 'us_english', a list of possible
Default value: 'us_english'
check_expiration
Data type: Boolean
Default value is false, possible values of true | false. Only applicable when Login_Type = 'SQL_LOGIN'.
Default value: false
check_policy
Data type: Boolean
Default value is false, possible values are true | false. Only applicable when Login_Type = 'SQL_LOGIN'.
Default value: true
disabled
Data type: Boolean
Default value is false. Accepts [Boolean] values of true or false.
Default value: false
permissions
Data type: Optional[Hash]
A hash of permissions that should be managed for the login. Valid keys are 'GRANT', 'GRANT_WITH_OPTION', 'DENY' or 'REVOKE'. Valid values must be an array of Strings i.e. {'GRANT' => ['CONNECT SQL', 'CREATE ANY DATABASE'] }
Default value: { }
sqlserver::login::permissions
Requirement/Dependencies: Requires defined type {sqlserver::config} in order to execute against the SQL Server instance
Parameters
The following parameters are available in the sqlserver::login::permissions
defined type:
login
Data type: String[1,128]
The login for which the permission will be manage.
permissions
Data type: Array[String[4,128]]
An array of permissions you would like managed. i.e. ['SELECT', 'INSERT', 'UPDATE', 'DELETE']
state
Data type: Pattern[/(?i)^(GRANT|REVOKE|DENY)$/]
The state you would like the permission in. Accepts 'GRANT', 'DENY', 'REVOKE'. Please note that REVOKE equates to absent and will default to database and system level permissions.
Default value: 'GRANT'
instance
Data type: String[1,16]
The name of the instance where the user and database exists. Defaults to 'MSSQLSERVER'
Default value: 'MSSQLSERVER'
with_grant_option
Data type: Optional[Boolean]
Bolean value that allows user to grant options.
Default value: false
sqlserver::role
Requirement/Dependencies: Requires defined type {sqlserver::config} in order to execute against the SQL Server instance
Parameters
The following parameters are available in the sqlserver::role
defined type:
ensure
Data type: Enum['present', 'absent']
Whether the role should be absent or present
Default value: 'present'
role
Data type: String[1,128]
The name of the role for which the permissions will be manage.
Default value: $title
instance
Data type: String[1,16]
The name of the instance where the role and database exists. Defaults to 'MSSQLSERVER'
Default value: 'MSSQLSERVER'
authorization
Data type: Optional[String]
The database principal that should own the role
Default value: undef
type
Data type: Enum['SERVER', 'DATABASE']
Whether the Role is SERVER
or DATABASE
Default value: 'SERVER'
database
Data type: String[1,128]
The name of the database the role exists on when specifying type => 'DATABASE'
. Defaults to 'master'
Default value: 'master'
permissions
Data type: Optional[Hash]
A hash of permissions that should be managed for the role. Valid keys are 'GRANT', 'GRANT_WITH_OPTION', 'DENY' or 'REVOKE'. Valid values must be an array of Strings i.e. {'GRANT' => ['CONNECT', 'CREATE ANY DATABASE'] }
Default value: { }
members
Data type: Array[String]
An array of users/logins that should be a member of the role
Default value: []
members_purge
Data type: Boolean
Whether we should purge any members not listed in the members parameter. Default: false
Default value: false
sqlserver::role::permissions
Requirement/Dependencies: Requires defined type {sqlserver::config} in order to execute against the SQL Server instance
Parameters
The following parameters are available in the sqlserver::role::permissions
defined type:
role
Data type: String[1,128]
The name of the role for which the permissions will be manage.
permissions
Data type: Array[String[4,128]]
An array of permissions you want manged for the given role
state
Data type: Pattern[/(?i)^(GRANT|REVOKE|DENY)$/]
The state you would like the permission in. Accepts 'GRANT', 'DENY', 'REVOKE'. Please note that REVOKE equates to absent and will default to database and system level permissions.
Default value: 'GRANT'
with_grant_option
Data type: Optional[Boolean]
Whether to give the role the option to grant this permission to other principal objects, accepts true or false, defaults to false
Default value: false
type
Data type: Enum['SERVER','DATABASE']
Whether the Role is SERVER
or DATABASE
Default value: 'SERVER'
database
Data type: String[1,128]
The name of the database the role exists on when specifying type => 'DATABASE'
. Defaults to 'master'
Default value: 'master'
instance
Data type: String[1,16]
The name of the instance where the role and database exists. Defaults to 'MSSQLSERVER'
Default value: 'MSSQLSERVER'
sqlserver::sp_configure
Required Dependencies: Requires defined type {sqlserver::config} in order to execute against the SQL Server instance
@see http://msdn.microsoft.com/en-us/library/ms176069.aspx Reconfigure Explanation @see http://msdn.microsoft.com/en-us/library/ms189631.aspx Server Configuration Options
Parameters
The following parameters are available in the sqlserver::sp_configure
defined type:
config_name
Data type: Pattern['^\w+']
The config name found within sys.configurations that you would like to update
Default value: $title
value
Data type: Integer
The value you would like to change to for the given config_name
, must be an integer value
instance
Data type: String[1,16]
The name of the instance you would like to manage against
Default value: 'MSSQLSERVER'
reconfigure
Data type: Boolean
If you would like to run RECONFIGURE against the server after updating the value, defaults to true
Default value: true
with_override
Data type: Boolean
This pertains tot he reconfigure
in which you would want to override or force the reconfigure, defaults to false
Default value: false
restart
Data type: Boolean
Will ensure service resource and notify if changes occur for a restart
Default value: false
sqlserver::user
Requirement/Dependencies: Requires defined type {sqlserver::config} in order to execute against the SQL Server instance
Examples
sqlserver::user{'myUser':
database => 'loggingDatabase',
login => 'myUser',
}
Parameters
The following parameters are available in the sqlserver::user
defined type:
user
Data type: String[1]
The username you want to manage, defaults to the title
Default value: $title
database
Data type: String[1,128]
The database you want the user to be created as
ensure
Data type: Enum['present', 'absent']
Ensure present or absent
Default value: 'present'
default_schema
Data type: Optional[String]
SQL schema you would like to default to, typically 'dbo'
Default value: undef
instance
Data type: String[1,16]
The named instance you want to manage against
Default value: 'MSSQLSERVER'
login
Data type: Optional[String[1]]
The login to associate the user with, by default SQL Server will assume user and login match if left empty
Default value: undef
password
Data type: Optional[String[1,128]]
The password for the user, can only be used when the database is a contained database.
Default value: undef
permissions
Data type: Optional[Hash]
A hash of permissions that should be managed for the user. Valid keys are 'GRANT', 'GRANT_WITH_OPTION', 'DENY' or 'REVOKE'. Valid values must be an array of Strings i.e. {'GRANT' => ['SELECT', 'INSERT'] }
Default value: { }
sqlserver::user::permissions
Requirement/Dependencies: Requires defined type {sqlserver::config} in order to execute against the SQL Server instance
Parameters
The following parameters are available in the sqlserver::user::permissions
defined type:
user
Data type: String[1,128]
The username for which the permission will be manage.
database
Data type: String[1,128]
The databaser you would like the permission managed on.
Default value: 'master'
permissions
Data type: Array[String[4,128]]
An array of permissions you would like managed. i.e. ['SELECT', 'INSERT', 'UPDATE', 'DELETE']
state
Data type: Pattern[/(?i)^(GRANT|REVOKE|DENY)$/]
The state you would like the permission in. Accepts 'GRANT', 'DENY', 'REVOKE'. Please note that REVOKE equates to absent and will default to database and system level permissions.
Default value: 'GRANT'
with_grant_option
Data type: Optional[Boolean]
Whether to give the user the option to grant this permission to other users, accepts true or false, defaults to false
Default value: false
instance
Data type: String[1,16]
The name of the instance where the user and database exists. Defaults to 'MSSQLSERVER'
Default value: 'MSSQLSERVER'
Resource types
sqlserver_features
Due to our prefetch and unaware of what name the user will provide we munge the value to meet our expecations.
Properties
The following properties are available in the sqlserver_features
type.
ensure
Valid values: present
, absent
The basic property that the resource should be in.
Default value: present
features
Valid values: Tools
, BC
, Conn
, SSMS
, ADV_SSMS
, SDK
, IS
, MDS
, BOL
, DREPLAY_CTLR
, DREPLAY_CLT
, DQC
Specifies features to install, uninstall, or upgrade. The list of top-level features include BC, Conn, SSMS, ADV_SSMS, SDK, IS and MDS.
Parameters
The following parameters are available in the sqlserver_features
type.
install_switches
A hash of switches you want to pass to the installer
is_svc_account
Either domain user name or system account. Defaults to "NT AUTHORITY\NETWORK SERVICE"
is_svc_password
Password for domain user.
name
namevar
Due to our prefetch and unaware of what name the user will provide we munge the value to meet our expecations.
pid
Specify the SQL Server product key to configure which edition you would like to use.
provider
The specific backend to use for this sqlserver_features
resource. You will seldom need to specify this --- Puppet will
usually discover the appropriate provider for your platform.
source
Location of the source files.
windows_feature_source
Specify the location of the Windows Feature source files. This may be needed to install the .Net Framework. See https://support.microsoft.com/en-us/kb/2734782 for more information.
sqlserver_instance
Namevar
Properties
The following properties are available in the sqlserver_instance
type.
ensure
Valid values: present
, absent
The basic property that the resource should be in.
Default value: present
features
Valid values: SQL
, SQLEngine
, Replication
, FullText
, DQ
, AS
, RS
, POLYBASE
, ADVANCEDANALYTICS
Specifies features to install, uninstall, or upgrade. The list of top-level features include SQLEngine, Replication, FullText, DQ AS, and RS.
Parameters
The following parameters are available in the sqlserver_instance
type.
agt_svc_account
agt_svc_password
as_svc_account
as_svc_password
as_sysadmin_accounts
install_switches
name
pid
polybase_svc_account
polybase_svc_password
provider
rs_svc_account
rs_svc_password
sa_pwd
security_mode
source
sql_svc_account
sql_svc_password
sql_sysadmin_accounts
windows_feature_source
agt_svc_account
Either domain user name or system account
agt_svc_password
Password for domain user name. Not required for system account
as_svc_account
The account used by the Analysis Services service.
as_svc_password
The password for the Analysis Services service account.
as_sysadmin_accounts
Specifies the list of administrator accounts to provision.
install_switches
A hash of switches you want to pass to the installer
name
namevar
Namevar
pid
Specify the SQL Server product key to configure which edition you would like to use.
polybase_svc_account
The account used by the Polybase Engine service. Only applicable for SQL Server 2016+.
polybase_svc_password
The password for the Polybase Engine service account. Only applicable for SQL Server 2016+.
provider
The specific backend to use for this sqlserver_instance
resource. You will seldom need to specify this --- Puppet will
usually discover the appropriate provider for your platform.
rs_svc_account
Specify the service account of the report server. This value is required. If you omit this value, Setup will use the default built-in account for the current operating system (either NetworkService or LocalSystem). If you specify a domain user account, the domain must be under 254 characters and the user name must be under 20 characters. The account name cannot contain the following characters: " / \ [ ] : ; | = , + * ? < >
rs_svc_password
Specify a strong password for the account. A strong password is at least 8 characters and includes a combination of upper and lower case alphanumeric characters and at least one symbol character. Avoid spelling an actual word or name that might be listed in a dictionary.
sa_pwd
Required when :security_mode => "SQL"
security_mode
Valid values: SQL
Specifies the security mode for SQL Server. If this parameter is not supplied, then Windows-only authentication mode is supported. Supported value: SQL
source
Location of source files.
sql_svc_account
Account for SQL Server service: Domain\User or system account.
sql_svc_password
A SQL Server service password is required only for a domain account.
sql_sysadmin_accounts
Windows account(s) to provision as SQL Server system administrators.
windows_feature_source
Specify the location of the Windows Feature source files. This may be needed to install the .Net Framework. See https://support.microsoft.com/en-us/kb/2734782 for more information.
sqlserver_tsql
Namevar
Properties
The following properties are available in the sqlserver_tsql
type.
onlyif
SQL Query to run and only run if exits with non-zero
returns
Returns the result of the executed command
Default value: 0
Parameters
The following parameters are available in the sqlserver_tsql
type.
command
command to run against an instance with the authenticated credentials used in sqlserver::config
database
initial database to connect to during query execution
Default value: master
instance
requires the usage of sqlserver::config with the user and password
name
namevar
Namevar
provider
The specific backend to use for this sqlserver_tsql
resource. You will seldom need to specify this --- Puppet will
usually discover the appropriate provider for your platform.
Functions
sqlserver_is_domain_or_local_user
Type: Ruby 3.x API
The sqlserver_is_domain_or_local_user function.
sqlserver_is_domain_or_local_user()
The sqlserver_is_domain_or_local_user function.
Returns: Boolean
Returns true is the username is for local/domain.
sqlserver_upcase
Type: Ruby 3.x API
The sqlserver_upcase function.
sqlserver_upcase()
The sqlserver_upcase function.
Returns: Any
Upcase values
sqlserver_validate_hash_uniq_values
Type: Ruby 3.x API
The sqlserver_validate_hash_uniq_values function.
sqlserver_validate_hash_uniq_values()
The sqlserver_validate_hash_uniq_values function.
Returns: String
Returns the arguments or a message with the duplicate values.
sqlserver_validate_instance_name
Type: Ruby 3.x API
The sqlserver_validate_instance_name function.
sqlserver_validate_instance_name()
The sqlserver_validate_instance_name function.
Returns: Any
Error if not a valid instance name.
sqlserver_validate_range
Type: Ruby 3.x API
The sqlserver_validate_range function.
sqlserver_validate_range()
The sqlserver_validate_range function.
Returns: Any
Error if value is not between range
sqlserver_validate_size
Type: Ruby 3.x API
The sqlserver_validate_size function.
sqlserver_validate_size()
The sqlserver_validate_size function.
Returns: Any
Error if not a valid size value
Tasks
get_sql_logins
Retrieve information about the logins configured for a SQL Server instance.
Supports noop? false
Parameters
instance_name
Data type: Optional[Variant[Array[String], String]]
The name of the SQL Instance running on the machine to connect to. Leave blank for the default instance of MSSQLSERVER
login_name
Data type: Optional[Variant[Array[String], String]]
The name of a particular login to search for. You can use partial names and any pattern that will work with the PowerShell '-match' operator.
exact_match
Data type: Optional[Boolean]
If set to true it will force names passed to the LoginName parameter to be an exact match to a SQL Login to pass the filter.
detailed
Data type: Optional[Boolean]
Return more detailed information from the server instead of the default summary information
get_sqlagent_jobs
Return information about SQL Agent jobs and job steps.
Supports noop? false
Parameters
instance_name
Data type: Optional[Variant[Array[String],String]]
The instance to get job information from
job_name
Data type: Optional[Variant[Array[String],String]]
The name or the pattern to match of the job to search for.
exact_match
Data type: Optional[Boolean]
Use only exact name matches for the job_name parameter instead of the default fuzzy matching.
set_sql_logins
Set IsDisabled, and Password properties of a SQL Login
Supports noop? true
Parameters
instance_name
Data type: Optional[Variant[Array[String],String]]
Instance that has the login to be modified. Leave blank for default instance.
login_name
Data type: Variant[Array[String],String]
Name of the login to modify. Matches are exact only by default.
fuzzy_match
Data type: Optional[Boolean]
Allow -match operator matches on $login_name so that inputs like 'sql' will match any login with 'sql' anywhere in the name.
enabled
Data type: Optional[Boolean]
Enable or disable an account. Set this to false to disable the account.
password
Data type: Optional[String]
The password to set for an account.
start_sql_agent_job
Start SQL Agent jobs on a server. You can start at a specified job step number (zero based indexes), and you can either wait on the job to complete, or return immediately.
Supports noop? false
Parameters
instance_name
Data type: Optional[Variant[Array[String],String]]
The instance to start a job on.
job_name
Data type: Variant[Array[String],String]
The name of the job to start.
fuzzy_match
Data type: Optional[Boolean]
Turn the job_name parameter into a pattern to match using the PowerShell -match operator.
step
Data type: Optional[Integer]
The zero based index number of the jop step to start from. Defaults to zero.
wait
Data type: Optional[Boolean]
Wait for all jobs started to complete before returning data. Defaults to false such that the task will return immediately indicating only that the job was started.
What are tasks?
Modules can contain tasks that take action outside of a desired state managed by Puppet. It’s perfect for troubleshooting or deploying one-off changes, distributing scripts to run across your infrastructure, or automating changes that need to happen in a particular order as part of an application deployment.
Tasks in this module release
Change log
All notable changes to this project will be documented in this file. The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
v3.0.0 (2021-02-27)
Changed
- pdksync - Remove Puppet 5 from testing and bump minimal version to 6.0.0 #369 (carabasdaniel)
Added
- pdksync - (feat) - Add support for Puppet 7 #363 (daianamezdrea)
Fixed
- (FM-8879) Handle T-SQL Errors Properly #349 (RandomNoun7)
- (MODULES-10335) - Update exec's title to be unique #341 (david22swan)
v2.6.2 (2020-01-21)
Fixed
- (MODULES-10384) - Registry value check tightened #343 (david22swan)
v2.6.1 (2020-01-16)
Fixed
- (MODULES-10388) fix missing gem #339 (sheenaajay)
v2.6.0 (2019-10-21)
Added
- Add support for Server 2019 #327 (sanfrancrisko)
v2.5.1
Fixed
- Add DQC to sqlserver_features feature attribute (MODULES-8600)
- Fix sqlserver_instances fact fails when registry contains uninstalled instances (MODULES-8439)
- Switch to using PowerShell
Restart-Service .. -Force
to restart the SQLServer service insqlserver::sp_configure
(MODULES-6904) - Fix ERB Template Errors (MODULES-9912)
2.5.0 - 2019-03-26
Added
- Bolt task to start SQL agent jobs (MODULES-8610).
Fixed
- Missing type declaration for the get_sqlagent_job.json
- Make job_name param required for the start_sql_agent_job task (MODULES-8749)
2.4.0 - 2019-03-12
Added
- Get agent jobs Bolt task (MODULES-8692)
- Get sql logins Bolt task (MODULES-8606)
- Set sql logins Bolt task (MODULES-8606)
Fixed
- Cannot manage a role with the same name on two instances or two databases (MODULES-8677) (Thanks Dylan Ratcliffe)
- Removing a SQL Login via
ensure => absent
in a sqlserver::login resource is not idempotent. (MODULES-8685) (Thanks Dylan Ratcliffe)
2.3.0 - 2019-01-22
Added
- Add support for installing and managing SQL 2019 instances (MODULES-8438)
Changed
- License terms updated to allow a Bolt trial period (License)
Fixed
- .NET 3.5 could be installed in cases where it was not necessary. (MODULES-8438)
- Features were not detected correctly if the registry keys were stored with a value other than 1. (Thanks GrammatonKlaric) (MODULES-7734)
2.2.0 - 2018-12-3
Added
- Convert module for PDK (MODULES-7406)
Changed
- Update support for Puppet version 6. (MODULES-7833)
- Update README_ja_JP.md
- Update stdlib version to 6. (MODULES-7705)
[2.1.1] - 2018-03-14
Added
- Add CONTRIBUTING.md (FM-6605)
Fixed
- Fix problem installing sql instance when an array of SQL Admins are specified. (MODULES-6356)
- Fix AppVeyor OpenSSL bug.(Modsync commit with discussion)
- During acceptance testing, only execute server provisioning steps if there is a server in the hosts array.
- Stop running
gem update bundler
during Travis runs. (MODULES-6339) - The
sqlserver_tsql
resource now returns errors from sql queries properly. (MODULES-6281)
[2.1.0] - 2017-12-8
Added
- Add support for installing and managing SQL 2017 instances. (MODULES-6168)
Changed
- Update documentation to reflect change that adds 2017 support. (MODULES-6244)
[2.0.2] - 2017-12-5
Fixed
- Fix bug where Puppet will not detect existing sql instances properly and attempts to reinstall an instance that already exists (MODULES-6022)
[2.0.1] - 2017-11-15
Changed
- Allow connections over TLS 1.1+ by replacing OLEDB driver with SQL Native Client (MODULES-5693)
- Updated documentation to include 2016 as a supported version of SQL Server
Fixed
- Ensure instances without SQL Engine are discoverable (MODULES-5566)
[2.0.0] - 2017-08-10
Added
- Added more detailed examples to the README
- Updated with Puppet 4 data types (MODULES-5126)
- Added parameters to manage PolyBase (MODULES-5070)
- Added support for Windows Server 2016
- Added test tiering and test mode switcher (FM-5062, FM-6141)
- Make .Net installation errors more obvious (MODULES-5092)
Changed
- Updated metadata for Puppet 5 (MODULES-5144)
Deprecated
- Deprecated the use of
Tools
andSQL
as installation features (MODULES-4257)
Removed
- Removed unsupported Puppet versions from metadata (MODULES-4842)
- Removed support for Stdlib on unsupported Puppet versions, (Stdlib versions less than 4.13.0)
- Removed service_ensure parameter as it had no use (MODULES-5030)
Fixed
- Using as_sysadmin_accounts without AS feature will error (MODULES-2386)
- SNAC_SDK shared feature can not be managed by the module (FM-5389)
- Purge members from SQL Server Role should actually purge (MODULES-2543)
- Identifiers are properly escaped during database creation (FM-5021)
- Removed forced TCP connection for SQL management (MODULES-4915)
[1.2.0] - 2017-05-08
Added
- Added locales directory, config.yaml and POT file for i18n. (MODULES-4334)
- Puppet-module-gems now implemented
Fixed
- Replace Puppet.version comparison with Puppet::Util::Package.versioncmp (MODULES-4528)
- Update beaker tests for Jenkins CI (MODULES-4667)
[1.16] - 2017-03-07
Fixed
- Fix issue where error was raised when adding or removing features if setup.exe returned 1641 (Reboot initiated) or 3010 (Reboot required) exit codes, only a warning is raised now (MODULES-4468).
[1.1.5] - 2017-02-15
Added
- Obfuscate passwords in logs if sqlserver_instance raises an error (MODULES-4255).
Fixed
- Fix issues with installing .Net 3.5 in acceptance tests
- Fix various issues with test environment in AppVeyor, Travis CI and Jenkins
- Fix documentation for localizationb
[1.1.4] - 2016-08-31
Added
- Add
windows_feature_source
parameter to thesqlserver_instance
andsqlserver_features
resources. This specifies the location of the Windows Feature source files, which might be needed to install the .NET Framework. See https://support.microsoft.com/en-us/kb/2734782 for more information (MODULES-3202).
Fixed
- Fix issues when adding multiple SYSADMIN role accounts on instance creation (MODULES-3427).
- Fix issues when creating and deleting Windows base logins (MODULES-3256).
- Fix errors when deleting MS SQL Server logins (MODULES-2323) and databases (MODULES-2554).
- Refactor acceptance tests for
sqlserver::login
resource (MODULES-3256). - Fix issues when modifying server roles for an existing login (MODULES-3083).
- Fix issues when modifying an existing Windows user login (MODULES-3752).
[1.1.3] - 2016-07-12
Added
- Update documentation with a more advanced SQL example.
- Add Windows Based Authentication for
sqlserver::config
. Modifies thesqlserver::config
class with an additional property calledlogin_type
which can be eitherSQL_LOGIN
orWINDOWS_LOGIN
, with a default ofSQL_LOGIN
.
Changed
- Minor refactoring of code which is not used or makes code path more obvious.
Fixed
- Fix Role Name Collisions. This fix introduces the database name into the title created for the
sqlserver_tsql
statements so that it is unique. - Fix TSQL error propagation. Introduce a minor refactor so that the
returns
property captures errors properly from TSQL executions. - Emit debug output on failed
onlyif
TSQL. Previously, there was no way of getting the log output from SQL Server when executing TSQL during anonlyif
.
[1.1.2] - 2016-04-11
Changed
- Update supported Puppet version ranges.
[1.1.1] - 2015-12-08
Changed
- Support newer PE versions.
[1.1.0] - 2015-09-08
Added
sqlserver_instance
andsqlserver_features
have new parameterinstall_switches
, which takes a hash of install switches and writes them to a temporary configuration file for the install process. (FM-2303)- Add define for permissions for Users, Roles, and Logins.
- New
sqlserver_tsql
provider available to execute custom scripts.
Changed
- Remove dependency on 'sqlcmd.exe'. (FM-2577)
sqlserver::config
no longer writes a file to the sytem.- Performance discovery improvements.
Removed
- Remove dependency for ACL modules.
Fixed
- Munge values for instance names to always be uppercase when comparing.
- Change the way we look up logins to use sys.server_principals instead of a function that might not report correctly.
- Fix issue with
collation_name
and databases where the variable was not named properly, causing it to never be set.
[1.0.0] - 2014-12-08
Initial release.
* This Changelog was automatically generated by github_changelog_generator
Dependencies
- puppetlabs/stdlib (>= 4.13.1 < 8.0.0)
- puppetlabs/powershell (>= 1.0.1 < 6.0.0)
This Module is only available for use with (1) the Puppet Enterprise Free License for up to 10 Nodes or as part of a Puppet Enterprise paid license, both subject to the Software License Agreement located at https://puppet.com/legal or other existing valid license agreement between user and Puppet ("Agreement") governing the use of Puppet Enterprise or (2) Puppet Bolt for up to a ninety (90) day period from the date this Module is downloaded, subject to the open source license for Puppet Bolt. With the exception of Puppet Bolt, this Module is not available for users of any other open source Puppet software. Any terms not defined herein shall have the meaning set forth in the Agreement. By downloading this Module, you represent that you have agreed to a valid Agreement for Puppet Enterprise or the applicable open source license for Puppet Bolt and you further agree that your use of the Module is governed by the terms of such Agreement and license, respectively.