-
Notifications
You must be signed in to change notification settings - Fork 12
CFE-3653: Prototyped dnf_appstream custom promise type #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nickanderson
wants to merge
3
commits into
cfengine:master
Choose a base branch
from
nickanderson:CFE-3635/master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,187 @@ | ||
| # DNF AppStream Promise Type | ||
|
|
||
| A CFEngine custom promise type for managing DNF AppStream modules on RHEL 8+ and compatible systems. | ||
|
|
||
| ## Overview | ||
|
|
||
| The `dnf_appstream` promise type allows you to manage DNF AppStream modules, which are a key feature of RHEL 8+ and compatible systems. AppStreams provide multiple versions of software components that can be enabled or disabled as needed. | ||
|
|
||
| ## Features | ||
|
|
||
| - Enable, disable, install, and remove DNF AppStream modules | ||
| - Support for specifying streams and profiles | ||
| - Input validation and sanitization for security | ||
| - Proper error handling and logging | ||
| - Module state checking to avoid unnecessary operations | ||
| - Uses DNF Python API for efficient and secure operations | ||
|
|
||
| ## Installation | ||
|
|
||
| To install this promise type, copy the `dnf_appstream.py` file to your CFEngine masterfiles directory and configure the promise agent: | ||
|
|
||
| ``` | ||
| promise agent dnf_appstream | ||
| { | ||
| interpreter => "/usr/bin/python3"; | ||
| path => "$(sys.inputdir)/dnf_appstream.py"; | ||
| } | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Enable a Module | ||
|
|
||
| ``` | ||
| bundle agent main | ||
| { | ||
| dnf_appstream: | ||
| "nodejs" | ||
| state => "enabled", | ||
| stream => "12"; | ||
| } | ||
| ``` | ||
|
|
||
| ### Disable a Module | ||
|
|
||
| ``` | ||
| bundle agent main | ||
| { | ||
| dnf_appstream: | ||
| "nodejs" | ||
| state => "disabled"; | ||
| } | ||
| ``` | ||
|
|
||
| ### Install a Module with Profile | ||
|
|
||
| ``` | ||
| bundle agent main | ||
| { | ||
| dnf_appstream: | ||
| "python36" | ||
| state => "installed", | ||
| stream => "3.6", | ||
| profile => "minimal"; | ||
| } | ||
| ``` | ||
|
|
||
| ### Remove a Module | ||
|
|
||
| ``` | ||
| bundle agent main | ||
| { | ||
| dnf_appstream: | ||
| "postgresql" | ||
| state => "removed"; | ||
| } | ||
| ``` | ||
|
|
||
| ## Attributes | ||
|
|
||
| The promise type supports the following attributes: | ||
|
|
||
| - `state` (required) - Desired state of the module: `enabled`, `disabled`, `installed`, or `removed` (default: `enabled`) | ||
| - `stream` (optional) - Specific stream of the module to use | ||
| - `profile` (optional) - Specific profile of the module to install | ||
|
|
||
| ## Module States | ||
|
|
||
| - `enabled` - The module is enabled and available for installation | ||
| - `disabled` - The module is disabled and not available for installation | ||
| - `installed` - The module is installed with its default profile (implies enabled) | ||
| - `removed` - The module is removed or not installed | ||
|
|
||
| Note: The `installed` state implies `enabled` because in DNF's module system, installing a module automatically enables it first. | ||
|
|
||
| ## Security Features | ||
|
|
||
| - Input validation and sanitization | ||
| - Module name validation (alphanumeric, underscore, dot, and dash only) | ||
| - Stream name validation (alphanumeric, underscore, dot, and dash only) | ||
| - Uses DNF Python API for secure operations instead of subprocess calls | ||
| - Proper error handling and timeout management | ||
|
|
||
| ## Requirements | ||
|
|
||
| - CFEngine 3.18 or later | ||
| - Python 3 | ||
| - DNF Python API (python3-dnf package) | ||
| - DNF package manager (RHEL 8+, Fedora, CentOS 8+) | ||
| - AppStream repositories configured | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Enable Multiple Modules | ||
|
|
||
| ``` | ||
| bundle agent enable_development_stack | ||
| { | ||
| dnf_appstream: | ||
| "nodejs" | ||
| state => "enabled", | ||
| stream => "14"; | ||
|
|
||
| "python36" | ||
| state => "enabled", | ||
| stream => "3.6"; | ||
|
|
||
| "postgresql" | ||
| state => "enabled", | ||
| stream => "12"; | ||
| } | ||
| ``` | ||
|
|
||
| ### Configure Web Server Stack | ||
|
|
||
| ``` | ||
| bundle agent configure_web_server | ||
| { | ||
| dnf_appstream: | ||
| "nginx" | ||
| state => "installed", | ||
| stream => "1.14"; | ||
|
|
||
| "php" | ||
| state => "installed", | ||
| stream => "7.4", | ||
| profile => "minimal"; | ||
| } | ||
| ``` | ||
|
|
||
| ### Complete Example with Package Installation | ||
|
|
||
| ``` | ||
| promise agent dnf_appstream | ||
| { | ||
| interpreter => "/usr/bin/python3"; | ||
| path => "$(sys.inputdir)/modules/promises/dnf_appstream.py"; | ||
| } | ||
|
|
||
| body package_method dnf | ||
| { | ||
| package_module => "dnf"; | ||
| package_policy => "present"; | ||
| } | ||
|
|
||
| bundle agent setup_web_server | ||
| { | ||
| # Enable AppStream modules | ||
| dnf_appstream: | ||
| "nodejs" | ||
| state => "enabled", | ||
| stream => "14"; | ||
|
|
||
| "postgresql" | ||
| state => "installed", | ||
| stream => "12"; | ||
|
|
||
| # Install packages from the enabled modules | ||
| packages: | ||
| # These packages will be installed from the enabled AppStream modules | ||
| "nodejs" package_method => dnf; | ||
| "postgresql-server" package_method => dnf; | ||
|
|
||
| # Standard packages | ||
| "nginx" package_method => dnf; | ||
| } | ||
| ``` |
This file contains hidden or 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,21 @@ | ||
| { | ||
| "name": "dnf_appstream", | ||
| "type": "promise-type", | ||
| "description": "A custom promise type to manage DNF AppStream modules", | ||
| "tags": ["dnf", "appstream", "modules", "package management", "redhat", "fedora", "centos"], | ||
| "files": [ | ||
| { | ||
| "path": "promise-types/dnf_appstream/dnf_appstream.py", | ||
| "type": "source", | ||
| "permissions": "644" | ||
| }, | ||
| { | ||
| "path": "promise-types/dnf_appstream/README.md", | ||
| "type": "documentation", | ||
| "permissions": "644" | ||
| } | ||
| ], | ||
| "dependencies": [], | ||
| "test_command": "python3 test_dnf_appstream.py", | ||
| "version": "0.0.1" | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.