-
-
Save rterbush/9719d2280d19eb95d583 to your computer and use it in GitHub Desktop.
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
apply_script_01: | |
cmd.run: | |
- name: ' | |
invoke-sqlcmd -inputfile "c:\\temp\\01_script.sql"' | |
- shell: powershell | |
- creates: 'c:\\var\\salt\\state\\_01_script.txt' | |
script_01_complete: | |
file.touch: | |
- name: 'c:\\var\\salt\\state\\_01_script.txt' | |
- require: | |
- cmd: apply_script_01 | |
apply_script_02: | |
cmd.run: | |
- name: ' | |
invoke-sqlcmd -inputfile "c:\\temp\\02_script.sql"' | |
- shell: powershell | |
- creates: 'c:\\var\\salt\\state\\_02_script.txt' | |
- require: | |
- cmd: apply_script_01 | |
script_02_complete: | |
file.touch: | |
- name: 'c:\\var\\salt\\state\\_02_script.txt' | |
- require: | |
- cmd: apply_script_02 |
@rterbush, here is an example using a powershell try
block with -ErrorAction Stop
with cmd.run and stateful: True
:
{%- set join_domain = salt['pillar.get']('join-domain:windows', {}) %}
{%- if join_domain %}
join standalone system to domain:
cmd.run:
- name: '
try
{
$domain = ([System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain()).Name;
"changed=no comment=`"System is joined already to a domain [$domain].`" domain=$domain";
}
catch
{
$cred = New-Object -TypeName System.Management.Automation.PSCredential
-ArgumentList {{ join_domain.username }}, (ConvertTo-SecureString
-String "{{ join_domain.encrypted_password }}"
-Key ([Byte[]] "{{ join_domain.key }}".split(",")));
{%- if join_domain.oupath -%}
Add-Computer -DomainName {{ join_domain.domain_name }} -Credential $cred
-Force -OUPath "{{ join_domain.oupath }}" -ErrorAction Stop;
{%- else -%}
Add-Computer -DomainName {{ join_domain.domain_name }} -Credential $cred
-Force -ErrorAction Stop;
{%- endif -%}
"changed=yes comment=`"Joined system to the domain.`" domain={{ join_domain.domain_name }}"
}'
- shell: powershell
- stateful: true
{%- endif %}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Went this direction for the following reasons: