-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstandalone_ansible_playbook.ps1
More file actions
executable file
·40 lines (34 loc) · 1.36 KB
/
standalone_ansible_playbook.ps1
File metadata and controls
executable file
·40 lines (34 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env pwsh
param (
[Parameter(Position=0)][string]$GitHubRepoUrl = "https://github.com/Kipjr/cloud-init_linux",
[Parameter(Position=1)][string]$PlaybookName = "site.yml",
[Parameter(Position=2)][string]$WorkingDir = "/tmp",
[Parameter(Position=3)][string]$AnsibleArg
)
$ErrorActionPreference = "Stop"
Set-StrictMode -Version 3
$UUID = (id -u)
if ($UUID -eq 0) {
Write-Host "Please run as a regular user. Exiting..."
exit
}
Set-Location -Path $WorkingDir
$TMPDIR = Join-Path -Path $WORKING_DIR -ChildPath ("ansible." + ([System.IO.Path]::GetRandomFileName()).Substring(0,4))
New-Item -Path $TMPDIR -ItemType Directory
Set-Location -Path $TMPDIR
Invoke-WebRequest -Uri "https://bootstrap.pypa.io/get-pip.py" -OutFile "${TMPDIR}/get-pip.py"
python3 "${TMPDIR}/get-pip.py" --user
$env:PATH="/home/adminuser/.local/bin:$env:PATH"
python3 -m pip install --user ansible
git clone $GitHubRepoUrl git_repo
if (Test-Path -Path "$PSScriptRoot/defaults/main.yml") {
Copy-item -Path "$PSScriptRoot/defaults/main.yml" "${TMPDIR}/git_repo/defaults/main.yml"
}
Set-Location -Path "${TMPDIR}/git_repo"
if (Test-Path -Path $PlaybookName) {
ansible-galaxy install -r collections/requirements.yml
ansible-playbook -v -i inventory "$AnsibleArg" "$PlaybookName"
} else {
Write-Output "Playbook $PlaybookName does not exist."
}
Set-Location -Path "$WorkingDir"