|
| 1 | +# DNF AppStream Promise Type |
| 2 | + |
| 3 | +A CFEngine custom promise type for managing DNF AppStream modules on RHEL 8+ and compatible systems. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +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. |
| 8 | + |
| 9 | +## Features |
| 10 | + |
| 11 | +- Enable, disable, install, and remove DNF AppStream modules |
| 12 | +- Support for specifying streams and profiles |
| 13 | +- Input validation and sanitization for security |
| 14 | +- Proper error handling and logging |
| 15 | +- Module state checking to avoid unnecessary operations |
| 16 | +- Uses DNF Python API for efficient and secure operations |
| 17 | + |
| 18 | +## Installation |
| 19 | + |
| 20 | +To install this promise type, copy the `dnf_appstream.py` file to your CFEngine masterfiles directory and configure the promise agent: |
| 21 | + |
| 22 | +``` |
| 23 | +promise agent dnf_appstream |
| 24 | +{ |
| 25 | + interpreter => "/usr/bin/python3"; |
| 26 | + path => "$(sys.inputdir)/dnf_appstream.py"; |
| 27 | +} |
| 28 | +``` |
| 29 | + |
| 30 | +## Usage |
| 31 | + |
| 32 | +### Enable a Module |
| 33 | + |
| 34 | +``` |
| 35 | +bundle agent main |
| 36 | +{ |
| 37 | + dnf_appstream: |
| 38 | + "nodejs" |
| 39 | + state => "enabled", |
| 40 | + stream => "12"; |
| 41 | +} |
| 42 | +``` |
| 43 | + |
| 44 | +### Disable a Module |
| 45 | + |
| 46 | +``` |
| 47 | +bundle agent main |
| 48 | +{ |
| 49 | + dnf_appstream: |
| 50 | + "nodejs" |
| 51 | + state => "disabled"; |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +### Install a Module with Profile |
| 56 | + |
| 57 | +``` |
| 58 | +bundle agent main |
| 59 | +{ |
| 60 | + dnf_appstream: |
| 61 | + "python36" |
| 62 | + state => "installed", |
| 63 | + stream => "3.6", |
| 64 | + profile => "minimal"; |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +### Remove a Module |
| 69 | + |
| 70 | +``` |
| 71 | +bundle agent main |
| 72 | +{ |
| 73 | + dnf_appstream: |
| 74 | + "postgresql" |
| 75 | + state => "removed"; |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +## Attributes |
| 80 | + |
| 81 | +The promise type supports the following attributes: |
| 82 | + |
| 83 | +- `state` (required) - Desired state of the module: `enabled`, `disabled`, `installed`, or `removed` (default: `enabled`) |
| 84 | +- `stream` (optional) - Specific stream of the module to use |
| 85 | +- `profile` (optional) - Specific profile of the module to install |
| 86 | + |
| 87 | +## Module States |
| 88 | + |
| 89 | +- `enabled` - The module is enabled and available for installation |
| 90 | +- `disabled` - The module is disabled and not available for installation |
| 91 | +- `installed` - The module is installed with its default profile (implies enabled) |
| 92 | +- `removed` - The module is removed or not installed |
| 93 | + |
| 94 | +Note: The `installed` state implies `enabled` because in DNF's module system, installing a module automatically enables it first. |
| 95 | + |
| 96 | +## Security Features |
| 97 | + |
| 98 | +- Input validation and sanitization |
| 99 | +- Module name validation (alphanumeric, underscore, dot, and dash only) |
| 100 | +- Stream name validation (alphanumeric, underscore, dot, and dash only) |
| 101 | +- Uses DNF Python API for secure operations instead of subprocess calls |
| 102 | +- Proper error handling and timeout management |
| 103 | + |
| 104 | +## Requirements |
| 105 | + |
| 106 | +- CFEngine 3.18 or later |
| 107 | +- Python 3 |
| 108 | +- DNF Python API (python3-dnf package) |
| 109 | +- DNF package manager (RHEL 8+, Fedora, CentOS 8+) |
| 110 | +- AppStream repositories configured |
| 111 | + |
| 112 | +## Examples |
| 113 | + |
| 114 | +### Enable Multiple Modules |
| 115 | + |
| 116 | +``` |
| 117 | +bundle agent enable_development_stack |
| 118 | +{ |
| 119 | + dnf_appstream: |
| 120 | + "nodejs" |
| 121 | + state => "enabled", |
| 122 | + stream => "14"; |
| 123 | +
|
| 124 | + "python36" |
| 125 | + state => "enabled", |
| 126 | + stream => "3.6"; |
| 127 | +
|
| 128 | + "postgresql" |
| 129 | + state => "enabled", |
| 130 | + stream => "12"; |
| 131 | +} |
| 132 | +``` |
| 133 | + |
| 134 | +### Configure Web Server Stack |
| 135 | + |
| 136 | +``` |
| 137 | +bundle agent configure_web_server |
| 138 | +{ |
| 139 | + dnf_appstream: |
| 140 | + "nginx" |
| 141 | + state => "installed", |
| 142 | + stream => "1.14"; |
| 143 | +
|
| 144 | + "php" |
| 145 | + state => "installed", |
| 146 | + stream => "7.4", |
| 147 | + profile => "minimal"; |
| 148 | +} |
| 149 | +``` |
| 150 | + |
| 151 | +### Complete Example with Package Installation |
| 152 | + |
| 153 | +``` |
| 154 | +promise agent dnf_appstream |
| 155 | +{ |
| 156 | + interpreter => "/usr/bin/python3"; |
| 157 | + path => "$(sys.inputdir)/modules/promises/dnf_appstream.py"; |
| 158 | +} |
| 159 | +
|
| 160 | +body package_method dnf |
| 161 | +{ |
| 162 | + package_module => "dnf"; |
| 163 | + package_policy => "present"; |
| 164 | +} |
| 165 | +
|
| 166 | +bundle agent setup_web_server |
| 167 | +{ |
| 168 | + # Enable AppStream modules |
| 169 | + dnf_appstream: |
| 170 | + "nodejs" |
| 171 | + state => "enabled", |
| 172 | + stream => "14"; |
| 173 | +
|
| 174 | + "postgresql" |
| 175 | + state => "installed", |
| 176 | + stream => "12"; |
| 177 | +
|
| 178 | + # Install packages from the enabled modules |
| 179 | + packages: |
| 180 | + # These packages will be installed from the enabled AppStream modules |
| 181 | + "nodejs" package_method => dnf; |
| 182 | + "postgresql-server" package_method => dnf; |
| 183 | + |
| 184 | + # Standard packages |
| 185 | + "nginx" package_method => dnf; |
| 186 | +} |
| 187 | +``` |
0 commit comments