-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathdeb_remote.py
More file actions
169 lines (153 loc) · 4.37 KB
/
deb_remote.py
File metadata and controls
169 lines (153 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/python
# copyright (c) 2020, Matthias Dellweg
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
DOCUMENTATION = r"""
---
module: deb_remote
short_description: Manage deb remotes of a pulp api server instance
description:
- "This performs CRUD operations on deb remotes in a pulp api server instance."
options:
architectures:
description:
- Whitespace separated list of architectures to sync.
type: str
components:
description:
- Whitespace separated list of components to sync.
type: str
distributions:
description:
- Whitespace separated list of distributions to sync.
type: str
gpgkey:
description:
- gpgkey of remote repository
type: str
policy:
description:
- Whether downloads should be performed immediately, or lazy.
type: str
choices:
- immediate
- on_demand
- streamed
sync_installer:
description:
- Sync installer packages
type: bool
version_added: "0.0.16"
sync_sources:
description:
- Sync source packages
type: bool
version_added: "0.0.16"
sync_udebs:
description:
- Sync installer packages
type: bool
version_added: "0.0.16"
extends_documentation_fragment:
- pulp.squeezer.pulp
- pulp.squeezer.pulp.entity_state
- pulp.squeezer.pulp.remote
author:
- Matthias Dellweg (@mdellweg)
"""
EXAMPLES = r"""
- name: Read list of deb remotes from pulp api server
pulp.squeezer.deb_remote:
pulp_url: https://pulp.example.org
username: admin
password: password
register: remote_status
- name: Report pulp deb remotes
debug:
var: remote_status
- name: Create a deb remote
pulp.squeezer.deb_remote:
pulp_url: https://pulp.example.org
username: admin
password: password
name: new_deb_remote
url: http://localhost/pub/deb/pulp_manifest
architectures: amd64
components: 'main contrib non-free'
distributions: buster
state: present
- name: Delete a deb remote
pulp.squeezer.deb_remote:
pulp_url: https://pulp.example.org
username: admin
password: password
name: new_deb_remote
state: absent
"""
RETURN = r"""
remotes:
description: List of deb remotes
type: list
returned: when no name is given
remote:
description: Deb remote details
type: dict
returned: when name is given
"""
from ansible_collections.pulp.squeezer.plugins.module_utils.pulp import (
PulpDebRemote,
PulpRemoteAnsibleModule,
)
def main():
with PulpRemoteAnsibleModule(
argument_spec={
"architectures": {},
"components": {},
"distributions": {},
"gpgkey": {},
"policy": {"choices": ["immediate", "on_demand", "streamed"]},
"sync_installer": {"type": "bool"},
"sync_sources": {"type": "bool"},
"sync_udebs": {"type": "bool"},
},
required_if=[("state", "present", ["name"]), ("state", "absent", ["name"])],
) as module:
natural_key = {"name": module.params["name"]}
desired_attributes = {
key: module.params[key]
for key in [
"url",
"architectures",
"components",
"distributions",
"download_concurrency",
"gpgkey",
"policy",
"sync_installer",
"sync_sources",
"sync_udebs",
"tls_validation",
]
if module.params[key] is not None
}
# Nullifiable values
if module.params["remote_username"] is not None:
desired_attributes["username"] = module.params["remote_username"] or None
if module.params["remote_password"] is not None:
desired_attributes["password"] = module.params["remote_password"] or None
desired_attributes.update(
{
key: module.params[key] or None
for key in [
"proxy_url",
"proxy_username",
"proxy_password",
"ca_cert",
"client_cert",
"client_key",
]
if module.params[key] is not None
}
)
PulpDebRemote(module, natural_key, desired_attributes).process()
if __name__ == "__main__":
main()