what is the puppet agent status on the machine?
Asked Answered
B

4

34

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"}
Bhopal answered 30/3, 2015 at 15:21 Comment(2)
what operating system? also, open-source puppet or puppet enterprise?Anesthetize
You should not edit your question to add the answer.Zip
D
46

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'
Dumortierite answered 31/3, 2015 at 13:39 Comment(3)
You're right @BobYoplait, the config option to check is agent_disabled_lockfile. Updated my answer.Dumortierite
running this on a windows server does not return the same results. the agent can be enabled but still return a valid lockfile.Javanese
I could not believe that Puppet agent doesn't have a more elegant API, but after a lot of research it seems you are right, the only way is to write that clumsy command and hope that meanwhile they haven't changed this internal implementation. So sad.Gynecium
Z
7

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".

Zip answered 9/2, 2018 at 12:42 Comment(0)
C
2

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

Creamer answered 30/3, 2015 at 19:55 Comment(1)
If puppet was installed as a gem rather than a package then the service command won't exist.Anesthetize
M
1

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.

Moulder answered 19/1, 2022 at 14:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.