Skip to content

Instantly share code, notes, and snippets.

View virtualhobbit's full-sized avatar
:octocat:
Building clouds

Mark Brookfield virtualhobbit

:octocat:
Building clouds
View GitHub Profile
---
- hosts: Linux
gather_facts: true
tasks:
- name: Upgrade all yum packages
yum:
name: "*"
state: latest
become: yes
---
ansible_become_password: "{{ lookup('hashi_vault', 'secret=credentials/computers/production/{{ inventory_hostname }}:Password')}}"
ansible_become_method: su
env:
VAULT_ADDR: '{{ vault_server }}'
VAULT_AUTH_METHOD: approle
VAULT_ROLE_ID: '{{ vault_role_id }}'
VAULT_SECRET_ID: '{{ vault_secret_id }}'
fields:
- id: vault_server
type: string
label: URL for Vault Server
- id: vault_role_id
type: string
label: Vault AppRole ID
- id: vault_secret_id
type: string
label: Vault Secret ID
recompose_pool:
stage: recompose
tags:
- windows
script:
- Write-Host "Connecting to Horizon"
- Connect-HVServer -Server $cs -User $csUser -Password $csPass -Domain $csDomain
- Write-Host "Refreshing Horizon Pool"
- Start-HVPool -Pool $poolName -Recompose -LogoffSetting FORCE_LOGOFF -ParentVM "$packer_vmName" -SnapshotVM "Created by Packer" -StopOnFirstError $true
- Write-Host "Disconnecting to Horizon"
install_powercli:
stage: install
tags:
- windows
script:
- Write-Host "Installing NuGet"
- Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
- Write-Host "Set the repo installation policy"
- Set-PSRepository PSGallery -InstallationPolicy Trusted
- Write-Host "Installing PowerCLI"
deploy_windows-10:
stage: build
tags:
- windows
script:
- Write-Host "Deploying Windows 10"
- Set-Location windows-10
- ../packer.exe build -force windows-10-pilot.json
retrieve_vault_password:
stage: retrieve
tags:
- windows
artifacts:
paths:
- windows-10/setup/Autounattend.xml
script:
- Write-Host "Retrieving Administrator password from Vault"
- $result = Invoke-RestMethod -Headers @{"X-Vault-Token" = ${env:VAULT_TOKEN}} -Method Get -Body $json -Uri ${env:VAULT_ADDR}/v1/creds/users/misc/administrator
get_packer:
stage: get
tags:
- windows
artifacts:
paths:
- packer.exe
script:
- Write-Host "Fetching packer"
- $packerFile = "packer_" + $packerVersion + "_windows_amd64.zip"
stages:
- get
- retrieve
- build
- install
- recompose
before_script:
- git config --global http.sslVerify false