On Wednesday, March 19, 2014 4:03:26 AM UTC-5, Roman Alekseev wrote:
>
> Hi,
>
> I created fact but it doesn't work. What did I make wrong?
>
>
>
>
>
>
>
> *# nginx_arg.rbFacter.add("nginx_arg") do  setcode do    
> Facter::Util::Resolution.exec("/usr/sbin/nginx -V 2> /etc/puppet/nginx.args 
> | /bin/cat /etc/puppet/nginx.args | /usr/bin/awk 
> -F'--http-proxy-temp-path=' {'print $2'} | /usr/bin/awk {'print $1'}  | 
> /bin/grep '\/'")  endend*
>
>

There are a couple of weird things about that, but before that:

   - What does "doesn't work" mean, specifically?
   - Where is the file located on the master?
   - Do you have pluginsync enabled on the agents?
   - Is the fact value output by "facter -p" on agent nodes that have 
   synced the fact?

With respect to the command itself,

   - which output stream from /usr/sbin/nginx are you trying to use?  (You 
   are using stderr (via a temp file), but you are also piping stdout and 
   ignoring it.)
   - the unquoted curly braces in the command will be parsed by the shell, 
   not passed to awk.
   - Setting awk's field separator to '--http-proxy-temp-path=' will 
   probably not do anything sensible if there are other options listed after 
   than one in nginx's output.
   - If you need a temp file, you should put it in /tmp or /var/tmp and 
   give it an unpredictable name.  But you don't need one for what it looks 
   like you're trying to do.

Were I writing a command to do what I *think* yours is trying to do, it 
would look something like this:

    Facter::Util::Resolution.exec(
      "/usr/sbin/nginx -V 2>&1 1>/dev/null | /bin/sed -n 
's,.*--http-proxy-temp-path=\(/\S\+\).*,\1,p'"
    )

That pipes the stderr stream of the nginx command into sed, discarding the 
stdout.  Sed then filters out everything except any strings of 
non-whitespace beginning with a slash character (/) and directly following 
the string "--http-proxy-temp-path=".  The output does not include the 
"--http-proxy-temp-path=".  If you need to allow for whitespace either 
before or after the '=' character then the pattern can be adjusted to 
achieve that.


John

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/51f8f45b-e739-4f24-8f84-2d8d6489c17c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to