Guidelines

This site is for tech Q&A. Please keep your posts focused on the subject at hand.

Ask one question at a time. Don't conflate multiple problems into a single question.

Make sure to include all relevant information in your posts. Try to avoid linking to external sites.

Links to documentation are fine, but in addition you should also quote the relevant parts in your posts.

0 votes
3.6k views
3.6k views

With the Puppet agent disabled you'll get a notice like this when trying to manually run the agent:

Notice: Skipping run of Puppet configuration client; administratively disabled (Reason: 'reason not specified');
Use 'puppet agent --enable' to re-enable.

Also the agent will exit with a status code of 1, so the status "agent disabled" could be detected like this:

puppet agent --test --noop >/dev/null 2>&1
if [ $? -eq 1 ]; then
  echo 'puppet agent is disabled'
fi

However, running the agent (even if it's just a dry-run) is not very elegant. Is there a better way of detecting the agent status?

in Scripting
by (115)
2 18 33
edit history

Please log in or register to answer this question.

1 Answer

0 votes
 

Disabling the Puppet agent creates a file /opt/puppetlabs/puppet/cache/state/agent_disabled.lock (re-enabling the agent removes it), so you can check for the presence of that file to detect whether or not the agent is disabled.

if [ -f /opt/puppetlabs/puppet/cache/state/agent_disabled.lock ]; then
  echo 'puppet agent is disabled'
fi

The file contains JSON data with the reason that was specified when disabling the agent, or the string "reason not specified" if the reason was omitted. That allows you to display the reason to other users or restore the original reason if you have to re-enable the agent temporarily.

Example:

The command

puppet agent --disable 'just for kicks'

will create the lock file with the following content:

{"disabled_message":"just for kicks"}

You can extract the message, then re-enable the agent for a test run, and disable it again with the original reason afterwards.

lockfile='/opt/puppetlabs/puppet/cache/state/agent_disabled.lock'
reason="$(jq -r '.disabled_message' "$lockfile")"
puppet agent --enable
puppet agent --test --noop
puppet agent --disable "$reason"

This is useful for instance when you're debugging Puppet manifests and want to have a notification in place so that other team members don't re-enable the agent by mistake.


edited by
by (115)
2 18 33
edit history
...