local/roles/1password/tasks/Windows.yaml

99 lines
2.6 KiB
YAML

---
# NOTE: The 1Password chocolatey packages are not up to date.
# GUI
- set_fact:
app_exe: '{{ansible_env.LOCALAPPDATA}}/1Password/app/8/1Password.exe'
installer_exe: '{{ansible_env.TEMP}}/1PasswordSetup-latest.exe'
- name: check if already installed
win_stat:
path: '{{app_exe}}'
register: app_stat
- name: download latest installer
when: not app_stat.stat.exists
win_get_url:
url: https://downloads.1password.com/win/1PasswordSetup-latest.exe
dest: '{{installer_exe}}'
environment: '{{proxy_environment}}'
- name: run installer
when: not app_stat.stat.exists
win_command: '{{installer_exe}}'
- name: remove installer
win_file:
path: '{{installer_exe}}'
state: absent
- name: create start menu shortcut
win_shortcut:
src: '{{app_exe}}'
dest: '{{ansible_env.ProgramData}}/Microsoft/Windows/Start Menu/Programs/1Password.lnk'
icon: '{{app_exe}},0'
# CLI
- set_fact:
cli_dir: '{{ansible_env.LOCALAPPDATA}}\1Password\cli'
cli_zip: '{{ansible_env.TEMP}}/op_windows_amd64.zip'
- set_fact:
cli_exe: '{{cli_dir}}\op.exe'
- name: check if op already installed
win_stat:
path: '{{cli_exe}}'
register: cli_stat
- name: get installed op version
when: cli_stat.stat.exists == True
win_command: '{{cli_exe}} --version'
register: cli_version
changed_when: false
- when: cli_stat.stat.exists == True
set_fact:
cli_installed_version: '{{cli_version.stdout.strip()}}'
- name: get list of op releases
win_uri:
url: https://raw.githubusercontent.com/kbenzie/op-release-scraper/main/op-releases.json
return_content: true
register: releases
- set_fact:
latest: '{{releases.json[0]}}'
- name: download latest op zip archive
when: cli_installed_version is not defined or cli_installed_version != latest.version
win_get_url:
url: '{{latest.downloads.Windows.amd64}}'
dest: '{{cli_zip}}'
environment: '{{proxy_environment}}'
- name: unzip op zip archive
when: cli_installed_version is not defined or cli_installed_version != latest.version
win_unzip:
src: '{{cli_zip}}'
dest: '{{cli_dir}}'
- name: add op install directory to user PATH
win_path:
scope: user
name: Path
elements: '{{cli_dir}}'
- name: get op powershell completion script
win_command:
argv:
- '{{ansible_env.LOCALAPPDATA}}/1Password/cli/op.exe'
- completion
- powershell
register: powershell_completion_script
changed_when: false
- name: create op powershell completion file
win_copy:
content: '{{powershell_completion_script.stdout}}'
dest: '{{cli_dir}}/opProfile.psm1'