generated from linux-system-roles/template
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up database replication without pacemaker
TODO: Add mssql_ha_reset_cert Add idempotency to all templates
- Loading branch information
Showing
20 changed files
with
968 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# SPDX-License-Identifier: MIT | ||
# This task files inputs sql file into MSSQL. | ||
# If you feed a file with .j2 extension, it generates a template from it. | ||
# If you feed a file with other extension, it just copies the file and runs it. | ||
--- | ||
- name: Verify that the mssql_password variable is defined | ||
assert: | ||
that: | ||
- mssql_password is not none | ||
fail_msg: >- | ||
You must define the mssql_password variable because MSSQL requires | ||
the sa user to authenticate to input SQL files. | ||
- name: Input {{ __mssql_input_sql_file }} to MSSQL | ||
block: | ||
# changed_when: false for idempotency because the file is always removed | ||
- name: Create a tempfile for the SQL file on the host | ||
tempfile: | ||
state: file | ||
register: __mssql_sql_tempfile | ||
changed_when: false | ||
|
||
# changed_when: false for idempotency because the file is always removed | ||
- name: Copy the {{ __mssql_input_sql_file }} file to the host | ||
copy: | ||
src: "{{ __mssql_input_sql_file }}" | ||
dest: "{{ __mssql_sql_tempfile.path }}" | ||
mode: preserve | ||
when: __mssql_input_sql_file is not search(".*\.j2") | ||
changed_when: false | ||
|
||
# changed_when: false for idempotency because the file is always removed | ||
- name: Generate the {{ __mssql_input_sql_file }} template on the host | ||
template: | ||
src: "{{ __mssql_input_sql_file }}" | ||
dest: "{{ __mssql_sql_tempfile.path }}" | ||
when: __mssql_input_sql_file is search(".*\.j2") | ||
changed_when: false | ||
|
||
- name: Ensure that the mssql-server service is started | ||
service: | ||
name: mssql-server | ||
state: started | ||
|
||
- name: Prepare MSSQL and facts for logging in | ||
include_tasks: verify_password.yml | ||
vars: | ||
__mssql_password: "{{ mssql_password }}" | ||
when: __mssql_sqlcmd_login_cmd is none | ||
|
||
- name: Input {{ __mssql_input_sql_file }} with the sqlcmd command | ||
command: >- | ||
{{ __mssql_sqlcmd_login_cmd }} -i {{ __mssql_sql_tempfile.path }} -b | ||
register: __mssql_sqlcmd_input_file | ||
changed_when: '"successfully" in __mssql_sqlcmd_input_file.stdout' | ||
|
||
always: | ||
- name: Print the output of the sqlcmd command if not empty | ||
debug: | ||
var: __mssql_sqlcmd_input_file.stdout_lines | ||
changed_when: false | ||
|
||
- name: Unset the __mssql_sqlcmd_input_file variable | ||
set_fact: | ||
__mssql_sqlcmd_input_file: "" | ||
|
||
#- name: Remove the tempfile | ||
# file: | ||
# path: "{{ __mssql_sql_tempfile.path }}" | ||
# state: absent |
Oops, something went wrong.