diff --git a/plugins/provisioners/salt/provisioner.rb b/plugins/provisioners/salt/provisioner.rb index 7a6376fd1..8b69b7915 100644 --- a/plugins/provisioners/salt/provisioner.rb +++ b/plugins/provisioners/salt/provisioner.rb @@ -176,7 +176,19 @@ module VagrantPlugins ## Actions # Get pillar string to pass with the salt command def get_pillar - " pillar='#{@config.pillar_data.to_json}'" if !@config.pillar_data.empty? + if !@config.pillar_data.empty? + if @machine.config.vm.communicator == :winrm + # ' doesn't have any special behavior on the command prompt, + # so '{"x":"y"}' becomes '{x:y}' with literal single quotes. + # However, """ will become " , and \\""" will become \" . + # Use \\"" instead of \\""" for literal inner-value quotes + # to avoid issue with odd number of quotes. + # --% disables special PowerShell parsing on the rest of the line. + " --% pillar=#{@config.pillar_data.to_json.gsub(/(?"qubit"}) + + expect(subject.get_pillar).to eq(" --% pillar={\"\"\"cat\"\"\":\"\"\"qubit\"\"\"}") + end + end + + context "linux" do + it "returns pillar data as json" do + allow(machine.config.vm).to receive(:communicator).and_return(:false) + allow(config).to receive(:pillar_data).and_return({"cat"=>"shimi"}) + expect(subject.get_pillar).to eq(" pillar='{\"cat\":\"shimi\"}'") + end + end + + context "empty data" do + it "returns nothing if pillar data is empty" do + allow(config).to receive(:pillar_data).and_return({}) + expect(subject.get_pillar).to eq(nil) + end + end + end + describe "#call_highstate" do context "master" do it "passes along extra cli flags" do diff --git a/website/source/docs/provisioning/salt.html.md b/website/source/docs/provisioning/salt.html.md index ce0c90e74..680c8b73d 100644 --- a/website/source/docs/provisioning/salt.html.md +++ b/website/source/docs/provisioning/salt.html.md @@ -183,6 +183,8 @@ times. The data passed in should only be hashes and lists. Here is an example:: end ``` +On Windows guests, this requires PowerShell 3.0 or higher. + ## Preseeding Keys Preseeding keys is the recommended way to handle provisioning