Hello All,

I am trying to create a new database on sql server using the below
mentioned ansible playbook.

But when I am executing the playbook and in the prompt option putting the
database name.

It is not taking that database name of the prompt and instead creating the
database mentioned in the SQL query (in this case creating database TestDB).

So needed help in how I can create the database dynamically by putting the
Database name in the prompt option.

---
 - hosts: SQLSERVER
   vars_prompt:
     - name: DB Config
       prompt: DbName
       default:
   tasks:
     - name: DB config
       win_shell: |
          $sql = "DECLARE @Query VARCHAR(MAX)=''
                  DECLARE @DbName VARCHAR(400) = 'TestDB'
                  DECLARE @DbFilePath VARCHAR(400) = 'E:\Database\'
                  SET @Query = @Query + 'CREATE DATABASE '+@DbName +' ON
 PRIMARY '
                  SET @Query = @Query + '( NAME = '''+@DbName +''',
FILENAME = '''+@DbFilePath+@DbName +'.mdf'' , SIZE = 3072KB , MAXSIZE =
UNLIMITED, FILEGROWTH = 1024KB ) '
                  SET @Query = @Query + ' LOG ON '
                  SET @Query = @Query + '( NAME = '''+@DbName +'_log'',
FILENAME = '''+@DbFilePath+@DbName +'_log.ldf'' , SIZE = 1024KB , MAXSIZE =
2048GB , FILEGROWTH = 10%)'
                  print @query
                  exec(@query)"
                  Invoke-SqlCmd -Query $sql

Thanks and Regards,
Praveen Singh

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAJK1W%3Dy%2Bpv-z46b3LjmPev2qMHHVkmr%2B5nPm4sT_08e3C85R%2Bw%40mail.gmail.com.

Reply via email to