How I can pass a variable from the playbook and it will be used powershell script in a remote host? My playbook sample is:
- name: SQL Configuration
script: files/sql-config.ps1
sql-config.ps1 execute on remote server and connect to SQL with $sql_pass. I don't want to store the pass in the ps1 script for obvious reasons, so I'm trying to figure out how I can pass the value for $sql_pass directly from ansible.
I've tried to set up a the variable directly within vars: directory in the playbook but the remote server didn't received the variable so the script failed.
Thanks in advance.
答案 0 :(得分:2)
当然,在你的sql-config.ps1中,首先需要:
IF NOT EXISTS (select col1 from Table1 where SomeId=@SomeId)
INSERT INTO Table1 values (@SomeId,...)
IF NOT EXISTS (select col1 from Table2 where SomeId=@SomeId)
INSERT INTO Table2 values (@SomeId,...)
然后,从您的剧本中,调用脚本,如:
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
BEGIN TRAN
IF NOT EXISTS (SELECT col1 FROM Table1 WITH (UPDLOCK) WHERE SomeId=@SomeId)
INSERT INTO Table1 VALUES (@SomeId,...)
COMMIT TRAN
BEGIN TRAN
IF NOT EXISTS (SELECT col1 FROM Table2 WITH (UPDLOCK) WHERE SomeId=@SomeId)
INSERT INTO Table2 VALUES (@SomeId,...)
COMMIT TRAN
将您的密码保存在ansible-vault下作为变量: