forked from Normation/ncf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
##################################################################################### | ||
# Copyright 2016 Normation SAS | ||
##################################################################################### | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, Version 3. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
##################################################################################### | ||
|
||
# There is 3 ways to have a promise dry-runned: | ||
# - set the global_dry_run class (this one is not set by ncf) | ||
# - call set_dry_run_mode() | ||
# - set a <promise_type>_dry_run class to make only this promise type to be dry-runned | ||
|
||
# @parameter mode The dry-run mode, "true" to enable dry-run-mode and "false" to disable it | ||
# | ||
# WARNING: | ||
# WARNING: Be carefull to have a different promiser content for each call to this method! | ||
# WARNING: | ||
# WARNING: The bodies defined here are used when no action body is specified in a promise. | ||
# WARNING: All ncf action bodies check the two global dry-run classes and prevent any modification | ||
# WARNING: when one of them if defined. This also means that: | ||
# WARNING: | ||
# WARNING: * You need to check for them in all of your custom bodies | ||
# WARNING: * promise type specific dry-run is NOT considered by action bodies, and will be overriden | ||
# WARNING: when using any action body. | ||
# WARNING: | ||
bundle agent set_dry_run_mode(mode) | ||
{ | ||
classes: | ||
# double negation, so that the default is dry_run (in case of error) | ||
"unset_mode" expression => strcmp("${mode}", "false"); | ||
"pass3" expression => "pass2"; | ||
"pass2" expression => "pass1"; | ||
"pass1" expression => "any"; | ||
|
||
pass3.!unset_mode | ||
# wait for pass3 to be able to display the report before | ||
# then abort agent execution | ||
"abort_agent_run" expression => "any"; | ||
|
||
reports: | ||
pass2.!unset_mode:: | ||
"${configuration.fatal} Dry-run mode is not compatible with this agent. Stopping immediately not to prevent any unwanted change." | ||
action => immediate; | ||
pass2.debug.unset_mode:: | ||
"${configuration.debug} Dry-run mode is not compatible with this agent, but only a disabling of dry-run has been requested. Ignoring."; | ||
} |