We are using ansible vault to create logins on SQL Server. Vault does not seem to be drop the database role gracefully when the revocation statements are specified as below
creation_statements: ["{% raw %} CREATE LOGIN [{{name}}] WITH PASSWORD = ‘{{password}}’; {% endraw %}
USE [{{ item.database }}];
{% raw %} CREATE USER [{{name}}] FOR LOGIN [{{name}}];{% endraw %}
GRANT {{ item.permission}} ON SCHEMA :: {{ item.schema }} {% raw %} TO [{{name}}]; {% endraw %}"]
revocation_statements: [“USE [{{ item.database }}];
{% raw %} DROP USER [{{name}}];
DROP LOGIN [{{name}}];{% endraw %}”]
token_ttl: “{{ item.token_ttl }}”
with_items:
- “{{ vault_config_sql_server }}”
The login is dropped from sql server but the database user still exists.
When the Revoacation statement is completely omitted,
Successfully dropped login and db user - Only When the Vault root user is sysadmin
Disabled the login and orphan db user still exists - When the Vault root user is not sysadmin
Ideally, we do not want the Vault root user to be sysadmin on the SQL Server.
Any way to fix this problem?