2017-12-13 05:31:00 +01:00
|
|
|
- name: Prepare random number
|
|
|
|
set_fact:
|
2018-09-04 06:30:09 +02:00
|
|
|
random_postfix: "{{ 1000 | random }}{{ resource_group | hash('md5') | truncate(7, True, '') }}"
|
2017-12-13 05:31:00 +01:00
|
|
|
run_once: yes
|
|
|
|
|
|
|
|
- name: Create instance of SQL Server -- check mode
|
|
|
|
azure_rm_sqlserver:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-09-04 06:30:09 +02:00
|
|
|
name: "sqlsrv{{ random_postfix }}"
|
2017-12-13 05:31:00 +01:00
|
|
|
location: eastus
|
|
|
|
admin_username: mylogin
|
|
|
|
admin_password: Testpasswordxyz12!
|
|
|
|
check_mode: yes
|
|
|
|
register: output
|
|
|
|
- name: Assert the resource instance is well created
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed
|
|
|
|
|
|
|
|
- name: Create instance of SQL Server
|
|
|
|
azure_rm_sqlserver:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-09-04 06:30:09 +02:00
|
|
|
name: "sqlsrv{{ random_postfix }}"
|
2017-12-13 05:31:00 +01:00
|
|
|
location: eastus
|
|
|
|
admin_username: mylogin
|
|
|
|
admin_password: Testpasswordxyz12!
|
2018-09-10 09:31:01 +02:00
|
|
|
tags:
|
|
|
|
aaa: bbb
|
2017-12-13 05:31:00 +01:00
|
|
|
register: output
|
|
|
|
- name: Assert the resource instance is well created
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed
|
|
|
|
- output.state == 'Ready'
|
|
|
|
|
|
|
|
- name: Create again instance of SQL Server
|
|
|
|
azure_rm_sqlserver:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-09-04 06:30:09 +02:00
|
|
|
name: "sqlsrv{{ random_postfix }}"
|
2017-12-13 05:31:00 +01:00
|
|
|
location: eastus
|
|
|
|
admin_username: mylogin
|
|
|
|
admin_password: Testpasswordxyz12!
|
|
|
|
register: output
|
|
|
|
- name: Assert the state has not changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed == false
|
|
|
|
- output.state == 'Ready'
|
|
|
|
|
2018-09-04 06:30:09 +02:00
|
|
|
# azure_rm_sqlserver_facts tests
|
|
|
|
|
|
|
|
- name: Gather facts SQL Server
|
|
|
|
azure_rm_sqlserver_facts:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
server_name: "sqlsrv{{ random_postfix }}"
|
|
|
|
register: output
|
|
|
|
- name: Assert that facts are returned
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed == False
|
|
|
|
- output.servers.sqlsrv{{ random_postfix }}.id != None
|
|
|
|
- output.servers.sqlsrv{{ random_postfix }}.name == "sqlsrv{{ random_postfix }}"
|
|
|
|
- output.servers.sqlsrv{{ random_postfix }}.type != None
|
|
|
|
- output.servers.sqlsrv{{ random_postfix }}.location != None
|
|
|
|
- output.servers.sqlsrv{{ random_postfix }}.kind != None
|
|
|
|
- output.servers.sqlsrv{{ random_postfix }}.version != None
|
|
|
|
- output.servers.sqlsrv{{ random_postfix }}.state != None
|
|
|
|
- output.servers.sqlsrv{{ random_postfix }}.fully_qualified_domain_name != None
|
2018-09-10 09:31:01 +02:00
|
|
|
- output.servers.sqlsrv{{ random_postfix }}.tags.aaa == 'bbb'
|
2018-09-04 06:30:09 +02:00
|
|
|
|
|
|
|
- name: Gather facts SQL Server - unexisting
|
|
|
|
azure_rm_sqlserver_facts:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
server_name: "unexisting"
|
|
|
|
register: output
|
|
|
|
- name: Assert that facts are returned
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed == False
|
|
|
|
- output.servers == {}
|
|
|
|
|
|
|
|
- name: Gather facts SQL Server - list
|
|
|
|
azure_rm_sqlserver_facts:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
register: output
|
|
|
|
- name: Assert that facts are returned
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed == False
|
|
|
|
- output.servers.sqlsrv{{ random_postfix }}.id != None
|
|
|
|
- output.servers.sqlsrv{{ random_postfix }}.name == "sqlsrv{{ random_postfix }}"
|
|
|
|
- output.servers.sqlsrv{{ random_postfix }}.type != None
|
|
|
|
- output.servers.sqlsrv{{ random_postfix }}.location != None
|
|
|
|
- output.servers.sqlsrv{{ random_postfix }}.kind != None
|
|
|
|
- output.servers.sqlsrv{{ random_postfix }}.version != None
|
|
|
|
- output.servers.sqlsrv{{ random_postfix }}.state != None
|
|
|
|
- output.servers.sqlsrv{{ random_postfix }}.fully_qualified_domain_name != None
|
|
|
|
|
|
|
|
# azure_rm_sqldatabase tests
|
|
|
|
|
|
|
|
- name: Create instance of SQL Database -- check mode
|
|
|
|
azure_rm_sqldatabase:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
server_name: sqlsrv{{ random_postfix }}
|
|
|
|
name: database{{ random_postfix }}
|
|
|
|
location: eastus
|
|
|
|
check_mode: yes
|
|
|
|
register: output
|
|
|
|
- name: Assert the resource instance is well created
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed
|
|
|
|
|
|
|
|
- name: Create instance of SQL Database
|
|
|
|
azure_rm_sqldatabase:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
server_name: sqlsrv{{ random_postfix }}
|
|
|
|
name: database{{ random_postfix }}
|
|
|
|
location: eastus
|
|
|
|
register: output
|
|
|
|
- name: Assert the resource instance is well created
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed
|
|
|
|
- output.status == 'Online'
|
|
|
|
|
|
|
|
- name: Create again instance of SQL Database
|
|
|
|
azure_rm_sqldatabase:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
server_name: sqlsrv{{ random_postfix }}
|
|
|
|
name: database{{ random_postfix }}
|
|
|
|
location: eastus
|
|
|
|
register: output
|
|
|
|
- name: Assert the state has not changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed == false
|
|
|
|
- output.status == 'Online'
|
|
|
|
|
|
|
|
- name: Delete instance of SQL Database -- check mode
|
|
|
|
azure_rm_sqldatabase:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
server_name: sqlsrv{{ random_postfix }}
|
|
|
|
name: database{{ random_postfix }}
|
|
|
|
state: absent
|
|
|
|
check_mode: yes
|
|
|
|
register: output
|
|
|
|
- name: Assert the state has changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed
|
|
|
|
|
|
|
|
- name: Delete instance of SQL Database
|
|
|
|
azure_rm_sqldatabase:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
server_name: sqlsrv{{ random_postfix }}
|
|
|
|
name: database{{ random_postfix }}
|
|
|
|
state: absent
|
|
|
|
register: output
|
|
|
|
- name: Assert the state has changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed
|
|
|
|
|
|
|
|
- name: Delete unexisting instance of SQL Database
|
|
|
|
azure_rm_sqldatabase:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
server_name: sqlsrv{{ random_postfix }}
|
|
|
|
name: database{{ random_postfix }}
|
|
|
|
state: absent
|
|
|
|
register: output
|
|
|
|
- name: Assert the state has changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed == false
|
|
|
|
|
|
|
|
# azure_rm_sqlfirewallrule tests
|
|
|
|
|
|
|
|
- name: Create instance of Firewall Rule -- check mode
|
|
|
|
azure_rm_sqlfirewallrule:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
server_name: "sqlsrv{{ random_postfix }}"
|
|
|
|
name: firewallrule{{ random_postfix }}
|
|
|
|
start_ip_address: 172.28.10.136
|
|
|
|
end_ip_address: 172.28.10.138
|
|
|
|
check_mode: yes
|
|
|
|
register: output
|
|
|
|
- name: Assert the resource instance is well created
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed
|
|
|
|
|
|
|
|
- name: Create instance of Firewall Rule
|
|
|
|
azure_rm_sqlfirewallrule:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
server_name: "sqlsrv{{ random_postfix }}"
|
|
|
|
name: firewallrule{{ random_postfix }}
|
|
|
|
start_ip_address: 172.28.10.136
|
|
|
|
end_ip_address: 172.28.10.138
|
|
|
|
register: output
|
|
|
|
- name: Assert the resource instance is well created
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed
|
|
|
|
|
|
|
|
- name: Create again instance of Firewall Rule
|
|
|
|
azure_rm_sqlfirewallrule:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
server_name: "sqlsrv{{ random_postfix }}"
|
|
|
|
name: firewallrule{{ random_postfix }}
|
|
|
|
start_ip_address: 172.28.10.136
|
|
|
|
end_ip_address: 172.28.10.138
|
|
|
|
register: output
|
|
|
|
- name: Assert the state has not changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed == false
|
|
|
|
|
2018-09-13 11:54:58 +02:00
|
|
|
#
|
|
|
|
# azure_rm_sqlserverfirewallrule_facts
|
|
|
|
#
|
|
|
|
|
|
|
|
- name: Create Firewall Rule - second
|
2018-09-04 06:30:09 +02:00
|
|
|
azure_rm_sqlfirewallrule:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-09-13 11:54:58 +02:00
|
|
|
server_name: sqlsrv{{ random_postfix }}
|
|
|
|
name: firewallrule{{ random_postfix }}second
|
|
|
|
start_ip_address: 172.28.10.136
|
|
|
|
end_ip_address: 172.28.10.138
|
|
|
|
|
|
|
|
- name: Gather facts SQL Firewall Rule
|
|
|
|
azure_rm_sqlfirewallrule_facts:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
server_name: sqlsrv{{ random_postfix }}
|
2018-09-04 06:30:09 +02:00
|
|
|
name: firewallrule{{ random_postfix }}
|
|
|
|
register: output
|
2018-09-13 11:54:58 +02:00
|
|
|
- name: Assert that facts are returned
|
2018-09-04 06:30:09 +02:00
|
|
|
assert:
|
|
|
|
that:
|
2018-09-13 11:54:58 +02:00
|
|
|
- output.changed == False
|
|
|
|
- output.rules[0].id != None
|
|
|
|
- output.rules[0].resource_group != None
|
|
|
|
- output.rules[0].server_name != None
|
|
|
|
- output.rules[0].name != None
|
|
|
|
- output.rules[0].start_ip_address != None
|
|
|
|
- output.rules[0].end_ip_address != None
|
2018-09-04 06:30:09 +02:00
|
|
|
|
2018-09-13 11:54:58 +02:00
|
|
|
- name: Gather facts SQL Firewall Rule
|
|
|
|
azure_rm_sqlfirewallrule_facts:
|
2018-09-04 06:30:09 +02:00
|
|
|
resource_group: "{{ resource_group }}"
|
2018-09-13 11:54:58 +02:00
|
|
|
server_name: sqlsrv{{ random_postfix }}
|
2018-09-04 06:30:09 +02:00
|
|
|
register: output
|
2018-09-13 11:54:58 +02:00
|
|
|
- name: Assert that facts are returned
|
2018-09-04 06:30:09 +02:00
|
|
|
assert:
|
|
|
|
that:
|
2018-09-13 11:54:58 +02:00
|
|
|
- output.changed == False
|
|
|
|
- output.rules[0].id != None
|
|
|
|
- output.rules[0].id != None
|
|
|
|
- output.rules[0].resource_group != None
|
|
|
|
- output.rules[0].server_name != None
|
|
|
|
- output.rules[0].name != None
|
|
|
|
- output.rules[0].start_ip_address != None
|
|
|
|
- output.rules[0].end_ip_address != None
|
|
|
|
- output.rules[1].id != None
|
|
|
|
- output.rules[1].resource_group != None
|
|
|
|
- output.rules[1].server_name != None
|
|
|
|
- output.rules[1].name != None
|
|
|
|
- output.rules[1].start_ip_address != None
|
|
|
|
- output.rules[1].end_ip_address != None
|
2018-09-04 06:30:09 +02:00
|
|
|
|
2018-09-13 11:54:58 +02:00
|
|
|
- name: Delete instance of Firewall Rule
|
2018-09-04 06:30:09 +02:00
|
|
|
azure_rm_sqlfirewallrule:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-09-13 11:54:58 +02:00
|
|
|
server_name: sqlsrv{{ random_postfix }}
|
2018-09-04 06:30:09 +02:00
|
|
|
name: firewallrule{{ random_postfix }}
|
|
|
|
state: absent
|
2018-09-13 11:54:58 +02:00
|
|
|
- name: Delete instance of Firewall Rule
|
|
|
|
azure_rm_sqlfirewallrule:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
server_name: sqlsrv{{ random_postfix }}
|
|
|
|
name: firewallrule{{ random_postfix }}second
|
|
|
|
state: absent
|
|
|
|
|
|
|
|
- name: Gather facts SQL Firewall Rule
|
|
|
|
azure_rm_sqlfirewallrule_facts:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
server_name: sqlsrv{{ random_postfix }}
|
|
|
|
name: firewallrule{{ random_postfix }}
|
2018-09-04 06:30:09 +02:00
|
|
|
register: output
|
2018-09-13 11:54:58 +02:00
|
|
|
- name: Assert that empty dictionary was returned
|
2018-09-04 06:30:09 +02:00
|
|
|
assert:
|
|
|
|
that:
|
2018-09-13 11:54:58 +02:00
|
|
|
- output.changed == False
|
|
|
|
- output.rules | length == 0
|
2018-09-04 06:30:09 +02:00
|
|
|
|
|
|
|
# finalise & clean up azure_rm_sqlserver test
|
|
|
|
|
2017-12-13 05:31:00 +01:00
|
|
|
- name: Delete instance of SQL Server -- check mode
|
|
|
|
azure_rm_sqlserver:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-09-04 06:30:09 +02:00
|
|
|
name: "sqlsrv{{ random_postfix }}"
|
2017-12-13 05:31:00 +01:00
|
|
|
state: absent
|
|
|
|
check_mode: yes
|
|
|
|
register: output
|
|
|
|
- name: Assert the state has changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed
|
|
|
|
|
|
|
|
- name: Delete instance of SQL Server
|
|
|
|
azure_rm_sqlserver:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-09-04 06:30:09 +02:00
|
|
|
name: "sqlsrv{{ random_postfix }}"
|
2017-12-13 05:31:00 +01:00
|
|
|
state: absent
|
|
|
|
register: output
|
|
|
|
- name: Assert the state has changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed
|
|
|
|
|
|
|
|
- name: Delete unexisting instance of SQL Server
|
|
|
|
azure_rm_sqlserver:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-09-04 06:30:09 +02:00
|
|
|
name: "sqlsrv{{ random_postfix }}"
|
2017-12-13 05:31:00 +01:00
|
|
|
state: absent
|
|
|
|
register: output
|
|
|
|
- name: Assert the state has changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed == false
|