From cd26711e7eea930d05d8805aae3b0510a86e8712 Mon Sep 17 00:00:00 2001 From: cfinlay Date: Wed, 11 Dec 2024 15:39:53 +0000 Subject: [PATCH] Copy logon script to client VMs --- ansible/roles/win_client/files/logon.ps1 | 28 ++++++++++++++++++++++++ ansible/roles/win_client/tasks/logon.yml | 12 ++++++++++ ansible/roles/win_client/tasks/main.yml | 1 + 3 files changed, 41 insertions(+) create mode 100644 ansible/roles/win_client/files/logon.ps1 create mode 100644 ansible/roles/win_client/tasks/logon.yml diff --git a/ansible/roles/win_client/files/logon.ps1 b/ansible/roles/win_client/files/logon.ps1 new file mode 100644 index 0000000..f552d70 --- /dev/null +++ b/ansible/roles/win_client/files/logon.ps1 @@ -0,0 +1,28 @@ +$bashProfilePath = Join-Path $HOME ".bash_profile" + +$condaPath = "C:\tools\miniforge3\Scripts\conda.exe" + +$requiredLine = 'eval "$(''/C/tools/miniforge3/Scripts/conda.exe'' ''shell.bash'' ''hook'')"' + +if (Test-Path $condaPath) { + Write-Host "Miniforge3 is installed at $condaPath" + + if (Test-Path $bashProfilePath) { + $currentContent = Get-Content -Path $bashProfilePath -ErrorAction SilentlyContinue + + if ($currentContent -contains $requiredLine) { + Write-Host "The required line is already present in .bash_profile" + } else { + Add-Content -Path $bashProfilePath -Value $requiredLine + Write-Host "The required line has been added to .bash_profile" + } + } else { + Set-Content -Path $bashProfilePath -Value $requiredLine -Force + Write-Host ".bash_profile created with the required line" + } + + Set-ItemProperty -Path $bashProfilePath -Name Attributes -Value ([System.IO.FileAttributes]::Hidden) + Write-Host ".bash_profile is set to hidden" +} else { + Write-Host "Miniforge3 is not installed. Exiting." +} diff --git a/ansible/roles/win_client/tasks/logon.yml b/ansible/roles/win_client/tasks/logon.yml new file mode 100644 index 0000000..2c17201 --- /dev/null +++ b/ansible/roles/win_client/tasks/logon.yml @@ -0,0 +1,12 @@ +--- +- name: Copy logon script to VMs + tags: + - logon + block: + - name: Copy logon script to VMs + win_copy: + src: "logon.ps1" + dest: "C:\\eidf\\" + force: true + when: "inventory_hostname in groups['meta-variant_client']|default([])" + when: groups['meta-variant_client'] is defined diff --git a/ansible/roles/win_client/tasks/main.yml b/ansible/roles/win_client/tasks/main.yml index 2ba3891..9acaa5e 100644 --- a/ansible/roles/win_client/tasks/main.yml +++ b/ansible/roles/win_client/tasks/main.yml @@ -3,3 +3,4 @@ - import_tasks: chocolatey.yml - import_tasks: rdgw.yml - import_tasks: start_menu.yml +- import_tasks: logon.yml