lowlydba.sqlserver.user module – Configures a user within a database

Note

This module is part of the lowlydba.sqlserver collection (version 3.1.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install lowlydba.sqlserver. You need further requirements to be able to use this module, see Requirements for details.

To use it in a playbook, specify: lowlydba.sqlserver.user.

New in lowlydba.sqlserver 1.1.0

Synopsis

  • Creates, modifies, or removes a user in a database.

Requirements

The below requirements are needed on the host that executes this module.

Parameters

Parameter

Comments

database

string / required

Database for the user.

default_schema

string

The default database schema for the user.

Default: "dbo"

external_provider

boolean

Specifies that the user is for Azure AD Authentication. Only used when creating a new user, this cannot be modified for an existing user.

Choices:

  • false

  • true

login

string / required

Name of the login that the user is mapped to.

sql_instance

string / required

The SQL Server instance to modify.

sql_password

string

Password for SQL Authentication.

sql_username

string

Username for SQL Authentication.

state

string

Whether or not the object should be present or absent.

Choices:

  • "present" ← (default)

  • "absent"

username

string / required

Name of the user.

Attributes

Attribute

Support

Description

check_mode

Support: full

Can run in check_mode and return changed status prediction without modifying target.

platform

Platforms: all

Target OS/families that can be operated against.

Examples

- name: Create a database user
  lowlydba.sqlserver.user:
    sql_instance: sql01.example.com
    login: app_login
    username: app_user
    database: AppDb

- name: Set a database user's default schema
  lowlydba.sqlserver.user:
    sql_instance: sql01.example.com
    login: app_login
    username: app_user
    database: AppDb
    default_schema: dev

- name: Remove a user
  lowlydba.sqlserver.user:
    sql_instance: sql01.example.com
    login: app_login
    username: app_user
    database: AppDb
    state: absent

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

data

dictionary

Output from the New-DbaDbUser, Get-DbaDbUser, or Remove-DbaDbUser function.

Returned: success, but not in check_mode.

Authors

  • John McCall (@lowlydba)