Merge pull request #10215 from briancain/FIX-SALT-PILLAR
Salt pillar configuration on Windows guests
This commit is contained in:
commit
a4d5ee6ac1
|
@ -176,7 +176,19 @@ module VagrantPlugins
|
||||||
## Actions
|
## Actions
|
||||||
# Get pillar string to pass with the salt command
|
# Get pillar string to pass with the salt command
|
||||||
def get_pillar
|
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
|
end
|
||||||
|
|
||||||
# Get colorization option string to pass with the salt command
|
# Get colorization option string to pass with the salt command
|
||||||
|
|
|
@ -50,6 +50,32 @@ describe VagrantPlugins::Salt::Provisioner do
|
||||||
end
|
end
|
||||||
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
|
describe "#call_highstate" do
|
||||||
context "master" do
|
context "master" do
|
||||||
it "passes along extra cli flags" do
|
it "passes along extra cli flags" do
|
||||||
|
|
|
@ -183,6 +183,8 @@ times. The data passed in should only be hashes and lists. Here is an example::
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
On Windows guests, this requires PowerShell 3.0 or higher.
|
||||||
|
|
||||||
## Preseeding Keys
|
## Preseeding Keys
|
||||||
|
|
||||||
Preseeding keys is the recommended way to handle provisioning
|
Preseeding keys is the recommended way to handle provisioning
|
||||||
|
|
Loading…
Reference in New Issue