| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
from __future__ import absolute_import, division, print_function |
| 19 |
__metaclass__ = type |
| 20 |
|
| 21 |
|
| 22 |
DOCUMENTATION = ''' |
| 23 |
--- |
| 24 |
module: repository |
| 25 |
version_added: 1.0.0 |
| 26 |
short_description: Manage Repositories |
| 27 |
description: |
| 28 |
- Create and manage repositories |
| 29 |
author: "Eric D Helms (@ehelms)" |
| 30 |
notes: |
| 31 |
- You can configure certain aspects of existing Red Hat Repositories (like I(download_policy)) using this module, |
| 32 |
but you can't create (enable) or delete (disable) them. |
| 33 |
- If you want to enable or disable Red Hat Repositories available through your subscription, |
| 34 |
please use the M(theforeman.foreman.repository_set) module instead. |
| 35 |
options: |
| 36 |
name: |
| 37 |
description: |
| 38 |
- Name of the repository |
| 39 |
required: true |
| 40 |
type: str |
| 41 |
description: |
| 42 |
description: |
| 43 |
- Description of the repository |
| 44 |
required: false |
| 45 |
type: str |
| 46 |
product: |
| 47 |
description: |
| 48 |
- Product to which the repository lives in |
| 49 |
required: true |
| 50 |
type: str |
| 51 |
label: |
| 52 |
description: |
| 53 |
- label of the repository |
| 54 |
type: str |
| 55 |
content_type: |
| 56 |
description: |
| 57 |
- The content type of the repository |
| 58 |
required: true |
| 59 |
choices: |
| 60 |
- deb |
| 61 |
- docker |
| 62 |
- file |
| 63 |
- ostree |
| 64 |
- puppet |
| 65 |
- yum |
| 66 |
- ansible_collection |
| 67 |
- python |
| 68 |
type: str |
| 69 |
url: |
| 70 |
description: |
| 71 |
- Repository URL to sync from |
| 72 |
required: false |
| 73 |
type: str |
| 74 |
ignore_global_proxy: |
| 75 |
description: |
| 76 |
- Whether content sync should use or ignore the global http proxy setting |
| 77 |
- This is deprecated with Katello 3.13 |
| 78 |
- It has been superseeded by I(http_proxy_policy) |
| 79 |
required: false |
| 80 |
type: bool |
| 81 |
http_proxy_policy: |
| 82 |
description: |
| 83 |
- Which proxy to use for content synching |
| 84 |
choices: |
| 85 |
- global_default_http_proxy |
| 86 |
- none |
| 87 |
- use_selected_http_proxy |
| 88 |
required: false |
| 89 |
type: str |
| 90 |
http_proxy: |
| 91 |
description: |
| 92 |
- Name of the http proxy to use for content synching |
| 93 |
- Should be combined with I(http_proxy_policy='use_selected_http_proxy') |
| 94 |
required: false |
| 95 |
type: str |
| 96 |
gpg_key: |
| 97 |
description: |
| 98 |
- Repository GPG key |
| 99 |
required: false |
| 100 |
type: str |
| 101 |
ssl_ca_cert: |
| 102 |
description: |
| 103 |
- Repository SSL CA certificate |
| 104 |
required: false |
| 105 |
type: str |
| 106 |
ssl_client_cert: |
| 107 |
description: |
| 108 |
- Repository SSL client certificate |
| 109 |
required: false |
| 110 |
type: str |
| 111 |
ssl_client_key: |
| 112 |
description: |
| 113 |
- Repository SSL client private key |
| 114 |
required: false |
| 115 |
type: str |
| 116 |
download_concurrency: |
| 117 |
description: |
| 118 |
- download concurrency for sync from upstream |
| 119 |
- as the API does not return this value, this will break idempotence for this module |
| 120 |
required: false |
| 121 |
type: int |
| 122 |
version_added: 3.0.0 |
| 123 |
download_policy: |
| 124 |
description: |
| 125 |
- The download policy for sync from upstream. |
| 126 |
- The download policy C(background) is deprecated and not available since Katello 4.3. |
| 127 |
choices: |
| 128 |
- background |
| 129 |
- immediate |
| 130 |
- on_demand |
| 131 |
required: false |
| 132 |
type: str |
| 133 |
mirror_on_sync: |
| 134 |
description: |
| 135 |
- toggle "mirror on sync" where the state of the repository mirrors that of the upstream repository at sync time |
| 136 |
- This is deprecated with Katello 4.3 |
| 137 |
- It has been superseeded by I(mirroring_policy=mirror_content_only) |
| 138 |
type: bool |
| 139 |
required: false |
| 140 |
mirroring_policy: |
| 141 |
description: |
| 142 |
- Policy to set for mirroring content |
| 143 |
- Supported since Katello 4.3 |
| 144 |
type: str |
| 145 |
choices: |
| 146 |
- additive |
| 147 |
- mirror_content_only |
| 148 |
- mirror_complete |
| 149 |
verify_ssl_on_sync: |
| 150 |
description: |
| 151 |
- verify the upstream certifcates are signed by a trusted CA |
| 152 |
type: bool |
| 153 |
required: false |
| 154 |
upstream_username: |
| 155 |
description: |
| 156 |
- username to access upstream repository |
| 157 |
type: str |
| 158 |
upstream_password: |
| 159 |
description: |
| 160 |
- Password to access upstream repository. |
| 161 |
- When this parameter is set, the module will not be idempotent. |
| 162 |
type: str |
| 163 |
docker_upstream_name: |
| 164 |
description: |
| 165 |
- name of the upstream docker repository |
| 166 |
- only available for I(content_type=docker) |
| 167 |
type: str |
| 168 |
docker_tags_whitelist: |
| 169 |
description: |
| 170 |
- list of tags to sync for Container Image repository |
| 171 |
- only available for I(content_type=docker) |
| 172 |
- Deprecated since Katello 4.4 |
| 173 |
type: list |
| 174 |
elements: str |
| 175 |
deb_releases: |
| 176 |
description: |
| 177 |
- comma separated list of releases to be synced from deb-archive |
| 178 |
- only available for I(content_type=deb) |
| 179 |
type: str |
| 180 |
deb_components: |
| 181 |
description: |
| 182 |
- comma separated list of repo components to be synced from deb-archive |
| 183 |
- only available for I(content_type=deb) |
| 184 |
type: str |
| 185 |
deb_architectures: |
| 186 |
description: |
| 187 |
- comma separated list of architectures to be synced from deb-archive |
| 188 |
- only available for I(content_type=deb) |
| 189 |
type: str |
| 190 |
deb_errata_url: |
| 191 |
description: |
| 192 |
- URL to sync Debian or Ubuntu errata information from |
| 193 |
- only available on Orcharhino |
| 194 |
- only available for I(content_type=deb) |
| 195 |
type: str |
| 196 |
required: false |
| 197 |
unprotected: |
| 198 |
description: |
| 199 |
- publish the repository via HTTP |
| 200 |
type: bool |
| 201 |
required: false |
| 202 |
checksum_type: |
| 203 |
description: |
| 204 |
- Checksum of the repository |
| 205 |
type: str |
| 206 |
required: false |
| 207 |
choices: |
| 208 |
- sha1 |
| 209 |
- sha256 |
| 210 |
ignorable_content: |
| 211 |
description: |
| 212 |
- List of content units to ignore while syncing a yum repository. |
| 213 |
- Must be subset of rpm,drpm,srpm,distribution,erratum. |
| 214 |
type: list |
| 215 |
elements: str |
| 216 |
required: false |
| 217 |
ansible_collection_requirements: |
| 218 |
description: |
| 219 |
- Contents of requirement yaml file to sync from URL |
| 220 |
type: str |
| 221 |
required: false |
| 222 |
auto_enabled: |
| 223 |
description: |
| 224 |
- repositories will be automatically enabled on a registered host subscribed to this product |
| 225 |
type: bool |
| 226 |
required: false |
| 227 |
os_versions: |
| 228 |
description: |
| 229 |
- Identifies whether the repository should be disabled on a client with a non-matching OS version. |
| 230 |
- A maximum of one OS version can be selected. |
| 231 |
- Set to C([]) to disable filtering again. |
| 232 |
type: list |
| 233 |
elements: str |
| 234 |
required: false |
| 235 |
choices: |
| 236 |
- rhel-6 |
| 237 |
- rhel-7 |
| 238 |
- rhel-8 |
| 239 |
- rhel-9 |
| 240 |
- rhel-10 |
| 241 |
arch: |
| 242 |
description: |
| 243 |
- Architecture of content in the repository |
| 244 |
- Set to C(noarch) to disable the architecture restriction again. |
| 245 |
type: str |
| 246 |
required: false |
| 247 |
include_tags: |
| 248 |
description: |
| 249 |
- List of tags to sync for a container image repository. |
| 250 |
type: list |
| 251 |
elements: str |
| 252 |
required: false |
| 253 |
version_added: 3.7.0 |
| 254 |
exclude_tags: |
| 255 |
description: |
| 256 |
- List of tags to exclude when syncing a container image repository. |
| 257 |
type: list |
| 258 |
elements: str |
| 259 |
required: false |
| 260 |
version_added: 3.7.0 |
| 261 |
retain_package_versions_count: |
| 262 |
description: |
| 263 |
- The maximum number of versions of each package to keep. |
| 264 |
type: int |
| 265 |
required: false |
| 266 |
version_added: 5.4.0 |
| 267 |
metadata_expire: |
| 268 |
description: |
| 269 |
- Set the metadata expiration time (in seconds) for a yum repository. |
| 270 |
type: int |
| 271 |
required: false |
| 272 |
version_added: 5.4.0 |
| 273 |
ansible_collection_auth_token: |
| 274 |
description: |
| 275 |
- The token key to use for authentication. |
| 276 |
type: str |
| 277 |
required: false |
| 278 |
version_added: 5.5.0 |
| 279 |
ansible_collection_auth_url: |
| 280 |
description: |
| 281 |
- The URL to receive a session token from, e.g. used with Automation Hub. |
| 282 |
type: str |
| 283 |
required: false |
| 284 |
version_added: 5.5.0 |
| 285 |
depth: |
| 286 |
description: |
| 287 |
- An option to specify how many ostree commits to traverse. |
| 288 |
type: int |
| 289 |
required: false |
| 290 |
version_added: 5.5.0 |
| 291 |
exclude_refs: |
| 292 |
description: |
| 293 |
- List of tags to exclude during an ostree sync. |
| 294 |
- The wildcards C(*), C(?) are recognized. |
| 295 |
- C(exclude_refs) is evaluated after C(include_refs). |
| 296 |
type: list |
| 297 |
elements: str |
| 298 |
required: false |
| 299 |
version_added: 5.5.0 |
| 300 |
excludes: |
| 301 |
description: |
| 302 |
- Python packages to exclude from the upstream URL. |
| 303 |
- "You may also specify versions, for example: C(django~=2.0)." |
| 304 |
type: list |
| 305 |
elements: str |
| 306 |
required: false |
| 307 |
version_added: 5.5.0 |
| 308 |
include_refs: |
| 309 |
description: |
| 310 |
- List of refs to include during an ostree sync. |
| 311 |
- The wildcards C(*), C(?) are recognized. |
| 312 |
type: list |
| 313 |
elements: str |
| 314 |
required: false |
| 315 |
version_added: 5.5.0 |
| 316 |
includes: |
| 317 |
description: |
| 318 |
- Python packages to include from the upstream URL, |
| 319 |
- "You may also specify versions, for example: C(django~=2.0)." |
| 320 |
- Leave empty to include every package. |
| 321 |
type: list |
| 322 |
elements: str |
| 323 |
required: false |
| 324 |
version_added: 5.5.0 |
| 325 |
keep_latest_packages: |
| 326 |
description: |
| 327 |
- The amount of latest versions of a package to keep on sync, includes pre-releases if synced. |
| 328 |
- Defaults to keep all versions. |
| 329 |
type: int |
| 330 |
required: false |
| 331 |
version_added: 5.5.0 |
| 332 |
package_types: |
| 333 |
description: |
| 334 |
- Package types to sync for Python content, separated by comma. FIXME |
| 335 |
- Leave empty to get every package type. |
| 336 |
choices: |
| 337 |
- bdist_dmg |
| 338 |
- bdist_dumb |
| 339 |
- bdist_egg |
| 340 |
- bdist_msi |
| 341 |
- bdist_rpm |
| 342 |
- bdist_wheel |
| 343 |
- bdist_wininst |
| 344 |
- sdist |
| 345 |
type: list |
| 346 |
elements: str |
| 347 |
required: false |
| 348 |
version_added: 5.5.0 |
| 349 |
upstream_authentication_token: |
| 350 |
description: |
| 351 |
- Upstream authentication token string for yum repositories. |
| 352 |
type: str |
| 353 |
required: false |
| 354 |
version_added: 5.5.0 |
| 355 |
|
| 356 |
extends_documentation_fragment: |
| 357 |
- theforeman.foreman.foreman |
| 358 |
- theforeman.foreman.foreman.entity_state_with_defaults |
| 359 |
- theforeman.foreman.foreman.organization |
| 360 |
''' |
| 361 |
|
| 362 |
EXAMPLES = ''' |
| 363 |
- name: "Create repository" |
| 364 |
theforeman.foreman.repository: |
| 365 |
username: "admin" |
| 366 |
password: "changeme" |
| 367 |
server_url: "https://foreman.example.com" |
| 368 |
name: "My repository" |
| 369 |
state: present |
| 370 |
content_type: "yum" |
| 371 |
product: "My Product" |
| 372 |
organization: "Default Organization" |
| 373 |
url: "http://yum.theforeman.org/plugins/latest/el7/x86_64/" |
| 374 |
mirror_on_sync: true |
| 375 |
download_policy: immediate |
| 376 |
|
| 377 |
- name: "Create repository with content credentials" |
| 378 |
theforeman.foreman.repository: |
| 379 |
username: "admin" |
| 380 |
password: "changeme" |
| 381 |
server_url: "https://foreman.example.com" |
| 382 |
name: "My repository 2" |
| 383 |
state: present |
| 384 |
content_type: "yum" |
| 385 |
product: "My Product" |
| 386 |
organization: "Default Organization" |
| 387 |
url: "http://yum.theforeman.org/releases/latest/el7/x86_64/" |
| 388 |
download_policy: on_demand |
| 389 |
mirror_on_sync: true |
| 390 |
gpg_key: RPM-GPG-KEY-my-product2 |
| 391 |
''' |
| 392 |
|
| 393 |
RETURN = ''' |
| 394 |
entity: |
| 395 |
description: Final state of the affected entities grouped by their type. |
| 396 |
returned: success |
| 397 |
type: dict |
| 398 |
contains: |
| 399 |
repositories: |
| 400 |
description: List of repositories. |
| 401 |
type: list |
| 402 |
elements: dict |
| 403 |
''' |
| 404 |
|
| 405 |
|
| 406 |
from ansible_collections.theforeman.foreman.plugins.module_utils.foreman_helper import KatelloEntityAnsibleModule |
| 407 |
|
| 408 |
|
| 409 |
class KatelloRepositoryModule(KatelloEntityAnsibleModule): |
| 410 |
pass |
| 411 |
|
| 412 |
|
| 413 |
def main(): |
| 414 |
module = KatelloRepositoryModule( |
| 415 |
foreman_spec=dict( |
| 416 |
product=dict(type='entity', scope=['organization'], required=True), |
| 417 |
label=dict(), |
| 418 |
name=dict(required=True), |
| 419 |
content_type=dict(required=True, choices=['docker', 'ostree', 'yum', 'puppet', 'file', 'deb', 'ansible_collection', 'python']), |
| 420 |
url=dict(), |
| 421 |
ignore_global_proxy=dict(type='bool'), |
| 422 |
http_proxy_policy=dict(choices=['global_default_http_proxy', 'none', 'use_selected_http_proxy']), |
| 423 |
http_proxy=dict(type='entity'), |
| 424 |
gpg_key=dict(type='entity', resource_type='content_credentials', scope=['organization'], no_log=False), |
| 425 |
ssl_ca_cert=dict(type='entity', resource_type='content_credentials', scope=['organization']), |
| 426 |
ssl_client_cert=dict(type='entity', resource_type='content_credentials', scope=['organization']), |
| 427 |
ssl_client_key=dict(type='entity', resource_type='content_credentials', scope=['organization'], no_log=False), |
| 428 |
download_policy=dict(choices=['background', 'immediate', 'on_demand']), |
| 429 |
download_concurrency=dict(type='int'), |
| 430 |
mirror_on_sync=dict(type='bool'), |
| 431 |
mirroring_policy=dict(type='str', choices=['additive', 'mirror_content_only', 'mirror_complete']), |
| 432 |
verify_ssl_on_sync=dict(type='bool'), |
| 433 |
upstream_username=dict(), |
| 434 |
upstream_password=dict(no_log=True), |
| 435 |
docker_upstream_name=dict(), |
| 436 |
docker_tags_whitelist=dict(type='list', elements='str'), |
| 437 |
deb_errata_url=dict(), |
| 438 |
deb_releases=dict(), |
| 439 |
deb_components=dict(), |
| 440 |
deb_architectures=dict(), |
| 441 |
description=dict(), |
| 442 |
unprotected=dict(type='bool'), |
| 443 |
checksum_type=dict(choices=['sha1', 'sha256']), |
| 444 |
ignorable_content=dict(type='list', elements='str'), |
| 445 |
ansible_collection_requirements=dict(), |
| 446 |
auto_enabled=dict(type='bool'), |
| 447 |
os_versions=dict(type='list', elements='str', choices=['rhel-6', 'rhel-7', 'rhel-8', 'rhel-9', 'rhel-10']), |
| 448 |
arch=dict(), |
| 449 |
include_tags=dict(type='list', elements='str'), |
| 450 |
exclude_tags=dict(type='list', elements='str'), |
| 451 |
retain_package_versions_count=dict(type='int'), |
| 452 |
metadata_expire=dict(type="int"), |
| 453 |
ansible_collection_auth_token=dict(no_log=True), |
| 454 |
ansible_collection_auth_url=dict(), |
| 455 |
depth=dict(type='int'), |
| 456 |
exclude_refs=dict(type='list', elements='str'), |
| 457 |
excludes=dict(type='list', elements='str'), |
| 458 |
include_refs=dict(type='list', elements='str'), |
| 459 |
includes=dict(type='list', elements='str'), |
| 460 |
keep_latest_packages=dict(type='int'), |
| 461 |
package_types=dict(type='list', elements='str', |
| 462 |
choices=['bdist_dmg', 'bdist_dumb', 'bdist_egg', 'bdist_msi', 'bdist_rpm', 'bdist_wheel', 'bdist_wininst', 'sdist']), |
| 463 |
upstream_authentication_token=dict(no_log=True), |
| 464 |
), |
| 465 |
mutually_exclusive=[ |
| 466 |
['mirror_on_sync', 'mirroring_policy'] |
| 467 |
], |
| 468 |
argument_spec=dict( |
| 469 |
state=dict(default='present', choices=['present_with_defaults', 'present', 'absent']), |
| 470 |
), |
| 471 |
entity_opts={'scope': ['product']}, |
| 472 |
) |
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
module.foreman_spec['entity']['scope'].remove('organization') |
| 477 |
|
| 478 |
if module.foreman_params['content_type'] != 'docker': |
| 479 |
invalid_list = [key for key in ['docker_upstream_name', 'docker_tags_whitelist', 'include_tags', 'exclude_tags'] if key in module.foreman_params] |
| 480 |
if invalid_list: |
| 481 |
module.fail_json(msg="({0}) can only be used with content_type 'docker'".format(",".join(invalid_list))) |
| 482 |
|
| 483 |
if module.foreman_params['content_type'] != 'deb': |
| 484 |
invalid_list = [key for key in ['deb_errata_url', 'deb_releases', 'deb_components', 'deb_architectures'] if key in module.foreman_params] |
| 485 |
if invalid_list: |
| 486 |
module.fail_json(msg="({0}) can only be used with content_type 'deb'".format(",".join(invalid_list))) |
| 487 |
|
| 488 |
if module.foreman_params['content_type'] != 'ansible_collection': |
| 489 |
invalid_list = [ |
| 490 |
key for key in ['ansible_collection_requirements', 'ansible_collection_auth_token', 'ansible_collection_auth_url'] if key in module.foreman_params |
| 491 |
] |
| 492 |
if invalid_list: |
| 493 |
module.fail_json(msg="({0}) can only be used with content_type 'ansible_collection'".format(",".join(invalid_list))) |
| 494 |
|
| 495 |
if module.foreman_params['content_type'] != 'yum': |
| 496 |
invalid_list = [key for key in ['ignorable_content', 'os_versions', 'metadata_expire', 'upstream_authentication_token'] if key in module.foreman_params] |
| 497 |
if invalid_list: |
| 498 |
module.fail_json(msg="({0}) can only be used with content_type 'yum'".format(",".join(invalid_list))) |
| 499 |
|
| 500 |
if module.foreman_params['content_type'] != 'ostree': |
| 501 |
invalid_list = [key for key in ['depth', 'exclude_refs', 'include_refs'] if key in module.foreman_params] |
| 502 |
if invalid_list: |
| 503 |
module.fail_json(msg="({0}) can only be used with content_type 'ostree'".format(",".join(invalid_list))) |
| 504 |
|
| 505 |
if module.foreman_params['content_type'] != 'python': |
| 506 |
invalid_list = [key for key in ['excludes', 'includes', 'package_types', 'keep_latest_packages'] if key in module.foreman_params] |
| 507 |
if invalid_list: |
| 508 |
module.fail_json(msg="({0}) can only be used with content_type 'python'".format(",".join(invalid_list))) |
| 509 |
|
| 510 |
if 'ignore_global_proxy' in module.foreman_params and 'http_proxy_policy' not in module.foreman_params: |
| 511 |
module.foreman_params['http_proxy_policy'] = 'none' if module.foreman_params['ignore_global_proxy'] else 'global_default_http_proxy' |
| 512 |
|
| 513 |
with module.api_connection(): |
| 514 |
if not module.desired_absent: |
| 515 |
module.auto_lookup_entities() |
| 516 |
module.foreman_params.pop('organization') |
| 517 |
module.run() |
| 518 |
|
| 519 |
|
| 520 |
if __name__ == '__main__': |
| 521 |
main() |