Jira (PUP-9208) Requesting new feature for notify messages

14 views
Skip to first unread message

Patrick Mayes (JIRA)

unread,
Oct 4, 2018, 8:35:04 AM10/4/18
to puppe...@googlegroups.com
Patrick Mayes created an issue
 
Puppet / New Feature PUP-9208
Requesting new feature for notify messages
Issue Type: New Feature New Feature
Assignee: Unassigned
Components: PE
Created: 2018/10/04 5:34 AM
Environment:

RHEL6, 7, Centos7

Priority: Normal Normal
Reporter: Patrick Mayes

Currently there is not a good way to have a catalog fail but continue compiling the catalog.  The options we have been given are to either use one of the 2 options which isn't ideal

This will come back with an error but would like to have a notify value that provides an error, this is for testing and also if a new node doesn't get provisioned properly:

  notify { 'this should fail': }
  -> exec { '/bin/false': }

The following will come back with an error 500 and stops compiling 

fail("There are no classes assigned to ${facts['fqdn']} please contact someone!!!")

We want to have an option where it continues to process but shows a failure message, example

test_fail("There are no classes assigned to $(facts['fqdn']} please contact someone!!!")

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93)
Atlassian logo

Henrik Lindberg (JIRA)

unread,
Oct 4, 2018, 1:32:29 PM10/4/18
to puppe...@googlegroups.com
Henrik Lindberg commented on New Feature PUP-9208
 
Re: Requesting new feature for notify messages

How about issuing a warning instead?

Patrick Mayes (JIRA)

unread,
Oct 4, 2018, 1:37:37 PM10/4/18
to puppe...@googlegroups.com
Patrick Mayes commented on New Feature PUP-9208

Because warning doesn't show up as a failure in the puppet reports that get displayed by the puppet console.

Michael Smith (JIRA)

unread,
Oct 4, 2018, 1:58:10 PM10/4/18
to puppe...@googlegroups.com
Michael Smith commented on New Feature PUP-9208

That sounds like something akin to a resource that always fails, rather than a function.

Patrick Mayes (JIRA)

unread,
Oct 4, 2018, 2:03:08 PM10/4/18
to puppe...@googlegroups.com
Patrick Mayes commented on New Feature PUP-9208

That works as long as we can have a custom message, in one case we only want to provide a custom status message when it fails stating 'This failed as expected' for testing, other times we want to post something saying for example 'This node facts['fqdn'] doesn't have any classes attached, email X...@ABC.com'

Jorie Tappa (JIRA)

unread,
Oct 8, 2018, 4:49:05 PM10/8/18
to puppe...@googlegroups.com
Jorie Tappa commented on New Feature PUP-9208

Could this be accomplished through a custom resource type?

Josh Cooper (JIRA)

unread,
Oct 8, 2018, 5:16:05 PM10/8/18
to puppe...@googlegroups.com
Josh Cooper commented on New Feature PUP-9208

If you write a custom resource type and provider, then you could verify that the catalog contains at least one class:

if @resource.catalog.classes.empty?
  raise "There are no classes assigned to ${Puppet[:certname]}"
end

This would generate an error on the agent at catalog application time, and the error will be in the report.

Patrick Mayes (JIRA)

unread,
Oct 9, 2018, 9:12:08 AM10/9/18
to puppe...@googlegroups.com
Patrick Mayes commented on New Feature PUP-9208

That covers only one case specifically, and while yes we could create custom resources and etc..  We see this being beneficial for more than just our company to be able to test failures but allow catalog complication to continue.  In this way if we added the specific resource into a module it would show up as an error for that module but other modules would still execute.  Also since we are using Puppet Enterprise we are requesting this as a feature request rather than writing something custom.

Henrik Lindberg (JIRA)

unread,
Oct 5, 2019, 6:18:03 AM10/5/19
to puppe...@googlegroups.com

Maybe using a Deferred function call would solve this as condition seems to be determined at compile time?
The Deferred value would need to be assigned to a resource attribute - for example the message of a Notify. If this needs to be a stable value the function that is called deferred could return the same value every time.

notify { 'example:'
  message => Deferred('agent_warning', ["stable message", "this is logged as a warning"])
}

Patrick Mayes (JIRA)

unread,
Oct 6, 2019, 4:08:03 AM10/6/19
to puppe...@googlegroups.com
Patrick Mayes commented on New Feature PUP-9208

As long as the catalog will still compile but show up as a failed puppet run (exit code 1) then I'm fine with that idea.  What I'm looking for is a run to fail but the catalog to still compile and apply other items. 

So if I had enteriprise_puppet modules, and a module called fail_me attached it would still run the enterprise_puppet modules successfully but for module fail_me with a notify message or a different resource the puppet run will show there was a failure for fail_me without having to call /bin/false to force a failure.

If this doesn't make sense then let me know and I will have a meeting setup via our Puppet TAM.

Henrik Lindberg (JIRA)

unread,
Oct 6, 2019, 5:40:04 AM10/6/19
to puppe...@googlegroups.com

