Hyper-V for trellis development

Hi there,

I’ve just started to look at Trellis so apologies if this is answered elsewhere, but how easy would it be to adapt Trellis to use Hyper-V for local development instead of Vagrant? I already have Vagrant integrated with Hyper-V on my dev machine and because of this I’m unable to use VirtualBox.

Cheers.

You’d need to add a Hyper-V provider to the Vagrantfile like these other ones: https://github.com/roots/trellis/blob/2773baa313a496227eafbe294ca5b30d484c232a/Vagrantfile#L128-L153

If you’re able to get it working, you could do a PR since it would be useful for others :thumbsup:

Thanks - been working on it for a few hours now, making some progress but not quite there.

I created the following Hyper-V section in the vagrantfile:

  # Hyper-V settings
  config.vm.provider 'hyperv' do |hv|
    config.vm.box = "maxx/ubuntu16"
    config.vm.box_version = '0.4'
    hv.vmname = config.vm.hostname
    hv.cpus = cpus
    hv.memory = memory
  end

I’m now getting some NFS errors “No host IP was given to the Vagrant core NFS helper.” which i think is related to the hostmanager plugin. Still working at it… :slight_smile:

Still struggling to get the dev environment loaded up. If someone can share their working Vagrantfile used on Windows with Hyper-V, that would be great.

So I managed to get this working after much googling and trial and error. I ended up removing all references to NFS in the Vagrantfile and used the ‘smb’ file sharing instead. I also ran into another issue which I wanted to ask about - not sure if this is related to my choice of smb instead of nfs? In the “\trellis\roles\wordpress-install\tasks\directories.yml” file I had to comment out the following sections:

# - name: Create web root of sites
#   file:
#     path: "{{ www_root }}/{{ item.key }}/{{ item.value.current_path | default('current') }}/web"
#     owner: "{{ web_user }}"
#     group: "{{ web_group }}"
#     mode: 0755
#     state: directory
#   with_dict: "{{ wordpress_sites }}"

and

# - name: Change site owner to user
#   file:
#     path: "{{ www_root }}/{{ item.key }}"
#     owner: "{{ web_user }}"
#     group: "{{ web_group }}"
#     state: directory
#     recurse: yes
#   with_dict: "{{ wordpress_sites }}"

The file permissions appeared to be correct in the VM, but the error I was getting was as follows:

chgrp failed                                                                                                     
failed: [default] (item=mywebsites.com) => {"failed": true, "gid": 1000, "group": "vagrant", "item": "mywebsites.com", "mode": "0755", "owner": "vagrant", "path": "/srv/www/mywebsites.com/current", "size": 4096, "s
tate": "directory", "uid": 1000}                                                                                 
        to retry, use: --limit @/home/vagrant/trellis/dev.retry                                                  
                                                                                                                 
PLAY RECAP *********************************************************************                                 
default                    : ok=87   changed=1    unreachable=0    failed=1                                      
                                                                                                                 
Ansible failed to complete successfully. Any error output should be                                              
visible above. Please fix these errors and try again.                                                            

But when looking at the folder permissions within the guest this was already set to ‘vagrant’ for both the owner and group. I guess this doesn’t matter in the dev environment, but not sure why i was getting this error?

I wanted to give this a try last night, I got Hyper-V installed, however the Vagrant docs do warn that you can’t use any other virtualization apps if you use Hyper-V. Since I tend to work with others on projects, and sometimes not in Windows at all, this is basically a no go for me.

It’s quite serious too, after installing Hyper-V I tried to vagrant up on a Virtualbox-based Vagrant project and got a blue screen :scream:

Yah, been on that BSOD too :open_mouth:

Yeah, if you use Hyper-V you can’t use Virtualbox or VMware. But on the positive side, the performance of Hyper-V is far superior than anything else on Windows 10.

2 Likes