Error when running 'puppet apply' from within a bash script

asked 2015-07-26 08:29:44 -0600

markb_1984 gravatar image

updated 2015-07-26 14:07:40 -0600

When invoking either puppet apply or puppet apply -e 'include' through a bash script, both work just fine, as per the following snippet:

#!/bin/bash
environmenthosts=192.168.5.5
puppetfacts=
userpassword=vagrant
releaseartifact=puppetmodules.tar.gz

for i in $environmenthosts;do echo $i; done | xargs -I{} bash -c "
{
  ./sshpasscmd $userpassword vagrant@{} sudo /bin/bash -c \"pwd; export PATH=/usr/bin:/usr/local/bin:/opt/vagrant_ruby/bin:/bin; puppet apply -e 'include'\"
}"

As soon as I add anything in addition to include, puppet fails to parse correctly. An example is if I include a valid class as per the following snippet:

./sshpasscmd $userpassword vagrant@{} sudo /bin/bash -c \"pwd; export PATH=/usr/bin:/usr/local/bin:/opt/vagrant_ruby/bin:/bin; puppet apply -e 'include ::test'\"

I then receive a bash error that would appear to indicate that the line above contains syntax errors. The exact error I receive is: 'ssh: Could not resolve hostname {}: nodename nor servname provided, or not known'. This is emanating from the fact that the '{}' in the hostname should be substituted by xargs in the for loop, but isn't. Bearing in mind the only difference between the script working and not working is the inclusion of 'include ::test' in the puppet apply command.

Running the puppet command directly on the box works just fine.

Appreciate insights into the cause of this issue.

Thanks.

edit retag flag offensive close merge delete

Comments

Does the command work if you change "include ::test" to "include test", assuming you can do that and get the correct class included?

GregLarkin gravatar imageGregLarkin ( 2015-07-27 15:58:24 -0600 )edit

This doesn't answer your question, but you could try putting your code in a script. Then do your ssh command, but download and run the script to set PATH and run the puppet command. Just a possible workaround.

johnnyb04 gravatar imagejohnnyb04 ( 2015-07-30 07:39:25 -0600 )edit

Im guessing its a shell parsing issue and the fact that include ::test does not work but include does is due to the ' space ' that you now have.. by money is on the space creating an issue with the parsing.

Kevin T gravatar imageKevin T ( 2017-01-09 08:39:58 -0600 )edit