1
votes

I'm trying to pass a string to a shell script that applies a state to a minion.

The script (build.sh):

pillar='pillar = '"'"'{"salt_master": "'$1'"}'"'"
echo $pillar
sudo salt 'ubuntu-test-node.example.com' state.sls ubuntu-node-test/firewall $pillar

The state (firewall.sls):

Allow SALT:
  iptables.append:
    - table: filter
    - chain: INPUT
    - jump: ACCEPT
    - comment: "Allow SALT Master"
    - protocol: tcp
    - dport: 4505:4506
    - source: {{ pillar['salt_master'] }}
    - position: 4
    - save: True

When I run ./build.sh 192.168.1.254 I get the following output and error- the echo output seems to be giving the desired string but the salt-stack is throwing an error.

 pillar = '{"salt_master": "192.168.1.254"}'
 ERROR: Minions returned with non-zero exit code
 ubuntu-test-node.example.com:
     Data failed to compile:
 ----------
     Rendering SLS 'base:ubuntu-node-test/firewall' failed: Jinja variable 'salt.utils.context.NamespacedDictWrapper object' has no attribute 'salt_master'

When running this command the salt-stack state is applied correctly

sudo salt 'ubuntu-test-node.example.com' state.sls ubuntu-node-test/firewall pillar='{"salt_master": "192.168.1.254"}'

What am I missing here? The echo output from the script matches the exact argument string I put in the manually typed-out command.

Thanks in advance

1

1 Answers

0
votes

The script doesn't look like it exactly spits out that command correctly as you show.

Try this:

pillar='pillar='"'"'{"salt_master": "'$1'"}'"'" 
echo $pillar 
sudo salt 'ubuntu-test-node.example.com' state.sls ubuntu-node-test/firewall $pillar

Observe no spaces between the second pillar on line one around the equals sign.