Absent Member.. Julien_chausse Absent Member..
Absent Member..
404 views

Puppet Agent Run - SSH Operation

Hello Helpers,

 

We are trying to run the puppet agent within a SSH operation.The expected result is the exit status code of the puppet run. The issue we are coming across is that OO is not returning as the same result of the command as if run on the guest machine.

OO will return nothing, the guest machine will return the exit status code. See below for details:

 

Here is the command in OO: 

 

expect (>|$|#)$

send sudo sh -c 'puppet agent -t --server ${puppet_server} --environment ${puppet_env} --pluginsync -l ${initial_puppet_run_log_file} > /dev/null ; echo "exit_status=${?}" '

expect (>|$|#)$

 

Step Result Inpector of the command in OO:

 

sudo sh -c 'puppet agent -t --server puppetservername --environment nonproduction --pluginsync –l /var/log/puppet/logfile > /dev/null ; echo "exit_status=${?}" '

 

Same command executed on the guest machine:

 

> sudo sh -c 'puppet agent -t --server puppetservername --environment nonproduction --pluginsync –l /var/log/puppet/logfile > /dev/null ; echo "exit_status=${?}" '
exit_status=1
>

 

 

Thanks in advance for your help.

Julien

Labels (1)
0 Likes
3 Replies
Absent Member.. Martin_gm Absent Member..
Absent Member..

Re: Puppet Agent Run - SSH Operation

The STDOUT result of the "SSh Shell" operation should contain "exit_status=1".

 

What is the content of this result in your case?

0 Likes
Absent Member.. Julien_chausse Absent Member..
Absent Member..

Re: Puppet Agent Run - SSH Operation

The "SSh Shell" operation does not return the output of the command before it completes successfully. This is our problem. Have you ever come across this issue ?

 

Any help welcome

Cheers

0 Likes
Malchore Absent Member.
Absent Member.

Re: Puppet Agent Run - SSH Operation

We have learned to not use the SSH Shell operation unless we really need to send multiple commands in the same SSH session. Based on your example, I would switch to using the SSH Command operation. You are only sending a single command, so no need to use SSH Shell.

 

We never could figure out how to use SSH Shell effectively. But a trick that always works is to do the following:

 

The first thing you do with any SSH Shell operation is to change the default Unix prompt to something unique. This is the standard pre-amble for ALL our SSH Shell operations:

 

expectEndsWith $
send export PS1='HPOOPROMPT$'
expectEndsWith HPOOPROMPT$

 

The command 'expectEndsWith' is a very simple "grep"-lilke utility that searches STDOUT for a string  and when found, triggers the following 'send' command. In our case, all of our Linux servers have a default user prompt of "$". (And our standard login banner never uses the $ character.) So, when SSH Shell sees "$", we know it is a the command prompt waiting for input. Next, we change the default prompt to HPOOPROMPT$. ( send export PS1='HPOOPROMPT$' ) From then on, all we do is...

 

send << command >>

expectEndsWith HPOOPROMPT$

 

It works.

 

But for your needs, you really only need to use the SSH Command operation. Be sure to create a result Flow Variable that takes the output from Output Field STDOUT. That will give you the entire STDOUT of the command. You can even apply a filter to extract only the last line of output, so you just get the "exit_status=1" string.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.