This commit is contained in:
2024-05-26 09:05:55 -05:00
parent 5969895920
commit 31d12f7d28
10 changed files with 67 additions and 1 deletions

View File

@@ -24,3 +24,18 @@ Set-PSReadLineOption -PredictionSource History
$env:POWERSHELL_TELEMETRY_OPTOUT = 1
$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1
$tokens = @(
@{
name = "GITLAB_TOKEN"
value = "cli-gitlab"
}
)
function unlockbw {
$env:BW_SESSION = "$(bw unlock --raw)"
foreach ($token in $tokens) {
Set-Variable -Name $token.name -Value $(bw get password $token.value) -Scope script
}
}

1
.env Normal file
View File

@@ -0,0 +1 @@
GITLAB_TOKEN="$(bw get password cli-gitlab)"

1
.gitignore vendored
View File

@@ -1 +0,0 @@
tmux/.config/tmux

View File

@@ -1,3 +1,4 @@
.env
ansible
Makefile
ansible.cfg

View File

@@ -1,2 +1,5 @@
include .env
export
run:
ansible-playbook ./ansible/local.yml -K

View File

@@ -1,6 +1,8 @@
- hosts: localhost
connection: local
become: true
vars:
GITLAB_TOKEN: "{{ lookup('env', 'GITLAB_TOKEN') }}"
# vars_prompt:
roles:

View File

@@ -1,6 +1,13 @@
- name: install fonts
include_tasks: "./scripts/install_fonts.yml"
- name: generate ssh keys
include_tasks: "./scripts/configure_ssh.yml"
- name: Configure Gitlab SSH
become_user: user
ansible.builtin.command: pwsh -f ./scripts/configure_gitlab.ps1 "{{ GITLAB_TOKEN }}"
- name: set gnome config
become_user: user
dconf:

View File

@@ -11,6 +11,7 @@ required_packages_brew:
- terraform
- kubernetes-cli
- zsh-autosuggestions
- bitwarden-cli
apt_keys:
- https://packages.microsoft.com/keys/microsoft.asc

View File

@@ -0,0 +1,32 @@
param ($GITLAB_TOKEN)
if (!$GITLAB_TOKEN){
Write-Output "Please unlock Bitwarden"
break
}
#Gitlab set ssh key
$header = @{
"PRIVATE-TOKEN"=$GITLAB_TOKEN
}
$GitlabAPI = "https://gitlab.com/api/v4"
$publickey = Get-Content ~/.ssh/id_ed25519.pub
$body = @{
title = "Ansible Script"
key = "$publickey"
} | ConvertTo-Json
Try{
Invoke-RestMethod -Headers $header -Uri $GitlabAPI/user/keys -Body $body -Method Post -ContentType application/json -ErrorVariable gitlabkey | Out-Null
}Catch{
if($gitlabkey -like "*Token is expired*"){
Write-Error "Token Has Expired"
exit -1
}
if($gitlabkey -notlike "*has already been taken*"){
Write-Error "Failed to upload key"
exit -1
}
}

View File

@@ -0,0 +1,5 @@
- name: Generate an OpenSSH keypair
become_user: user
community.crypto.openssh_keypair:
path: ~/.ssh/id_ed25519
type: ed25519