Puppet output to agent without notify
Given the following example:
[root@puppet ~]# cat notify_test.pp
define test (
Boolean $condition = false,
) {
if $condition {
notify { "Debug Output of Test[${title}]": }
}
}
$test_resource_name_a = 'A'
test { $test_resource_name_a:
condition => true,
}
$test_resource_name_b = 'B'
test { $test_resource_name_b: }
exec { 'TestExec':
refreshonly => true,
command => '/usr/bin/echo "Mock Service Refresh"',
logoutput => true,
subscribe => Test[$test_resource_name_a, $test_resource_name_b],
}
Which should only print something to the agent but appearently refreshes all subscribing resources becaus of resource containment (see https://puppet.com/docs/puppet/4.10/lang_containment.html). Unwanted result:
[root@puppet ~]# puppet apply notify_test.pp
Notice: Compiled catalog for puppet in environment production in 0.10 seconds
Notice: Debug Output of Test[A]
Notice: /Stage[main]/Main/Test[A]/Notify[Debug Output of Test[A]]/message: defined 'message' as 'Debug Output of Test[A]'
Notice: /Stage[main]/Main/Exec[TestExec]/returns: Mock Service Refresh
Notice: /Stage[main]/Main/Exec[TestExec]: Triggered 'refresh' from 1 events
Notice: Applied catalog in 1.53 seconds
So whenever the condition is met (e.g. my custom function which uses an HTTP Client to get data from REST APIs which I use is my manifests but dont have real impact on the catalog compilation) all subscribers (e.g. services) would restart every 30 minutes.
This behaviour is unacceptable, so how can I print something to the puppet agent (puppet agent -t
) without notifying/refreshing auto-contained resources?
puppet puppet-enterprise
add a comment |
Given the following example:
[root@puppet ~]# cat notify_test.pp
define test (
Boolean $condition = false,
) {
if $condition {
notify { "Debug Output of Test[${title}]": }
}
}
$test_resource_name_a = 'A'
test { $test_resource_name_a:
condition => true,
}
$test_resource_name_b = 'B'
test { $test_resource_name_b: }
exec { 'TestExec':
refreshonly => true,
command => '/usr/bin/echo "Mock Service Refresh"',
logoutput => true,
subscribe => Test[$test_resource_name_a, $test_resource_name_b],
}
Which should only print something to the agent but appearently refreshes all subscribing resources becaus of resource containment (see https://puppet.com/docs/puppet/4.10/lang_containment.html). Unwanted result:
[root@puppet ~]# puppet apply notify_test.pp
Notice: Compiled catalog for puppet in environment production in 0.10 seconds
Notice: Debug Output of Test[A]
Notice: /Stage[main]/Main/Test[A]/Notify[Debug Output of Test[A]]/message: defined 'message' as 'Debug Output of Test[A]'
Notice: /Stage[main]/Main/Exec[TestExec]/returns: Mock Service Refresh
Notice: /Stage[main]/Main/Exec[TestExec]: Triggered 'refresh' from 1 events
Notice: Applied catalog in 1.53 seconds
So whenever the condition is met (e.g. my custom function which uses an HTTP Client to get data from REST APIs which I use is my manifests but dont have real impact on the catalog compilation) all subscribers (e.g. services) would restart every 30 minutes.
This behaviour is unacceptable, so how can I print something to the puppet agent (puppet agent -t
) without notifying/refreshing auto-contained resources?
puppet puppet-enterprise
add a comment |
Given the following example:
[root@puppet ~]# cat notify_test.pp
define test (
Boolean $condition = false,
) {
if $condition {
notify { "Debug Output of Test[${title}]": }
}
}
$test_resource_name_a = 'A'
test { $test_resource_name_a:
condition => true,
}
$test_resource_name_b = 'B'
test { $test_resource_name_b: }
exec { 'TestExec':
refreshonly => true,
command => '/usr/bin/echo "Mock Service Refresh"',
logoutput => true,
subscribe => Test[$test_resource_name_a, $test_resource_name_b],
}
Which should only print something to the agent but appearently refreshes all subscribing resources becaus of resource containment (see https://puppet.com/docs/puppet/4.10/lang_containment.html). Unwanted result:
[root@puppet ~]# puppet apply notify_test.pp
Notice: Compiled catalog for puppet in environment production in 0.10 seconds
Notice: Debug Output of Test[A]
Notice: /Stage[main]/Main/Test[A]/Notify[Debug Output of Test[A]]/message: defined 'message' as 'Debug Output of Test[A]'
Notice: /Stage[main]/Main/Exec[TestExec]/returns: Mock Service Refresh
Notice: /Stage[main]/Main/Exec[TestExec]: Triggered 'refresh' from 1 events
Notice: Applied catalog in 1.53 seconds
So whenever the condition is met (e.g. my custom function which uses an HTTP Client to get data from REST APIs which I use is my manifests but dont have real impact on the catalog compilation) all subscribers (e.g. services) would restart every 30 minutes.
This behaviour is unacceptable, so how can I print something to the puppet agent (puppet agent -t
) without notifying/refreshing auto-contained resources?
puppet puppet-enterprise
Given the following example:
[root@puppet ~]# cat notify_test.pp
define test (
Boolean $condition = false,
) {
if $condition {
notify { "Debug Output of Test[${title}]": }
}
}
$test_resource_name_a = 'A'
test { $test_resource_name_a:
condition => true,
}
$test_resource_name_b = 'B'
test { $test_resource_name_b: }
exec { 'TestExec':
refreshonly => true,
command => '/usr/bin/echo "Mock Service Refresh"',
logoutput => true,
subscribe => Test[$test_resource_name_a, $test_resource_name_b],
}
Which should only print something to the agent but appearently refreshes all subscribing resources becaus of resource containment (see https://puppet.com/docs/puppet/4.10/lang_containment.html). Unwanted result:
[root@puppet ~]# puppet apply notify_test.pp
Notice: Compiled catalog for puppet in environment production in 0.10 seconds
Notice: Debug Output of Test[A]
Notice: /Stage[main]/Main/Test[A]/Notify[Debug Output of Test[A]]/message: defined 'message' as 'Debug Output of Test[A]'
Notice: /Stage[main]/Main/Exec[TestExec]/returns: Mock Service Refresh
Notice: /Stage[main]/Main/Exec[TestExec]: Triggered 'refresh' from 1 events
Notice: Applied catalog in 1.53 seconds
So whenever the condition is met (e.g. my custom function which uses an HTTP Client to get data from REST APIs which I use is my manifests but dont have real impact on the catalog compilation) all subscribers (e.g. services) would restart every 30 minutes.
This behaviour is unacceptable, so how can I print something to the puppet agent (puppet agent -t
) without notifying/refreshing auto-contained resources?
puppet puppet-enterprise
puppet puppet-enterprise
edited Nov 16 '18 at 14:47
Pali
asked Nov 16 '18 at 14:35
PaliPali
7191726
7191726
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
This is a limitation inherent in modeling Notify
as a resource. By definition and design, applying a resource does nothing if that resource is initially in sync with the target system. In order that Notify
resources do anything (i.e. emit their message), they are always initially out of sync, and emitting their message brings them into sync. You can conceptualize that as a transition from "not printed" to "printed", if you like.
But that means that from Puppet's perspective, every Notify
resource is changed every time it is applied. That generates an event, which is propagated to the Notify
's container and onward.
This behaviour is unacceptable, so how can I print something to the
puppet agent (puppet agent -t
) without notifying/refreshing
auto-contained resources?
If you must have the messages in the agent's log (as opposed to the master's) then your options are limited. In fact, the best I can come up with is to write a custom resource type and provider that is always in sync, yet emits messages into the log anyway. I tested using an Exec
with an unless
parameter that emits the message, but Puppet does not seem to print the output of the unless
command. Certainly, Notify
is right out.
If it would be sufficient to emit the message into the master's log, then there is a set of functions for that purpose. Among them, notice(), info(), and debug() seem the most likely for your purpose.
Side note: the phrase "auto-contained resources" suggests that there is another kind. Before Puppet 6 you could declare resources at top scope, and those are contained only by the catalog itself, which does not propagate events to anything else. But every resource declared inside a container -- class or defined type -- is contained by that container. That's always seemed very natural to me. Usually the thing that trips people up about containment is that classes are only contained when you explicitly make it so. There are good reasons for that, but I won't go into them here.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53339889%2fpuppet-output-to-agent-without-notify%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This is a limitation inherent in modeling Notify
as a resource. By definition and design, applying a resource does nothing if that resource is initially in sync with the target system. In order that Notify
resources do anything (i.e. emit their message), they are always initially out of sync, and emitting their message brings them into sync. You can conceptualize that as a transition from "not printed" to "printed", if you like.
But that means that from Puppet's perspective, every Notify
resource is changed every time it is applied. That generates an event, which is propagated to the Notify
's container and onward.
This behaviour is unacceptable, so how can I print something to the
puppet agent (puppet agent -t
) without notifying/refreshing
auto-contained resources?
If you must have the messages in the agent's log (as opposed to the master's) then your options are limited. In fact, the best I can come up with is to write a custom resource type and provider that is always in sync, yet emits messages into the log anyway. I tested using an Exec
with an unless
parameter that emits the message, but Puppet does not seem to print the output of the unless
command. Certainly, Notify
is right out.
If it would be sufficient to emit the message into the master's log, then there is a set of functions for that purpose. Among them, notice(), info(), and debug() seem the most likely for your purpose.
Side note: the phrase "auto-contained resources" suggests that there is another kind. Before Puppet 6 you could declare resources at top scope, and those are contained only by the catalog itself, which does not propagate events to anything else. But every resource declared inside a container -- class or defined type -- is contained by that container. That's always seemed very natural to me. Usually the thing that trips people up about containment is that classes are only contained when you explicitly make it so. There are good reasons for that, but I won't go into them here.
add a comment |
This is a limitation inherent in modeling Notify
as a resource. By definition and design, applying a resource does nothing if that resource is initially in sync with the target system. In order that Notify
resources do anything (i.e. emit their message), they are always initially out of sync, and emitting their message brings them into sync. You can conceptualize that as a transition from "not printed" to "printed", if you like.
But that means that from Puppet's perspective, every Notify
resource is changed every time it is applied. That generates an event, which is propagated to the Notify
's container and onward.
This behaviour is unacceptable, so how can I print something to the
puppet agent (puppet agent -t
) without notifying/refreshing
auto-contained resources?
If you must have the messages in the agent's log (as opposed to the master's) then your options are limited. In fact, the best I can come up with is to write a custom resource type and provider that is always in sync, yet emits messages into the log anyway. I tested using an Exec
with an unless
parameter that emits the message, but Puppet does not seem to print the output of the unless
command. Certainly, Notify
is right out.
If it would be sufficient to emit the message into the master's log, then there is a set of functions for that purpose. Among them, notice(), info(), and debug() seem the most likely for your purpose.
Side note: the phrase "auto-contained resources" suggests that there is another kind. Before Puppet 6 you could declare resources at top scope, and those are contained only by the catalog itself, which does not propagate events to anything else. But every resource declared inside a container -- class or defined type -- is contained by that container. That's always seemed very natural to me. Usually the thing that trips people up about containment is that classes are only contained when you explicitly make it so. There are good reasons for that, but I won't go into them here.
add a comment |
This is a limitation inherent in modeling Notify
as a resource. By definition and design, applying a resource does nothing if that resource is initially in sync with the target system. In order that Notify
resources do anything (i.e. emit their message), they are always initially out of sync, and emitting their message brings them into sync. You can conceptualize that as a transition from "not printed" to "printed", if you like.
But that means that from Puppet's perspective, every Notify
resource is changed every time it is applied. That generates an event, which is propagated to the Notify
's container and onward.
This behaviour is unacceptable, so how can I print something to the
puppet agent (puppet agent -t
) without notifying/refreshing
auto-contained resources?
If you must have the messages in the agent's log (as opposed to the master's) then your options are limited. In fact, the best I can come up with is to write a custom resource type and provider that is always in sync, yet emits messages into the log anyway. I tested using an Exec
with an unless
parameter that emits the message, but Puppet does not seem to print the output of the unless
command. Certainly, Notify
is right out.
If it would be sufficient to emit the message into the master's log, then there is a set of functions for that purpose. Among them, notice(), info(), and debug() seem the most likely for your purpose.
Side note: the phrase "auto-contained resources" suggests that there is another kind. Before Puppet 6 you could declare resources at top scope, and those are contained only by the catalog itself, which does not propagate events to anything else. But every resource declared inside a container -- class or defined type -- is contained by that container. That's always seemed very natural to me. Usually the thing that trips people up about containment is that classes are only contained when you explicitly make it so. There are good reasons for that, but I won't go into them here.
This is a limitation inherent in modeling Notify
as a resource. By definition and design, applying a resource does nothing if that resource is initially in sync with the target system. In order that Notify
resources do anything (i.e. emit their message), they are always initially out of sync, and emitting their message brings them into sync. You can conceptualize that as a transition from "not printed" to "printed", if you like.
But that means that from Puppet's perspective, every Notify
resource is changed every time it is applied. That generates an event, which is propagated to the Notify
's container and onward.
This behaviour is unacceptable, so how can I print something to the
puppet agent (puppet agent -t
) without notifying/refreshing
auto-contained resources?
If you must have the messages in the agent's log (as opposed to the master's) then your options are limited. In fact, the best I can come up with is to write a custom resource type and provider that is always in sync, yet emits messages into the log anyway. I tested using an Exec
with an unless
parameter that emits the message, but Puppet does not seem to print the output of the unless
command. Certainly, Notify
is right out.
If it would be sufficient to emit the message into the master's log, then there is a set of functions for that purpose. Among them, notice(), info(), and debug() seem the most likely for your purpose.
Side note: the phrase "auto-contained resources" suggests that there is another kind. Before Puppet 6 you could declare resources at top scope, and those are contained only by the catalog itself, which does not propagate events to anything else. But every resource declared inside a container -- class or defined type -- is contained by that container. That's always seemed very natural to me. Usually the thing that trips people up about containment is that classes are only contained when you explicitly make it so. There are good reasons for that, but I won't go into them here.
edited Nov 16 '18 at 16:55
answered Nov 16 '18 at 16:49
John BollingerJohn Bollinger
79.4k74075
79.4k74075
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53339889%2fpuppet-output-to-agent-without-notify%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown