anadimisra / biztalk-provisioner

Automated provisioner for BizTalk Server.
MIT License
0 stars 2 forks source link

investigate: synced folder implementation for windows #5

Closed vishagilityroots closed 7 years ago

vishagilityroots commented 7 years ago

Vagrant + Puppet (agentless) on Linux works by rsyncing a directory over to the remote VM over SSH. This does not work in our situation, as we do not have an SSH server running on the Windows VM.

For a purely "Windows" solution we need a non-SSH method to sync folders. Investigate.

vishagilityroots commented 7 years ago

One approach is SMB-based synced folders.

But this will require my laptop (i.e SMB host) to have a publicly accessible (preferably static) IP and Port. Can't imagine that happening over the personal internet connections I use.

Alternatively I can provision a Samba server on AWS as part of the provisioning process. Let that directory contain all necessary pieces for provisioning.

vishagilityroots commented 7 years ago

Another approach: Use Powershell to SCP directory

:exclamation: Powershell 5 is required for Copy-Item -ToSession to work.

Download Powershell 5 here.

:exclamation: To send files via Powershell and WinRM you need to enable Powershell Remoting..

Code below enables Powershell remoting and adds the EC2 host to trusted hosts:

PS C:\Users\vvenu3> Enable-PSRemoting –force
WinRM has been updated to receive requests.
WinRM service type changed successfully.
WinRM service started.

WinRM has been updated for remote management.
Created a WinRM listener on HTTP://* to accept WS-Man requests to any IP on this machine.

PS C:\Users\vvenu3> winrm set winrm/config/client ‘@{TrustedHosts="ec2-13-126-199-191.ap-south-1.compute.amazonaws.com"}
'
Client
    NetworkDelayms = 5000
    URLPrefix = wsman
    AllowUnencrypted = false
    Auth
        Basic = true
        Digest = true
        Kerberos = true
        Negotiate = true
        Certificate = true
        CredSSP = false
    DefaultPorts
        HTTP = 5985
        HTTPS = 5986
    TrustedHosts = ec2-13-126-199-191.ap-south-1.compute.amazonaws.com

Then you would create a session and send files as follows:

# create PSCredentials Object
$password = ConvertTo-SecureString "REPLACE_WITH_PASSWORD" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential("Administrator",$password)

# create HTTP Session to remote server using PSCredential object as credentials
$session = New-PSSession ec2-13-126-199-191.ap-south-1.compute.amazonaws.com -Port 5985 -Credential $cred

# Copy directory to remote.
Copy-Item -ToSession $session -Path C:\Users\vvenu3\work\biztalk-provisioner -Destination C:\Users\Administrator\biztalk-provisioner -Recurse

:exclamation: for this to work in automated provisioner, we need to automatically retrieve the provisioned AWS Server's IP address.

References

vishagilityroots commented 7 years ago

New Problem: Script fails with strange errors

Is it possible that remote machine needs Powershell 5.0 as well?? Looking into silent install of PS 5.0.

Update no. the problem was that I was using shell provisioner to run a local script. :exclamation: Shell provisioner runs only remote scripts. You need vagrant-host-shell plugin to run host-shell as provisioning step.

vishagilityroots commented 7 years ago

Verified working with my rsync implementation using powershell. Fixed.

vishagilityroots commented 7 years ago

Tried out this plugin: https://github.com/Cimpress-MCP/vagrant-winrm-syncedfolders

It seems to sync directories very well over WinRM (verified with Vagrant 1.8.x)

        config2.vm.synced_folder ".", "C:/vagrant", type: "winrm"

And with this approach, provisioning with puppet also works, using the winrm method of syncing manifests.

  config.vm.provision :puppet do |puppet|
    # remote manifest path
    puppet.manifests_path = "manifests"
    # remote module Path: https://github.com/mitchellh/vagrant/issues/2902
    puppet.module_path = "modules"
    puppet.manifest_file = "default.pp"
    puppet.binary_path = "C:/puppet/bin"
    # TODO this uses https://github.com/Cimpress-MCP/vagrant-winrm-syncedfolders
    puppet.synced_folder_type = "winrm"
  end
vishagilityroots commented 7 years ago

Rsync works with the above commits. Closing ... again.