Unfortunately my idea of using deferred does not work without modifications. Given this:

notify{ first:
  message => "first notify"
}
$x = Deferred('new', [String, Deferred('err', ["oh no"])])
notify{test:
  message => $x
}

It will make a normal run + log an error.

henrik$ puppet apply test.pp
Error: Scope(): oh no
Notice: first notify
Notice: /Stage[main]/Main/Notify[first]/message: defined 'message' as 'first notify'
Notice:
Notice: /Stage[main]/Main/Notify[test]/message: defined 'message' as ''
Notice: Applied catalog in 0.01 seconds
henrik$ echo $?
0

But will exit with 0.

If changing the call to err to fail it fails prematurely - like this:

henrik$ puppet apply test.pp
Error: oh no
henrik$ echo $?
1

Then it does not apply anything because fail bailed out.

What is missing is a function that will log and cause an exit 1. Ping Josh Cooper Do you think it is possible to write such a function?

Sidenote: the double deferred that calls String.new is because err and warning returns nil and notify resource does not like this. The double defferred type casts the nil/undef into a String.

Mikhail (JIRA)

unread,
Nov 29, 2019, 5:07:05 AM11/29/19
to puppe...@googlegroups.com
Mikhail commented on New Feature PUP-9208

Good time, dear people.

During struggling around the similar issue we've found a construction, which implements the desired behavior:

 exec {@(END/L)
        Some multiline
        message
        | END
    :
    command => '/$',
}   notify {'Im compiled and applied':
    message => '👌',
}

with `puppet apply --detailed-exitcodes manifest.pp` it returns 6

Josh Cooper (Jira)

unread,
Jan 28, 2021, 1:39:04 PM1/28/21
to puppe...@googlegroups.com
Josh Cooper commented on New Feature PUP-9208

Since you want the catalog compilation to succeed, but catalog application to partially fail, then I'd suggest writing a custom type. Using a custom type, you can access the catalog, and check to see it has the classes you expect:

Puppet::Type.newtype(:guard) do
  @doc = "Guard against missing classes"
 
  newparam(:name)
 
  newproperty(:message, :idempotent => false) do
    desc "The message to be sent to the log"
    def sync
      resource.fail(self.should)
    end
 
    def retrieve
      resource.catalog.classes
    end
 
    def insync?(is)
      # there is always a settings class
      is != ["settings"]
    end
 
    defaultto { @resource[:name] }
  end
end

Then you can guard any resources where specific classes are expected, such as to protect again misclassification, and only fail those resources while allowing unrelated resources to be applied. For example, given:

guard { "missing": }
 
notify { "dependent":
  require => Guard['missing']
}
 
notify{ "unrelated": }

# puppet apply partialfail.pp
Notice: Compiled catalog for localhost in environment production in 0.03 seconds
Error: missing
Error: /Stage[main]/Main/Guard[missing]/message: change from ['settings'] to 'missing' failed: missing
Notice: /Stage[main]/Main/Notify[dependent]: Dependency Guard[missing] has failures: true
Warning: /Stage[main]/Main/Notify[dependent]: Skipping because of failed dependencies
Notice: unrelated
Notice: /Stage[main]/Main/Notify[unrelated]/message: defined 'message' as 'unrelated'
Notice: Applied catalog in 0.01 seconds

Note puppet will exit with 0, because from its perspective, it applied the entire catalog. To differentiate between "all resources were applied successfully" vs "at least one resource failed" you must use --detailed-exitcodes as Mikhail mentioned. See PUP-2754 for more history on that.

Alternatively, it is possible to write a custom function to conditionally add a deferred resource that fails a notify, like [~henrik] mentioned.

Adding a parameter like failure => true to the notify resource is also possible, but you're still going to need to write a custom function to conditionally set the parameter if the catalog's classes are empty. But then you could just as add a deferred err function like Henrik Lindberg suggested.

As a result, we don't have plans to add this to the core notify resource. Please reach out to your TAM to see about getting a custom type or function implemented to solve your use case.

This message was sent by Atlassian Jira (v8.5.2#805002-sha1:a66f935)
Atlassian logo

Charlie Sharpsteen (Jira)

unread,
Jul 16, 2021, 4:42:02 PM7/16/21
to puppe...@googlegroups.com

The notify resource basically does two things:

  • Logs a message at a selectable level
  • Generates a refresh event

Enhancing notify with something like event_type => failure in addition to event_type => refresh doesn’t seem like much of an overload. I know there are also folks out there that would also appreciate event_type => none as they just want the log message and not the event.

This message was sent by Atlassian Jira (v8.13.2#813002-sha1:c495a97)
Atlassian logo

Beth Glenfield (Jira)

unread,
Jul 27, 2021, 10:21:04 AM7/27/21
to puppe...@googlegroups.com

This feature request can be tracked on Product Board at this URL: https://portal.productboard.com/puppet/1-puppet-idea-portal/c/275-log-messages-without-notify-resource. We would greatly appreciate adding any additional context through the portal card for this issue.

Reply all
Reply to author
Forward
0 new messages