Skip to content

Instantly share code, notes, and snippets.

@ignatev
Last active May 14, 2020 11:31
Show Gist options
  • Save ignatev/2c0b501a554c4aaf61bc020c0995e3af to your computer and use it in GitHub Desktop.
Save ignatev/2c0b501a554c4aaf61bc020c0995e3af to your computer and use it in GitHub Desktop.
#
# Cookbook:: psaas-cookbook
# Recipe:: image-builder-base
#
# Copyright:: 2019, The Authors, All Rights Reserved.
ruby_block 'refreshenv' do
block do
refresh_env
end
action :nothing
end
powershell_script 'install-chocolatey' do
code <<-EOH
Set-ExecutionPolicy Bypass -Scope Process -Force;
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'));
EOH
notifies :run, 'ruby_block[refreshenv]', :immediately
end
chocolatey_package 'vscode'
chocolatey_package 'inspec'
chocolatey_package 'azure-cli' do
notifies :run, 'ruby_block[refreshenv]', :immediately
end
powershell_script 'install-azcli-devops-extension' do
code <<-EOH
az extension add --name azure-devops
EOH
end
powershell_script 'disable-firewall' do
code <<-EOH
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False
EOH
end
powershell_script 'configure-winrm' do
code <<-EOH
$url = "https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1"
$file = "$env:temp\\ConfigureRemotingForAnsible.ps1"
(New-Object -TypeName System.Net.WebClient).DownloadFile($url, $file)
powershell.exe -ExecutionPolicy ByPass -File $file
EOH
end
windows_env 'AppStream_Resource_Type' do
value "image-builder"
action :create
end
user "devops" do
password "x(UIU?mE;t4mAmSQE"
end
group "Administrators" do
action :modify
members "devops"
append true
end
require 'win32/registry'
def get_reg_env(hkey, subkey, &block)
Win32::Registry.open(hkey, subkey) do |reg|
reg.each_value do |name|
value = reg.read_s_expand(name)
if block && ENV.key?(name)
ENV[name] = block.call(name, ENV[name], value)
else
ENV[name] = value
end
end
end
end
def refresh_env
get_reg_env(Win32::Registry::HKEY_LOCAL_MACHINE, 'System\CurrentControlSet\Control\Session Manager\Environment')
get_reg_env(Win32::Registry::HKEY_CURRENT_USER, 'Environment') do |name, old_value, new_value|
if name.upcase == 'PATH'
old_value || File::PATH_SEPARATOR || new_value
else
new_value
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment