Bob Yoplait
Bob Yoplait

Reputation: 2499

what is the puppet agent status on the machine?

I know about

puppet agent --disable "my message"  --verbose

but I would like to know at some point on a given machine, what is its puppet agent status. I don't see how to do it from

man puppet-agent

Is there an command that would tell me if the agent is enabled or disabled ?

Thank you.

-

------------------- EDIT

CentOS release 6.6 (Final)

bash-4.1$ puppet --version
3.7.4
bash-4.1$ file /usr/bin/puppet 
/usr/bin/puppet: a /usr/bin/ruby script text executable

------------------- EDIT2

Whether it is enabled or disabled, I always get this:

[root@p1al25 ~]# cat `sudo puppet agent --configprint agent_catalog_run_lockfile`
cat: /var/lib/puppet/state/agent_catalog_run.lock: No such file or directory
[root@p1al25 ~]# puppet agent --disable "my message"
[root@p1al25 ~]# cat `sudo puppet agent --configprint agent_catalog_run_lockfile`
cat: /var/lib/puppet/state/agent_catalog_run.lock: No such file or directory
[root@p1al25 ~]# service puppet status
puppet (pid  4387) is running...

------------------- EDIT3

This one worked, thanks daxlerod

[root@p1al25 ~]# service puppet status
puppet (pid  4387) is running...
[root@p1al25 ~]# puppet agent --disable "my message" --verbose
Notice: Disabling Puppet.
[root@p1al25 ~]# cat `puppet agent --configprint agent_disabled_lockfile` 
{"disabled_message":"reason not specified"}

Upvotes: 35

Views: 101778

Answers (4)

artyom.razinov
artyom.razinov

Reputation: 665

Mac OS X:

Status:

$ puppet resource service puppet
service { 'puppet':
  ensure => 'stopped',
  enable => 'false',
}

Note that if it's enabled, it will return:

service { 'puppet':
  ensure => 'stopped',
  enable => 'true',
}

Start:

sudo puppet resource service puppet ensure=running enable=true

Stop:

sudo puppet resource service puppet ensure=stopped enable=false

Bonus: There's a trick I like: sudo --non-interactive. I use it in scripts for user that is sudoer. This will fail on computers that don't have sudoer instead of blocking execution of script.

Upvotes: 1

dr_
dr_

Reputation: 2292

I thought I'd post here an updated answer.

If the Puppet agent is disabled, there will be a file $vardir/state/agent_disabled.lock. This file also contains the reasons of the disabling, if a reason has been given via puppet agent --disable 'because reasons'.

You can get the value of $vardir via the command puppet config print vardir.


To sum up:

[me@linuxbox ~]# cat $(puppet config print vardir)/state/agent_disabled.lock

If the agent is disabled, you get:

{"disabled_message":"because reasons"}

If the agent is enabled, you get an error "No such file or directory".

Upvotes: 7

daxlerod
daxlerod

Reputation: 1166

A one-liner to get the current status is:

cat `puppet agent --configprint agent_disabled_lockfile`

Generally, this must be run as root, so I use:

sudo cat `sudo puppet agent --configprint agent_disabled_lockfile`

There are a number of possible results.

  • cat: \path\to\lock: No such file or directory Puppet is not disabled.
  • Any other text means that puppet is disabled, and the text is the reason provided when puppet was disabled by puppet agent --disable 'reason'

Upvotes: 47

KirstensAmazing
KirstensAmazing

Reputation: 123

agent status is typically used in a master-slave setup.

More details are here:

https://docs.puppetlabs.com/learning/agent_master_basic.html

since there are two possible questions you could be asking. One being:

Is my service running?
to which the answer would be running your typical service command (for example service puppet status)

Or, is my agent fully able to run?

To which the answer would be to use the command puppet agent --test

Upvotes: 2

Related Questions