Open Wenzel opened 1 year ago
The ansible provisioner currently only supports ssh connections. Implementation updates will be required for winrm support so marking this as an enhancement.
Cheers
As a workaround I used the vagrant-host-shell
plugin to run a local script that will get the guest's IP address via vagrant winrm-config
dump and then provision the guest with ansible
:
Vagrantfile
....
# workaround https://github.com/hashicorp/vagrant/issues/13193
config.vm.provision :host_shell do |host_shell|
host_shell.inline = 'source ../venv/bin/activate && ./setup_target.sh'
end
setup_target.sh
#!/bin/bash
ip_address=$(vagrant winrm-config | grep 'HostName' | head -1 | awk '{print $2}')
ansible-playbook -i "${ip_address}," \
-e ansible_connection=winrm \
-e ansible_port=5985 \
-e ansible_winrm_transport=basic \
-e ansible_winrm_scheme=http \
-e ansible_shell_type=powershell \
-e ansible_user=vagrant \
-e ansible_password=vagrant \
playbook.yml $*
Since vagrant-host-shell is unmaintained since 2014, and Vagrant 2.3.7+ breaks the plugin compatibility, I switched to another workaround based on Vagrant triggers:
config.trigger.after :provision do |trigger|
trigger.info = "Provisioning"
trigger.run = {inline: "bash -c 'source ../venv/bin/activate && ./setup_target.sh -e target_harness=#{TARGET}'"}
end
The ansible provisioner currently only supports ssh connections. Implementation updates will be required for winrm support so marking this as an enhancement.
Cheers
This issue seems to be unresolved and stale. I have been attempting to build ansible provisioning with Vagrant recently and have posted a discussion topic to attempt to resurrect this issue. It does appear some work has been done to include WinRM support with the ansible provisioning plugin, however it seems incomplete or bugged.
Hope this helps bring some discussion and resolution to this topic.
Debug output
https://gist.github.com/Wenzel/4ba6ea863129f44bb3752edb2187b85b
Expected behavior
vagrant provision should have run the Ansible provisioner and the win_ping test should have completed
Actual behavior
Ansible attempts to use an SSH connection, despite our VM configured to use WinRM.
Reproduction information
Vagrant version
Vagrant 2.3.6
Host operating system
Ubuntu 23.04
Guest operating system
Windows 10
Steps to reproduce
python3 -m venv venv && source venv/bin/activate && pip install ansible pywinrm
1.git clone https://github.com/Wenzel/kafl.targets -b vagrant_ansible_ssh_bug
cd common/windows_template
packer build -var-file win10.pkrvars.hcl windows.pkr.hcl
vagrant box add packer_windows_libvirt.box --name kafl_windows
vagrant up
Vagrantfile
https://github.com/Wenzel/kafl.targets/blob/vagrant_ansible_ssh_bug/common/windows_template/Vagrantfile