-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_choco.yml
59 lines (49 loc) · 1.81 KB
/
install_choco.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
---
# Adapted from:
# https://github.com/deekayen/ansible-role-chocolatey
# BSD 3-Clause License
# Copyright (c) 2017, David Norman
# Install choco and reboot
- hosts: windows
vars:
chocolatey_installer: https://chocolatey.org/install.ps1
chocolatey_path: c:/ProgramData/chocolatey
chocolatey_version: latest
chocolatey_windows_compression: "false"
tasks:
- name: "Check for existing chocolatey install."
win_stat:
path: "{{ chocolatey_path }}/choco.exe"
register: chocolatey_exe
- debug:
var: chocolatey_exe
verbosity: 2
- name: "Install latest Chocolatey."
raw: "$env:chocolateyUseWindowsCompression='{{ chocolatey_windows_compression }}'; \
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
iex ((New-Object System.Net.WebClient).DownloadString('{{ chocolatey_installer }}'))"
register: chocolatey_install_result
when:
- chocolatey_exe.stat.exists is defined
- not chocolatey_exe.stat.exists
- chocolatey_version == "latest"
- name: "Install specific Chocolatey."
raw: "$env:chocolateyUseWindowsCompression='{{ chocolatey_windows_compression }}'; \
$env:chocolateyVersion = '{{ chocolatey_version }}'; \
iex ((New-Object System.Net.WebClient).DownloadString('{{ chocolatey_installer }}'))"
register: chocolatey_install_result
when:
- chocolatey_exe.stat.exists is defined
- not chocolatey_exe.stat.exists
- chocolatey_version != "latest"
- debug:
var: chocolatey_install_result
verbosity: 3
- name: "Add chocolatey to PATH."
win_path:
name: PATH
elements: '%ALLUSERSPROFILE%\chocolatey\bin'
scope: machine
state: present
- name: "Reboot."
win_reboot: