-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathmssql-create-db-with-dsc.yml
executable file
·74 lines (70 loc) · 1.96 KB
/
mssql-create-db-with-dsc.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
- name: Create a db on MSSQL using DSC
hosts: all
gather_facts: no
become: no
vars:
db_name: rhdemo1
tasks:
- name: Install required DSC modules
win_psmodule:
name: "{{ item }}"
state: present
loop:
- NetworkingDsc
- SqlServerDsc
- name: create database
win_dsc:
resource_name: SqlScriptQuery
ServerName: localhost
InstanceName: MSSQLServer
Credential_username: sa
Credential_password: '{{ mssql_password }}'
SetQuery: |
CREATE DATABASE ['{{ db_name }}']
TestQuery: |
if (select count(name) from sys.databases where name = '{{ db_name }}') = 0
BEGIN
RAISERROR ('Did not find database [{{ db_name }}]', 16, 1)
END
ELSE
BEGIN
PRINT 'Found database [{{ db_name }}]'
END
GetQuery: |
SELECT Name FROM sys.databases WHERE Name = '{{ db_name }}' FOR JSON AUTO
- name: Open port for MSSQL
win_dsc:
resource_name: Firewall
ensure: Present
name: MSSQL
enabled: True
localport: 1433
action: Allow
direction: Inbound
protocol: TCP
# - name: Set windows connection variables
# set_fact:
# ansible_port: 5986
# ansible_connection: winrm
# ansible_winrm_server_cert_validation: ignore
# delegate_to: 127.0.0.1
#
# - name: Enable port for MSSQL
# win_firewall_rule:
# name: MSSQL
# localport: 1433
# action: allow
# direction: in
# protocol: tcp
# profiles: public
# state: present
# enabled: yes
#
# - name: Create a db
# mssql_db:
# login_host: "{{ ansible_host | default(ansible_ssh_host) | default(inventory_hostname) }}"
# login_user: sa
# login_password: '{{ mssql_password }}'
# name: '{{ db_name }}'
# state: present
# delegate_to: 127.0.0.1