Merge pull request #10215 from briancain/FIX-SALT-PILLAR

Salt pillar configuration on Windows guests
This commit is contained in:
Brian Cain 2018-09-20 09:17:32 -07:00 committed by GitHub
commit a4d5ee6ac1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 1 deletions

View File

@ -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(/(?<!\\)\"/, '"""').gsub(/\\\"/, %q(\\\\\""))}"
else
" pillar='#{@config.pillar_data.to_json}'"
end
end
end
# Get colorization option string to pass with the salt command

View File

@ -50,6 +50,32 @@ describe VagrantPlugins::Salt::Provisioner do
end
end
describe "#get_pillar" do
context "windows" do
it "escapes pillar data for powershell and returns as json" do
allow(machine.config.vm).to receive(:communicator).and_return(:winrm)
allow(config).to receive(:pillar_data).and_return({"cat"=>"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

View File

@ -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