Skip to content

Commit

Permalink
(#83) Fix issues with Linux host in local testing (#87)
Browse files Browse the repository at this point in the history
* (#83) Use plaintext authentication in Vagrant and CredSSP in Ansible

* (#83) Add path to inventory file

* (#83) Use credssp authentication to connect to WinRM

* (#83) Add '--start-at' example

* (#83) Add Open issues

* (#83) Clarify problem

* (#83) Use more barebones win2022 vagrant image

Avoid using a VM for the client which already has Chocolatey installed
as we want to test that works.

Co-authored-by: Rain Sallow <[email protected]>
  • Loading branch information
voskampm and vexx32 authored Nov 9, 2022
1 parent 38725a8 commit 4bc8a32
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
3 changes: 2 additions & 1 deletion chocolatey/tests/integration/vagrant-inventory.winrm
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ ansible_user=vagrant
ansible_password=vagrant
ansible_connection=winrm
ansible_port=5985
ansible_winrm_transport=ntlm
ansible_winrm_transport=credssp
ansible_winrm_server_cert_validation=ignore
ansible_become_method=runas
22 changes: 17 additions & 5 deletions testing-chocolatey/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,17 @@ Vagrant.configure("2") do |config|

end

# Needed when running on Fedora 36.
config.winrm.transport = :plaintext
config.winrm.max_tries = 300
config.winrm.retry_delay = 2
config.winrm.username = 'vagrant'
config.winrm.password = 'vagrant'
config.winrm.basic_auth_only = true

config.vm.define :choco_win_client do |client|
client.vm.box = "StefanScherer/windows_10"
# client.vm.box = "StefanScherer/windows_10" # Starts 'Windows Update' when Vagrant is still running resulting in connection errors.
client.vm.box = "StefanScherer/windows_2022" # Windows 2022
client.vm.communicator = "winrm"
client.vm.guest = :windows
client.vm.hostname = "win-client"
Expand All @@ -66,14 +75,11 @@ Vagrant.configure("2") do |config|
client.vm.network :forwarded_port, guest: 3389, host: 3389, id: "rdp", auto_correct: true, host_ip: "127.0.0.1"
client.vm.network :forwarded_port, guest: 22, host: 2222, id: "ssh", auto_correct: true, host_ip: "127.0.0.1"

client.winrm.username = "vagrant"
client.winrm.password = "vagrant"

client.vm.provider :virtualbox do |vbox|
vbox.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vbox.gui = false
vbox.customize ["modifyvm", :id, "--vram", 32]
vbox.customize ["modifyvm", :id, "--memory", "1024"]
vbox.customize ["modifyvm", :id, "--memory", "2048"]
vbox.customize ["modifyvm", :id, "--audio", "none"]
vbox.customize ["modifyvm", :id, "--clipboard", "bidirectional"]
vbox.customize ["modifyvm", :id, "--draganddrop", "hosttoguest"]
Expand All @@ -86,6 +92,12 @@ Vagrant.configure("2") do |config|

client.vm.provision "shell" do |ps|
ps.inline = <<-PS1
# Configure WinRM for Ansible
$installScript = Invoke-WebRequest -Uri "https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1" -UseBasicParsing
& ([scriptblock]::Create($installScript))
# Enable CredSSP/https in WinRM
Enable-WSManCredSSP -Role Server -Force
# Install Chocolatey
$installScript = Invoke-WebRequest -Uri "https://community.chocolatey.org/install.ps1" -UseBasicParsing
& ([scriptblock]::Create($installScript))
Expand Down
23 changes: 17 additions & 6 deletions testing-chocolatey/local-testing.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Beta-Testing Chocolatey with the Ansible Collection

- [Prerequisites](#prerequisites)
- [Getting Started](#getting-started)
- [Vagrant](#vagrant)
- [Generic](#generic)
- [Running `ansible-test`](#running-ansible-test)
- [Beta-Testing Chocolatey with the Ansible Collection](#beta-testing-chocolatey-with-the-ansible-collection)
- [Prerequisites](#prerequisites)
- [Getting Started](#getting-started)
- [Vagrant](#vagrant)
- [Generic](#generic)
- [Running `ansible-test`](#running-ansible-test)
- [Open issues](#open-issues)

## Prerequisites

Expand Down Expand Up @@ -88,7 +90,11 @@ Continue on to the [Running `ansible-test`](#running-ansible-test) section.
```sh
source ~/ansible/bin/activate
cd ~/.ansible/collections/ansible_collections/chocolatey/chocolatey
ansible-test windows-integration -vvvv --inventory vagrant-inventory.winrm --requirements --continue-on-error
ansible-test windows-integration --inventory /home/vagrant/.ansible/collections/ansible_collections/chocolatey/chocolatey/tests/integration/vagrant-inventory.winrm --requirements --continue-on-error
```
or to start a specific test:
```
ansible-test windows-integration --inventory /home/vagrant/.ansible/collections/ansible_collections/chocolatey/chocolatey/tests/integration/vagrant-inventory.winrm --requirements --continue-on-error --start-at win_chocolatey_facts
```

1. To retrieve the test files from the Ansible server VM when using Vagrant, copy the test result files to the `/vagrant/results` shared folder to retrieve them from the Linux VM:
Expand All @@ -110,3 +116,8 @@ npm install xunit-viewer -g
xunit-viewer -r ./results -o ./results/report.html
Invoke-Item ./results/report.html
```
### Open issues
* [Vagrant environment does not load ansible.windows modules correctly](https://github.com/chocolatey/chocolatey-ansible/issues/71)

0 comments on commit 4bc8a32

Please sign in to comment.