Generate an Ansible Configuration file with PowerShell

Steps to Proceed
Step 1 : Define Variables for file_path> , private_ip, password in an automated way.
Step 2 : Include the following code snippet accordingly (ansible_port using the default ssh port)
$inventoryPath= file_path
$inventoryFile = @"
[Linux]
private_ip ansible_password=password

[Linux:vars]
ansible_user=user
ansible_connection=ssh
ansible_port=22
ansible_ssh_common_args='-o StrictHostKeyChecking=no'

"@

$inventoryFile | Out-File $inventoryPath
Write-Host "Writing Inventory file ..." -ForegroundColor Yellow
(Get-Content $inventoryPath -Raw).Replace("`r`n","`n") | Set-Content $inventoryPath -Force

Post a Comment

0 Comments