test.ps1 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. $modules = @(
  2. "powershell-yaml"
  3. )
  4. $play_folders = @(
  5. "plays/common"
  6. )
  7. foreach ($mod in $modules){
  8. try {
  9. Import-Module $mod |Out-Null
  10. } catch {
  11. }
  12. if ((Get-Module $mod) -eq $null){
  13. "Need to install $mod module..."
  14. Install-Module -Scope CurrentUser -Force $mod
  15. Import-Module $mod
  16. }
  17. }
  18. $tplfile = "provision_tpl.yml"
  19. $provisionfile = "provision.yml"
  20. if (Test-Path $provisionfile -PathType leaf)
  21. {
  22. "Using $provisionfile"
  23. $currentplays = ConvertFrom-Yaml ([System.IO.File]::ReadAllText($provisionfile))
  24. } else {
  25. $currentplays = @()
  26. }
  27. $plays = @()
  28. foreach ($dir in $play_folders){
  29. $plays += (ls "$dir" |
  30. foreach-object {$_.name} | sort |
  31. ForEach-Object {
  32. "$dir/$_" |out-host
  33. $content = ConvertFrom-Yaml ([System.IO.File]::ReadAllText("$dir/$_"));
  34. $content.name = "$dir/$_"
  35. [PSCustomObject]@{
  36. enabled = [Boolean]($currentplays|foreach-object {$_.name}) -match "$dir/$_";
  37. name = "$_";
  38. dir = "$dir";
  39. content = $content;
  40. }
  41. }
  42. )
  43. }
  44. $enabledplays = $plays | Where-Object {$_.enabled}
  45. "Active Playbooks:"
  46. $enabledplays | Select-Object name,dir
  47. "Available Playbooks:"
  48. $plays | Select-Object name,dir
  49. # $label = (ConvertTo-Yaml ($commonplays|Select-Object nam))
  50. # $label
  51. $griddata = $plays
  52. "Griddata"
  53. $griddata|out-host
  54. . ./gui/gui.ps1
  55. $result = $griddata | Out-GridView -PassThru
  56. $ymltext = ConvertTo-Yaml($commonplays)
  57. ""
  58. # [System.IO.File]::WriteAllText($provisionfile, $ymltext)