{"id":15022730,"url":"https://github.com/puppetlabs/puppetlabs-sqlserver","last_synced_at":"2025-04-06T02:10:43.313Z","repository":{"id":17879364,"uuid":"20821283","full_name":"puppetlabs/puppetlabs-sqlserver","owner":"puppetlabs","description":"PE-only Microsoft SQL module","archived":false,"fork":false,"pushed_at":"2025-02-18T07:24:55.000Z","size":1324,"stargazers_count":5,"open_issues_count":5,"forks_count":21,"subscribers_count":121,"default_branch":"main","last_synced_at":"2025-03-30T01:11:15.497Z","etag":null,"topics":["hacktoberfest","module","supported"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/puppetlabs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-06-14T00:05:15.000Z","updated_at":"2025-02-18T07:24:11.000Z","dependencies_parsed_at":"2024-12-30T05:20:19.556Z","dependency_job_id":"83da9415-996a-466d-8ed5-a9c49ddab3d0","html_url":"https://github.com/puppetlabs/puppetlabs-sqlserver","commit_stats":{"total_commits":617,"total_committers":58,"mean_commits":"10.637931034482758","dds":0.7698541329011346,"last_synced_commit":"380482befb9cd66ba71490dde50a4d8697dc7251"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puppetlabs%2Fpuppetlabs-sqlserver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puppetlabs%2Fpuppetlabs-sqlserver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puppetlabs%2Fpuppetlabs-sqlserver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puppetlabs%2Fpuppetlabs-sqlserver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/puppetlabs","download_url":"https://codeload.github.com/puppetlabs/puppetlabs-sqlserver/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247423515,"owners_count":20936626,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","module","supported"],"created_at":"2024-09-24T19:58:19.482Z","updated_at":"2025-04-06T02:10:43.258Z","avatar_url":"https://github.com/puppetlabs.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sqlserver\n\n#### Table of contents\n\n1. [Overview](#overview)\n2. [Module Description - What the module does and why it is useful](#module-description)\n3. [Setup - The basics of getting started with sqlserver](#setup)\n    * [Setup requirements](#setup-requirements)\n    * [Beginning with sqlserver](#beginning-with-sqlserver)\n4. [Usage - Configuration options and additional functionality](#usage)\n    * [Install SQL Server tools and features](#install-sql-server-tools-and-features-not-specific-to-a-sql-server-instance)\n    * [Create a new database](#create-a-new-database-on-an-instance-of-sql-server)\n    * [Set up a new login](#set-up-a-new-login)\n    * [Create a new login and a user](#create-a-new-login-and-a-user-for-a-given-database)\n    * [Manage the user's permissions](#manage-the-above-users-permissions)\n    * [Run custom TSQL statements](#run-custom-tsql-statements)\n5. [Reference - An under-the-hood peek at what the module is doing and how](#reference)\n6. [Limitations - OS compatibility, etc.](#limitations)\n7. [License](#license)\n8. [Development - Guide for contributing to the module](#development)\n\n## Overview\n\nThe sqlserver module installs and manages Microsoft SQL Server 2014, 2016, 2017, 2019 and 2022 on Windows systems.\n\n## Module Description\n\nMicrosoft 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.\n\n## Setup\n\n### Setup Requirements\n\nThe sqlserver module requires the following:\n\n* .NET 3.5. (Installed automatically if not present. This might require an internet connection.)\n* The contents of the SQL Server ISO file, mounted or extracted either locally or on a network share.\n* Windows Server 2012+.\n\n### Beginning with sqlserver\n\nTo get started with the sqlserver module, include in your manifest:\n\n```puppet\nsqlserver_instance{ 'MSSQLSERVER':\n    features                =\u003e ['SQL'],\n    source                  =\u003e 'E:/',\n    sql_sysadmin_accounts   =\u003e ['myuser'],\n}\n```\n\nThis 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'.\n\nA more advanced configuration, including installer switches:\n\n```puppet\nsqlserver_instance{ 'MSSQLSERVER':\n  source                  =\u003e 'E:/',\n  features                =\u003e ['SQL'],\n  security_mode           =\u003e 'SQL',\n  sa_pwd                  =\u003e 'p@ssw0rd!!',\n  sql_sysadmin_accounts   =\u003e ['myuser'],\n  install_switches        =\u003e {\n    'TCPENABLED'          =\u003e 1,\n    'SQLBACKUPDIR'        =\u003e 'C:\\\\MSSQLSERVER\\\\backupdir',\n    'SQLTEMPDBDIR'        =\u003e 'C:\\\\MSSQLSERVER\\\\tempdbdir',\n    'INSTALLSQLDATADIR'   =\u003e 'C:\\\\MSSQLSERVER\\\\datadir',\n    'INSTANCEDIR'         =\u003e 'C:\\\\Program Files\\\\Microsoft SQL Server',\n    'INSTALLSHAREDDIR'    =\u003e 'C:\\\\Program Files\\\\Microsoft SQL Server',\n    'INSTALLSHAREDWOWDIR' =\u003e 'C:\\\\Program Files (x86)\\\\Microsoft SQL Server',\n  }\n}\n```\n\nThis 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.\n\n## Usage\n\n**Note**: For clarification on Microsoft SQL Server terminology, please see [Microsoft SQL Server Terms](#microsoft-sql-server-terms) below.\n\n### Install SQL Server tools and features not specific to a SQL Server instance\n\n```puppet\nsqlserver_features { 'Generic Features':\n  source   =\u003e 'E:/',\n  features =\u003e ['BC', 'Conn', 'SDK'],\n}\n```\n\n### Create a new database on an instance of SQL Server\n\n```puppet\nsqlserver::database{ 'minviable':\n  instance =\u003e 'MSSQLSERVER',\n}\n```\n\n### Set up a new login\n\n```puppet\nSQL Login\nsqlserver::login{ 'vagrant':\n  instance =\u003e 'MSSQLSERVER',\n  password =\u003e 'Pupp3t1@',\n}\n\n# Windows Login\nsqlserver::login{ 'WIN-D95P1A3V103\\localAccount':\n  instance   =\u003e 'MSSQLSERVER',\n  login_type =\u003e 'WINDOWS_LOGIN',\n}\n```\n\n### Create a new login and a user for a given database\n\n```puppet\nsqlserver::login{ 'loggingUser':\n  password =\u003e 'Pupp3t1@',\n}\n\nsqlserver::user{ 'rp_logging-loggingUser':\n  user     =\u003e 'loggingUser',\n  database =\u003e 'rp_logging',\n  require  =\u003e Sqlserver::Login['loggingUser'],\n}\n```\n\n### Manage the above user's permissions\n\n```puppet\nsqlserver::user::permissions{'INSERT-loggingUser-On-rp_logging':\n    user        =\u003e 'loggingUser',\n    database    =\u003e 'rp_logging',\n    permissions =\u003e 'INSERT',\n    require     =\u003e Sqlserver::User['rp_logging-loggingUser'],\n}\n\nsqlserver::user::permissions{ 'Deny the Update as we should only insert':\n  user        =\u003e 'loggingUser',\n  database    =\u003e 'rp_logging',\n  permissions =\u003e 'UPDATE',\n  state       =\u003e 'DENY',\n  require     =\u003e Sqlserver::User['rp_logging-loggingUser'],\n}\n```\n\n### Run custom TSQL statements\n\n#### Use `sqlserver_tsql` to trigger other classes or defined types\n\n```puppet\nsqlserver_tsql{ 'Query Logging DB Status':\n  instance =\u003e 'MSSQLSERVER',\n  onlyif   =\u003e \"IF (SELECT count(*) FROM myDb.dbo.logging_table WHERE\n      message like 'FATAL%') \u003e 1000  THROW 50000, 'Fatal Exceptions in Logging', 10\",\n  notify   =\u003e Exec['Too Many Fatal Errors']\n}\n```\n\n#### Clean up regular logs with conditional checks\n\n```puppet\nsqlserver_tsql{ 'Cleanup Old Logs':\n  instance =\u003e 'MSSQLSERVER',\n  command  =\u003e \"DELETE FROM myDb.dbo.logging_table WHERE log_date \u003c '${log_max_date}'\",\n  onlyif   =\u003e \"IF exists(SELECT * FROM myDb.dbo.logging_table WHERE log_date \u003c '${log_max_date}')\n      THROW 50000, 'need log cleanup', 10\",\n}\n```\n\n#### If you want your statement to always execute, leave out the `onlyif` parameter\n\n```puppet\nsqlserver_tsql{ 'Always running':\n  instance =\u003e 'MSSQLSERVER',\n  command  =\u003e 'EXEC notified_executor()',\n}\n```\n\n### Advanced example\n\nThis advanced example:\n\n* Installs the basic SQL Server Engine from installation media mounted at 'D:\\' with TCP Enabled and various directories set.\n\n* 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.\n\n* 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.\n\n* 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.\n\n* Ensures that the advanced options for `sp_configure` are enabled, so that Puppet can manage the `max memory` setting for the instance.\n\n* Ensure that the `max memory` (MB) configuration item is set to 2048 megabytes.\n\n```puppet\n$sourceloc = 'D:/'\n\n# Install a SQL Server default instance\nsqlserver_instance{'MSSQLSERVER':\n  source                =\u003e $sourceloc,\n  features              =\u003e ['SQLEngine'],\n  sql_sysadmin_accounts =\u003e [$facts['id']],\n  install_switches      =\u003e {\n    'TCPENABLED'          =\u003e 1,\n    'SQLBACKUPDIR'        =\u003e 'C:\\\\MSSQLSERVER\\\\backupdir',\n    'SQLTEMPDBDIR'        =\u003e 'C:\\\\MSSQLSERVER\\\\tempdbdir',\n    'INSTALLSQLDATADIR'   =\u003e 'C:\\\\MSSQLSERVER\\\\datadir',\n    'INSTANCEDIR'         =\u003e 'C:\\\\Program Files\\\\Microsoft SQL Server',\n    'INSTALLSHAREDDIR'    =\u003e 'C:\\\\Program Files\\\\Microsoft SQL Server',\n    'INSTALLSHAREDWOWDIR' =\u003e 'C:\\\\Program Files (x86)\\\\Microsoft SQL Server'\n  }\n}\n\n# Resource to connect to the DB instance\nsqlserver::config { 'MSSQLSERVER':\n  admin_login_type =\u003e 'WINDOWS_LOGIN'\n}\n\n# Enforce SQL Server Administrators\n$local_dba_group_name = 'DB Administrators'\n$local_dba_group_netbios_name = \"${facts['hostname']}\\\\DB Administrators\"\n\ngroup { $local_dba_group_name:\n  ensure =\u003e present\n}\n\n-\u003e sqlserver::login { $local_dba_group_netbios_name :\n  login_type  =\u003e 'WINDOWS_LOGIN',\n}\n\n-\u003e sqlserver::role { 'sysadmin':\n  ensure   =\u003e 'present',\n  instance =\u003e 'MSSQLSERVER',\n  type     =\u003e 'SERVER',\n  members  =\u003e [$local_dba_group_netbios_name, $facts['id']],\n}\n\n# Enforce memory consumption\nsqlserver_tsql {'check advanced sp_configure':\n  command =\u003e 'EXEC sp_configure \\'show advanced option\\', \\'1\\'; RECONFIGURE;',\n  onlyif =\u003e 'sp_configure @configname=\\'max server memory (MB)\\'',\n  instance =\u003e 'MSSQLSERVER'\n}\n\n-\u003e sqlserver::sp_configure { 'MSSQLSERVER-max memory':\n  config_name =\u003e 'max server memory (MB)',\n  instance =\u003e 'MSSQLSERVER',\n  reconfigure =\u003e true,\n  restart =\u003e true,\n  value =\u003e 2048\n}\n```\n*Note:*\n$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:\n\n```puppet\n$netbios_name = split($facts['domain'],'\\.')[0]\n\n$dba_group_netbios_name = \"${netbios_name}\\\\DB Administrators\"\n\nsqlserver::role { 'sysadmin':\n  ensure   =\u003e 'present',\n  instance =\u003e 'MSSQLSERVER',\n  type     =\u003e 'SERVER',\n  members  =\u003e [$dba_group_netbios_name, $facts['id']],\n}\n```\n\n## Reference\n\nFor information on the classes and types, see the [REFERENCE.md](https://github.com/puppetlabs/puppetlabs-sqlserver/blob/main/REFERENCE.md)\n\n## Limitations\n\nSQL 2017, 2019 and 2022 detection support has been added. This support is limited to functionality already present for other versions.\n\nThe MSOLEDBSQL driver is now required to use this module. You can use this chocolatey [package](https://community.chocolatey.org/packages/msoledbsql) for installation. but it must version 18.x or earlier. (v19+ is not currently supported)\n\nThis module can manage only a single version of SQL Server on a given host (one and only one of SQL Server 2014, 2016, 2017, 2019 or 2022). The module is able to manage multiple SQL Server instances of the same version.\n\nThis 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.\n\nIn 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](https://chocolatey.org/packages/sql-server-management-studio). 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](https://forge.puppet.com/puppetlabs/chocolatey) to manage SSMS installation.\n\n## License\n\nThis codebase is licensed under the Apache2.0 licensing, however due to the nature of the codebase the open source dependencies may also use a combination of [AGPL](https://opensource.org/license/agpl-v3/), [BSD-2](https://opensource.org/license/bsd-2-clause/), [BSD-3](https://opensource.org/license/bsd-3-clause/), [GPL2.0](https://opensource.org/license/gpl-2-0/), [LGPL](https://opensource.org/license/lgpl-3-0/), [MIT](https://opensource.org/license/mit/) and [MPL](https://opensource.org/license/mpl-2-0/) Licensing.\n\n## Development\n\nThis module was built by Puppet specifically for use with Puppet Enterprise (PE).\n\nIf you run into an issue with this module, or if you would like to request a feature, please [file a ticket](https://tickets.puppet.com/browse/MODULES/).\n\nIf you have problems getting this module up and running, please [contact Support](https://puppet.com/support-services/customer-support).\n\nIf you would like to contribute to this module, please follow the rules in the [CONTRIBUTING.md](https://github.com/puppetlabs/puppetlabs-sqlserver/blob/master/CONTRIBUTING.md). For more information, see our [module contribution guide.](https://puppet.com/docs/puppet/latest/contributing.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpuppetlabs%2Fpuppetlabs-sqlserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpuppetlabs%2Fpuppetlabs-sqlserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpuppetlabs%2Fpuppetlabs-sqlserver/lists"}