Skip to content

Instantly share code, notes, and snippets.

@neilus
Last active August 25, 2020 13:24
Show Gist options
  • Save neilus/995c635d99144e37b922250de10e45b7 to your computer and use it in GitHub Desktop.
Save neilus/995c635d99144e37b922250de10e45b7 to your computer and use it in GitHub Desktop.
PoC: Managing windows via Ansible - A vagrant environment
.tox/
virtualenv/
.venv/
.vagrant/

Managing windows machine via Ansible

TL;DR;

Long story short:

  1. pip install -r requirements.txt
  2. vagrant up - note that this might fail at the provisioning, but no worries!
  3. ansible -m win_ping windows to ensure the VM is reachable
  4. ansible-playbook playbook This will install a lot of stuff and reboot
[ssh_connection]
pipelining = True
ssh_args = -o ControlMaster=auto -o ControlPersist=30m -o
ConnectionAttempts=100 -o UserKnownHostsFile=/dev/null
[defaults]
inventory = ./.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
callback_whitelist = profile_tasks
fact_caching = memory
gathering = smart
host_key_checking = False
retry_files_enabled = False
stdout_callback = skippy
timeout = 60
winrm_server_cert_validation=ignore
---
- name: Test Play
hosts: windows
tasks:
- name: Install Chocolatey
win_shell: |
Set-ExecutionPolicy Bypass -Scope Process -Force;
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
- name: Ensure we wait long enough for the updates to be applied during reboot
win_updates:
reboot: yes
reboot_timeout: 36000
- name: Install packages via Chocolatey
win_chocolatey:
name: "{{ item }}"
with_items:
- python
# - python2
# - python3
# - python.pypy
# - ironpython
- git
- git-lfs
- dotnetcore-sdk
- vscode
- vscode-intellicode
- vscode-python
- vscode-ruby
- vscode-vsliveshare
- vscode-gitignore
- vscode-ansible
- vscode-go
- vscode-java
- vscode-java-debug
- vscode-react-native
- vscode-maven
- vscode-yaml
- vscode-maven
- vscode-java-debug
# - vscode-firefox-debug
# - vscode-chrome-debug
- vscode-gitattributes
- vscode-java-test
- vscode-csharp
- vscode-powershell
- vscode-gitlens
- vscode-csharpextensions
- vscode-settingssync
#- intellijidea-community
#- pycharm-community
# - googlechrome
# - firefox
# - microsoft-edge
- microsoft-windows-terminal
# - visualstudio2019community
# - visualstudio2019-remotetools
# - visualstudio2019-performancetools
# - visualstudio2019-workload-nativecrossplat
# - visualstudio2019-workload-xamarinbuildtools
# - visualstudio2019-workload-node
# - visualstudio2019-workload-nodebuildtools
# - visualstudio2019-workload-netcoretools
# - visualstudio2019-workload-netcorebuildtools
# - visualstudio2019-workload-netweb
# - visualstudio2019-workload-vctools
# - visualstudio2019-workload-datascience
# - visualstudio2019-workload-databuildtools
# - visualstudio2019-workload-python
# - selenium-all-drivers
# - ojdkbuild
- ojdkbuild8
- ojdkbuild11
- wsl
#- wsl-ubuntu-1804
#- wsl-kalilinux
#- wsl-fedoraremix
#- ubuntuhere
- minikube
- docker-machine
# - docker-desktop
- docker-compose
- golang
- dep
- vim
ansible
ansible-lint
pywinrm
[tox]
skipsdist = True
envlist = vagrant, ansible, py{38}
[testenv]
passenv = *
recreate = False
deps = -r{toxinidir}/requirements.txt
whitelist_externals =
vagrant
echo
commands = {posargs:echo 'You can run a command like: "tox -- vagrant up" or whatever inside the venv'}
[testenv:vagrant]
commands =
vagrant validate
[testenv:ansible]
commands =
ansible-lint -v --parseable-severity --force-color playbook.yml
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "peru/windows-10-enterprise-x64-eval"
config.vm.communicator = :winrm
config.vm.guest = :windows
config.vm.provider "libvirt" do |provider|
provider.cpus = "4"
provider.memory = "8096"
end
config.vm.provider "virtualbox" do |provider|
provider.gui = false
provider.cpus = "4"
provider.memory = "8096"
provider.customize [ "modifyvm", :id, "--nested-hw-virt", "on" ]
# provider.customize [ "modifyvm", :id, "--accelerate3d", "on" ]
# provider.customize [ "modifyvm", :id, "--monitorcount", "2"]
end
# config.vm.network "private_network", type: "dhcp"
N = 1
win_list = []
(1..N).each do |machine_id|
config.vm.define "windows#{machine_id}" do |win|
win.vm.hostname = "windows#{machine_id}"
#win.vm.network "private_network", type: "dhcp"
win_list << "windows#{machine_id}"
if machine_id == N
win.vm.provision "ansible" do |ansible|
ansible.playbook = "./playbook.yml"
ansible.limit = "all"
ansible.groups = {
"windows" => win_list,
"windows:vars" => {
"ansible_winrm_server_cert_validation" => "ignore"
}
}
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment