Skip to content

Commit 326cad0

Browse files
author
rhel-9-sm-tenant root
committed
Added deb_package to manage debian packages - #231
1 parent d2bcb49 commit 326cad0

12 files changed

Lines changed: 76879 additions & 0 deletions

meta/runtime.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ action_groups:
1414
- container_repository
1515
- container_sync
1616
- deb_distribution
17+
- deb_package
1718
- deb_publication
1819
- deb_remote
1920
- deb_repository

plugins/modules/deb_package.py

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
#!/usr/bin/python
2+
3+
# copyright (c) 2026, Chris Taylor
4+
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
5+
6+
7+
DOCUMENTATION = r"""
8+
---
9+
module: deb_package
10+
short_description: Manage deb packages of a pulp api server instance
11+
description:
12+
- "This performs Create/Read/Remove operations on deb packages in the context of a repository."
13+
options:
14+
sha256:
15+
description:
16+
- sha256 digest of the deb package content to query or manipulate
17+
type: str
18+
aliases:
19+
- digest
20+
file:
21+
description:
22+
- A path to a file to be uploaded as the new package.
23+
- Alternatively this is used to calculate the checksum of the file to be removed.
24+
type: path
25+
chunk_size:
26+
description:
27+
- Chunk size in bytes used to upload the file.
28+
type: int
29+
default: 33554432
30+
repository:
31+
description:
32+
- The repository in which the content should be present or absent.
33+
type: str
34+
extends_documentation_fragment:
35+
- pulp.squeezer.pulp.entity_state
36+
- pulp.squeezer.pulp
37+
author:
38+
- Chris Taylor (@chtaylo2)
39+
- Jacob Floyd (@cognifloyd)
40+
- Daniel Ziegenberg (@ziegenberg)
41+
- Matthias Dellweg (@mdellweg)
42+
"""
43+
44+
EXAMPLES = r"""
45+
- name: "Read list of deb packages from pulp api server"
46+
deb_package:
47+
api_url: "localhost:24817"
48+
username: "admin"
49+
password: "password"
50+
register: "content_status"
51+
- name: "Report pulp deb packages"
52+
debug:
53+
var: "content_status"
54+
- name: "Create a deb package"
55+
deb_package:
56+
api_url: "localhost:24817"
57+
username: "admin"
58+
password: "password"
59+
sha256: "0000111122223333444455556666777788889999aaaabbbbccccddddeeeeffff"
60+
file: "data/important_package.deb"
61+
repository: "target_repository"
62+
state: "present"
63+
"""
64+
65+
RETURN = r"""
66+
packages:
67+
description: "List of deb packages"
68+
type: "list"
69+
returned: "when digest and file are not given"
70+
package:
71+
description: "The deb package details"
72+
type: "dict"
73+
returned: "when digest or file are given"
74+
"""
75+
76+
import os
77+
import traceback
78+
79+
from ansible_collections.pulp.squeezer.plugins.module_utils.pulp_glue import (
80+
PulpEntityAnsibleModule,
81+
SqueezerException,
82+
)
83+
84+
try:
85+
from pulp_glue.deb.context import PulpAptRepositoryContext, PulpDebPackageContext
86+
87+
PULP_GLUE_IMPORT_ERR = None
88+
89+
except ImportError:
90+
PULP_GLUE_IMPORT_ERR = traceback.format_exc()
91+
PulpDebPackageContext = None
92+
93+
94+
def main():
95+
with PulpEntityAnsibleModule(
96+
context_class=PulpDebPackageContext,
97+
entity_singular="package",
98+
entity_plural="packages",
99+
import_errors=[("pulp-glue-deb", PULP_GLUE_IMPORT_ERR)],
100+
argument_spec={
101+
"sha256": {"aliases": ["digest"]},
102+
"file": {"type": "path"},
103+
"chunk_size": {"type": "int", "default": 33554432},
104+
"repository": {},
105+
},
106+
required_if=[
107+
("state", "present", ["file", "repository"]),
108+
("state", "absesent", ["repository"]),
109+
],
110+
) as module:
111+
sha256 = module.params["sha256"]
112+
if module.params["file"]:
113+
if not os.path.exists(module.params["file"]):
114+
raise SqueezerException("File not found.")
115+
file_sha256 = module.sha256(module.params["file"])
116+
if sha256:
117+
if sha256 != file_sha256:
118+
raise SqueezerException("File checksum mismatch.")
119+
else:
120+
sha256 = file_sha256
121+
122+
if sha256 is None and module.state == "absent":
123+
raise SqueezerException(
124+
"One of 'file' and 'sha256' is required if 'state' is 'absent'."
125+
)
126+
127+
natural_key = {
128+
"sha256": sha256,
129+
}
130+
desired_attributes = {}
131+
defaults = {
132+
"file": module.params["file"],
133+
"chunk_size": module.params["chunk_size"],
134+
}
135+
136+
if module.params["repository"]:
137+
module.context.repository_ctx = PulpAptRepositoryContext(
138+
module.pulp_ctx, entity={"name": module.params["repository"]}
139+
)
140+
141+
module.process(natural_key, desired_attributes, defaults=defaults)
142+
143+
144+
if __name__ == "__main__":
145+
main()

tests/fixtures/deb_package-0.yml

Lines changed: 75670 additions & 0 deletions
Large diffs are not rendered by default.

tests/fixtures/deb_package-1.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
? !!python/object/apply:multidict._multidict.istr
6+
- Accept
7+
: - application/json
8+
Accept-Encoding:
9+
- gzip, deflate, zstd
10+
Connection:
11+
- keep-alive
12+
? !!python/object/apply:multidict._multidict.istr
13+
- User-Agent
14+
: - Squeezer/0.5.0-dev
15+
method: GET
16+
uri: http://pulp.example.org/pulp/api/v3/repositories/deb/apt/?name=test_deb_repository&offset=0&limit=1
17+
response:
18+
body:
19+
string: '{"count":1,"next":null,"previous":null,"results":[{"pulp_href":"/pulp/api/v3/repositories/deb/apt/019eb35f-17ba-708e-b988-38a74aba420b/","prn":"prn:deb.aptrepository:019eb35f-17ba-708e-b988-38a74aba420b","pulp_created":"2026-06-10T21:10:14.203257Z","pulp_last_updated":"2026-06-10T21:10:24.221402Z","versions_href":"/pulp/api/v3/repositories/deb/apt/019eb35f-17ba-708e-b988-38a74aba420b/versions/","pulp_labels":{},"latest_version_href":"/pulp/api/v3/repositories/deb/apt/019eb35f-17ba-708e-b988-38a74aba420b/versions/1/","name":"test_deb_repository","description":null,"retain_repo_versions":null,"remote":null,"autopublish":false,"publish_upstream_release_fields":true,"signing_service":null,"signing_service_release_overrides":{}}]}'
20+
headers:
21+
Access-Control-Expose-Headers:
22+
- Correlation-ID
23+
Allow:
24+
- GET, POST, HEAD, OPTIONS
25+
Connection:
26+
- keep-alive
27+
Content-Length:
28+
- '735'
29+
Content-Type:
30+
- application/json
31+
Correlation-ID:
32+
- ec83e8ea56d849059f0743968bff1546
33+
Cross-Origin-Opener-Policy:
34+
- same-origin
35+
Date:
36+
- Wed, 10 Jun 2026 21:10:27 GMT
37+
Referrer-Policy:
38+
- same-origin
39+
Server:
40+
- nginx/1.22.1
41+
Vary:
42+
- Accept
43+
X-Content-Type-Options:
44+
- nosniff
45+
X-Frame-Options:
46+
- DENY
47+
status:
48+
code: 200
49+
message: OK
50+
- request:
51+
body: null
52+
headers:
53+
? !!python/object/apply:multidict._multidict.istr
54+
- Accept
55+
: - application/json
56+
Accept-Encoding:
57+
- gzip, deflate, zstd
58+
Connection:
59+
- keep-alive
60+
? !!python/object/apply:multidict._multidict.istr
61+
- Correlation-Id
62+
: - ec83e8ea56d849059f0743968bff1546
63+
? !!python/object/apply:multidict._multidict.istr
64+
- User-Agent
65+
: - Squeezer/0.5.0-dev
66+
method: GET
67+
uri: http://pulp.example.org/pulp/api/v3/content/deb/packages/?sha256=eb061a19af924d0add800ea5c86546d125f96454b45e60a541c205bdba5f6f6b&repository_version=%2Fpulp%2Fapi%2Fv3%2Frepositories%2Fdeb%2Fapt%2F019eb35f-17ba-708e-b988-38a74aba420b%2Fversions%2F1%2F&offset=0&limit=1
68+
response:
69+
body:
70+
string: '{"count":1,"next":null,"previous":null,"results":[{"pulp_href":"/pulp/api/v3/content/deb/packages/019eb35f-3e94-7214-8036-d77c4dfeba21/","prn":"prn:deb.package:019eb35f-3e94-7214-8036-d77c4dfeba21","pulp_created":"2026-06-10T21:10:24.153728Z","pulp_last_updated":"2026-06-10T21:10:24.153749Z","pulp_labels":{},"vuln_report":null,"artifact":"/pulp/api/v3/artifacts/019eb35f-3dbf-7b1f-ae8f-d456872442cd/","relative_path":"pool/g/geirrodr/geirrodr_1.0_armeb.deb","md5":null,"sha1":null,"sha224":"4e7f5641b0c912087fdc42a99aa3226c984f38dc169f8387e4d36622","sha256":"eb061a19af924d0add800ea5c86546d125f96454b45e60a541c205bdba5f6f6b","sha384":"e44ba9043b39e09f7c086178e0fd51ef6bc61bcd40f6fb80d308b2e6cf025d34167f73906289dc771059813acae432af","sha512":"6adf58df1e40469bac2a7ee2cb170c0aba7eab4ec3596250258b2bb15ab184165d85450d486d0f7ada1552c2bef5b06377049b8894417e8bd92c08f7f8785afc","package":"geirrodr","source":null,"version":"1.0","architecture":"armeb","section":"misc","priority":"optional","origin":null,"tag":null,"bugs":null,"essential":null,"build_essential":null,"installed_size":"9","maintainer":"Equivs
71+
Dummy Package Generator <root@bd208d733cce>","original_maintainer":null,"description":"Geirrodr\n
72+
Geirrodr was a jotunn and the father of the giantesses Gjalp and Greip.","description_md5":null,"homepage":null,"built_using":null,"auto_built_package":null,"multi_arch":"foreign","breaks":null,"conflicts":null,"depends":null,"recommends":null,"suggests":null,"enhances":null,"pre_depends":null,"provides":null,"replaces":null}]}'
73+
headers:
74+
Access-Control-Expose-Headers:
75+
- Correlation-ID
76+
Allow:
77+
- GET, POST, HEAD, OPTIONS
78+
Connection:
79+
- keep-alive
80+
Content-Length:
81+
- '1534'
82+
Content-Type:
83+
- application/json
84+
Correlation-ID:
85+
- ec83e8ea56d849059f0743968bff1546
86+
Cross-Origin-Opener-Policy:
87+
- same-origin
88+
Date:
89+
- Wed, 10 Jun 2026 21:10:27 GMT
90+
Referrer-Policy:
91+
- same-origin
92+
Server:
93+
- nginx/1.22.1
94+
Vary:
95+
- Accept
96+
X-Content-Type-Options:
97+
- nosniff
98+
X-Frame-Options:
99+
- DENY
100+
status:
101+
code: 200
102+
message: OK
103+
version: 1

0 commit comments

Comments
 (0)