Skip to content

Commit 37c8c6e

Browse files
committed
Update output and changelog
1 parent 3d7a840 commit 37c8c6e

File tree

4 files changed

+45
-26
lines changed

4 files changed

+45
-26
lines changed

AnsibleCtl/Functions/Start-AnsibleCtl.ps1

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ function Start-AnsibleCtl
9696

9797
Write-Verbose "[ansiblectl] Version $Script:PSModuleVersion"
9898

99+
if (-not $Silent.IsPresent -and $VerbosePreference -eq 'SilentlyContinue')
100+
{
101+
Write-Host "> Verify input and prepare .ansiblectl cache folder... `r" -NoNewline
102+
}
103+
99104
# Ensure we are on a Windows system by using the legacy Windows
100105
# PowerShell or the modern cross-platform PowerShell on the Windows OS.
101106
if ($PSVersionTable.PSVersion.Major -gt 5 -and -not $IsWindows)
@@ -193,6 +198,11 @@ function Start-AnsibleCtl
193198
## Container Image
194199
##
195200

201+
if (-not $Silent.IsPresent -and $VerbosePreference -eq 'SilentlyContinue')
202+
{
203+
Write-Host "> Define container image for the ansiblectl container... `r" -NoNewline
204+
}
205+
196206
if ($PSCmdlet.ParameterSetName -like 'ContainerImage_*')
197207
{
198208
# Nothing to do, the container image is already specified.
@@ -231,6 +241,11 @@ function Start-AnsibleCtl
231241
## SSH Keys
232242
##
233243

244+
if (-not $Silent.IsPresent -and $VerbosePreference -eq 'SilentlyContinue')
245+
{
246+
Write-Host "> Prepare SSH Keys for the ansiblectl container... `r" -NoNewline
247+
}
248+
234249
$sshKeysCleanupFiles = @()
235250

236251
if ($PSCmdlet.ParameterSetName -like '*_KeyFiles')
@@ -340,18 +355,6 @@ function Start-AnsibleCtl
340355
## Run Ansible Control Node
341356
##
342357

343-
if (-not $Silent.IsPresent)
344-
{
345-
Write-Host ''
346-
Write-Host 'ANSIBLE CONTROL NODE' -ForegroundColor 'Magenta'
347-
Write-Host '********************' -ForegroundColor 'Magenta'
348-
Write-Host ''
349-
Write-Host "Ansible Repo : $repositoryFullPath"
350-
Write-Host "Container Image : $ContainerImage"
351-
Write-Host "SSH Key Mode : $sshKeyMode"
352-
Write-Host ''
353-
}
354-
355358
$normalizedRepositoryPath = '/{0}' -f $repositoryFullPath.Replace(':', '').Replace('\', '/').Trim('/')
356359

357360
$dockerSshKeysVolumeMount = '{0}/.ansiblectl/.ssh:/tmp/.ssh' -f $normalizedRepositoryPath
@@ -360,17 +363,17 @@ function Start-AnsibleCtl
360363

361364
if ($PSCmdlet.ParameterSetName -like 'Dockerfile_*')
362365
{
363-
if (-not $Silent.IsPresent)
366+
if (-not $Silent.IsPresent -and $VerbosePreference -eq 'SilentlyContinue')
364367
{
365-
Write-Host '> Building container image from specified Dockerfile...'
368+
Write-Host "> Building container image from specified Dockerfile... `r" -NoNewline
366369
}
367370
Invoke-DockerProcess -Command 'build' -ArgumentList '-t', $ContainerImage, '-f', $Dockerfile, $dockerfilePath -ErrorMessage "The Docker build of the Dockerfile '$Dockerfile' failed."
368371
}
369372
else
370373
{
371-
if (-not $Silent.IsPresent)
374+
if (-not $Silent.IsPresent -and $VerbosePreference -eq 'SilentlyContinue')
372375
{
373-
Write-Host '> Pulling container image from remote registry...'
376+
Write-Host "> Pulling container image from remote registry... `r" -NoNewline
374377
}
375378
Invoke-DockerProcess -Command 'pull' -ArgumentList $ContainerImage -ErrorMessage "The Docker pull of the container image '$ContainerImage' failed."
376379
}
@@ -380,11 +383,17 @@ function Start-AnsibleCtl
380383

381384
if (-not $Silent.IsPresent)
382385
{
383-
Write-Host '> Start ansiblectl container with mounted volumes...'
386+
Write-Host ' '
387+
Write-Host 'ANSIBLE CONTROL NODE' -ForegroundColor 'Magenta'
388+
Write-Host '********************' -ForegroundColor 'Magenta'
389+
Write-Host ''
390+
Write-Host "Ansible Repo : $repositoryFullPath"
391+
Write-Host "Container Image : $ContainerImage"
392+
Write-Host "SSH Key Mode : $sshKeyMode"
384393
Write-Host ''
385394
}
386395

387-
Invoke-DockerProcess -Command 'run' -ArgumentList '-it', '--rm', '-h', 'ansiblectl', '-v', $dockerSshKeysVolumeMount, '-v', $dockerRepositoryPathVolumeMount, '-v', $dockerBashHistoryVolumeMount, $ContainerImage
396+
Invoke-DockerProcess -Command 'run' -ArgumentList '-it', '--rm', '-h', 'ansiblectl', '-v', $dockerSshKeysVolumeMount, '-v', $dockerRepositoryPathVolumeMount, '-v', $dockerBashHistoryVolumeMount, $ContainerImage -ShowOutput
388397
}
389398
catch
390399
{
@@ -408,17 +417,23 @@ Register-ArgumentCompleter -CommandName 'Start-AnsibleCtl' -ParameterName 'Ansib
408417
param ($CommandName, $ParameterName, $WordToComplete, $CommandAst, $FakeBoundParameters)
409418

410419
# Hardcode the 'latest' tag as it's always available
411-
[System.Management.Automation.CompletionResult]::new('latest', 'latest', 'ParameterValue', 'latest')
420+
$results = @('latest')
412421

413422
# Query the config.json from the GitHub repository to get the available
414423
# Ansible versions which will be builded and published to the container.
415424
# This is not perfect, but the image registry has non anonymous API to get
416425
# all containers tags.
417426
$config = Invoke-RestMethod -uri 'https://raw.githubusercontent.com/claudiospizzi/ansiblectl/refs/heads/main/docker/config.json'
418427
foreach ($ansibleVersion in $config.ansible.versions) {
419-
if ($ansibleVersion -like "$WordToComplete*") {
420-
[System.Management.Automation.CompletionResult]::new($ansibleVersion, $ansibleVersion, 'ParameterValue', $ansibleVersion)
421-
[System.Management.Automation.CompletionResult]::new("$ansibleVersion-ci", "$ansibleVersion-ci", 'ParameterValue', "$ansibleVersion-ci")
428+
$results += $ansibleVersion
429+
$results += "$ansibleVersion-ci"
430+
}
431+
432+
foreach ($result in $results)
433+
{
434+
if ($result -like "$WordToComplete*")
435+
{
436+
[System.Management.Automation.CompletionResult]::new($result, $result, 'ParameterValue', $result)
422437
}
423438
}
424439
}

AnsibleCtl/Helpers/Invoke-DockerProcess.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ function Invoke-DockerProcess
2121
[System.String[]]
2222
$ArgumentList,
2323

24+
# If specified, show the output of the docker command in the console.
25+
[Parameter(Mandatory = $false)]
26+
[Switch]
27+
$ShowOutput,
28+
2429
# The error message to display if the command fails.
2530
[Parameter(Mandatory = $false)]
2631
[System.String]
@@ -41,7 +46,7 @@ function Invoke-DockerProcess
4146

4247
# If -Verbose was specified, don't redirect the output and show it in
4348
# the console output.
44-
if ($VerbosePreference -eq 'SilentlyContinue')
49+
if ($VerbosePreference -eq 'SilentlyContinue' -and -not $ShowOutput.IsPresent)
4550
{
4651
$dockerCommandSplat['RedirectStandardOutput'] = [System.IO.Path]::GetTempFileName()
4752
$dockerCommandSplat['RedirectStandardError'] = [System.IO.Path]::GetTempFileName()

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ All notable changes to this project will be documented in this file.
55
The format is mainly based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8-
## 0.1.0 - 2025-09-17
8+
## Unreleased
99

10-
- Added: Initial development release of AnsibleCtl with the Start-AnsibleCtl cmdlet
10+
- Added: Initial development release of AnsibleCtl container image with the Start-AnsibleCtl cmdlet

docker/build.ps1

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)