Class: Kitchen::Yansible::Tools::Install::Windows

Inherits:
Kitchen::Yansible::Tools::Install show all
Defined in:
lib/kitchen-yansible/tools/install/windows.rb

Constant Summary

Constants inherited from Kitchen::Yansible::Tools::Install

BINARY_DEFAULT_PREFIX, BINARY_INSTALL_PREFIX

Instance Method Summary collapse

Methods inherited from Kitchen::Yansible::Tools::Install

#alternatives_command, #ansible_alternatives, #ansible_version, #get_python_version, #initialize, #install_ansible_pip, #install_package, make, #package_manager, #pip_version, #python_version_size, #ruby_alternatives, #search_alternatives, #update_cache, #update_path

Methods included from Exec

#check_command, #command_exists, #detect_platform, #execute_local_command, #local_command_exists, #local_command_path, #print_cmd_error, #print_cmd_parameters, #sudo, #sudo_env, #unindent

Constructor Details

This class inherits a constructor from Kitchen::Yansible::Tools::Install

Instance Method Details

#install_pythonObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/kitchen-yansible/tools/install/windows.rb', line 76

def install_python
  python_version='3.7.6'
  base_url="https://www.python.org/ftp/python/#{python_version}"
  installer_name = "python-#{python_version}-amd64.exe"
  download_url = "#{base_url}/#{installer_name}"
  base_dir='C:\\python'
  distr_dir="#{base_dir}\\distr"
  install_dir="#{base_dir}\\install"
  install_args = [ '/passive', 'InstallAllUsers=1', 'PrependPath=1', "TargetDir=\"#{install_dir}\"", '/quiet' ]

  """
    #{install_win_software(download_url, distr_dir, install_dir, install_args, "python")}
  """
end

#install_rubyObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/kitchen-yansible/tools/install/windows.rb', line 91

def install_ruby
  ruby_version='2.6.5-1'
  base_url="https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-#{ruby_version}"
  installer_name = "rubyinstaller-#{ruby_version}-x64.exe"
  download_url = "#{base_url}/#{installer_name}"
  base_dir='C:\\opscode\\chef'
  distr_dir="#{base_dir}\\distr"
  install_dir="#{base_dir}\\embedded"
  install_args = [ '/silent', '/lang=en', '/tasks="assocfiles,modpath"', "/dir=\"#{install_dir}\"" ]

  """
    #{install_win_software(download_url, distr_dir, install_dir, install_args, "ruby")}
  """
end

#install_win_software(url, distr_dir, install_dir, install_arguments, test_binary) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/kitchen-yansible/tools/install/windows.rb', line 35

def install_win_software(url, distr_dir, install_dir, install_arguments, test_binary )
  """
    $downloadUrl = \"#{url}\"
    $distrDir=\"#{distr_dir}\"
    $installerName = \"#{File.basename(URI.parse(url).path)}\"
    $installDir=\"#{install_dir}\"
    $testBinary=\"#{test_binary}\"
    mkdir $distrDir -Force | out-null
    mkdir $installDir -Force | out-null

    try {
      $binaryInstalled = $False
      try {
        $binaryInstalled=(&{#{test_binary} --version} 2>&1 | % gettype) -ne [System.Management.Automation.ErrorRecord]
      }
      catch {
        echo \"#{test_binary.capitalize} is not installed.\"
      }
      if (! $binaryInstalled) {
        if (! (Test-Path \"${distrDir}\\${installerName}\") ) {
          echo \"Downloading ${installerName}\"
          Invoke-WebRequest -DisableKeepAlive -UseBasicParsing -Method GET -Uri \"${downloadUrl}\" -OutFile \"${distrDir}\\${installerName}\"
        }

        echo \"Installing ${installerName}\"
        $p = Start-Process -Wait -Passthru -FilePath \"${distrDir}\\${installerName}\" -ArgumentList #{install_arguments.join(', ')}

        if ($p.ExitCode -ne 0) {
          throw \"${installerName} installation was not successful. Received exit code $($p.ExitCode)\"
        }
      } else {
        echo \"#{test_binary.capitalize} installed already. Skipping.\"
      }
    }
    catch {
      Write-Error ($_ | ft -Property * | out-string) -ErrorAction Continue
      exit 1
    }
  """
end

#local_installObject



106
107
108
109
110
111
112
113
# File 'lib/kitchen-yansible/tools/install/windows.rb', line 106

def local_install
  """
    $ErrorActionPreference = 'Stop'

    #{install_python}
    #{install_ruby}
  """
end

#pip_required_packagesObject



28
29
30
31
32
33
# File 'lib/kitchen-yansible/tools/install/windows.rb', line 28

def pip_required_packages
  [
    "ansible#{pip_version(ansible_version)}",
    "pywinrm"
  ]
end

#remote_installObject



115
116
117
# File 'lib/kitchen-yansible/tools/install/windows.rb', line 115

def remote_install
  "echo 'Not supported'"
end