Skip to content

Commit 464bbca

Browse files
committed
Add CIFS Support
Add abbility to add cifs as storage to proxmox, see proxmox_storage.py for Usage Examples
1 parent d4b7309 commit 464bbca

File tree

3 files changed

+60
-7
lines changed

3 files changed

+60
-7
lines changed

defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,4 @@ pve_storages: []
5757
pve_ssh_port: 22
5858
pve_manage_ssh: true
5959
pve_hooks: {}
60+
no_logging: false

library/proxmox_storage.py

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,22 @@
103103
description:
104104
- Specifies whether or not the given path is an externally managed
105105
mountpoint.
106-
106+
namespace:
107+
required: false
108+
description:
109+
- Specifies the Namespace that should be used on PBS
110+
share:
111+
required: false
112+
description:
113+
- Specifies the CIFS-Share to use
114+
subdir:
115+
required: false
116+
- specifies the folder in the share dir to use for proxmox
117+
(useful to seperate proxmox content from other content)
118+
domain:
119+
required: false
120+
- Specifies Realm to use for NTLM/LDAPS Authentification if using
121+
an AD-Enabled share
107122
author:
108123
- Fabien Brachere (@fbrachere)
109124
'''
@@ -170,13 +185,25 @@
170185
datastore: main
171186
fingerprint: f2:fb:85:76:d2:2a:c4:96:5c:6e:d8:71:37:36:06:17:09:55:f7:04:e3:74:bb:aa:9e:26:85:92:63:c8:b9:23
172187
encryption_key: autogen
188+
namespace: Top/something
173189
- name: Create a ZFS storage type
174190
proxmox_storage:
175191
name: zfs1
176192
type: zfspool
177193
content: [ "images", "rootdir" ]
178194
pool: rpool/data
179195
sparse: true
196+
- name: CIFS-Share
197+
proxmox_Storage:
198+
name: cifs1
199+
server: cifs-host.domain.tld
200+
type: cifs
201+
content: ["snippets", "vztmpl", "iso" ]
202+
share: sharename
203+
subdir: /subdir
204+
username: user
205+
password: supersecurepass
206+
domain: addomain.tld
180207
'''
181208

182209
RETURN = '''
@@ -220,7 +247,10 @@ def __init__(self, module):
220247
self.thinpool = module.params['thinpool']
221248
self.sparse = module.params['sparse']
222249
self.is_mountpoint = module.params['is_mountpoint']
223-
250+
self.namespace = module.params['namespace']
251+
self.domain = module.params['domain']
252+
self.subdir = module.params['subdir']
253+
self.share = module.params['share']
224254
# Validate the parameters given to us
225255
fingerprint_re = re.compile('^([A-Fa-f0-9]{2}:){31}[A-Fa-f0-9]{2}$')
226256
if self.fingerprint is not None and not fingerprint_re.match(self.fingerprint):
@@ -305,16 +335,26 @@ def prepare_storage_args(self):
305335
args['vgname'] = self.vgname
306336
if self.thinpool is not None:
307337
args['thinpool'] = self.thinpool
338+
if self.namespace is not None:
339+
args['namespace'] = self.namespace
308340
if self.sparse is not None:
309341
args['sparse'] = 1 if self.sparse else 0
310342
if self.is_mountpoint is not None:
311343
args['is_mountpoint'] = 1 if self.is_mountpoint else 0
312-
344+
if self.namespace is not None:
345+
args['namespace'] = self.namespace
346+
# CIFS
347+
if self.subdir is not None:
348+
args['subdir'] = self.subdir
349+
if self.domain is not None:
350+
args['domain'] = self.domain
351+
# end cifs
313352
if self.maxfiles is not None and 'backup' not in self.content:
314353
self.module.fail_json(msg="maxfiles is not allowed when there is no 'backup' in content")
315354
if self.krbd is not None and self.type != 'rbd':
316355
self.module.fail_json(msg="krbd is only allowed with 'rbd' storage type")
317-
356+
if self.share is not None:
357+
args['share'] = self.share
318358
return args
319359

320360
def create_storage(self):
@@ -386,7 +426,7 @@ def main():
386426
nodes=dict(type='list', required=False, default=None),
387427
type=dict(default=None, type='str', required=True,
388428
choices=["dir", "nfs", "rbd", "lvm", "lvmthin", "cephfs",
389-
"zfspool", "btrfs", "pbs"]),
429+
"zfspool", "btrfs", "pbs","cifs"]),
390430
# Remaining PVE API arguments (depending on type) past this point
391431
datastore=dict(default=None, type='str', required=False),
392432
encryption_key=dict(default=None, type='str', required=False),
@@ -405,7 +445,12 @@ def main():
405445
vgname=dict(default=None, type='str', required=False),
406446
thinpool=dict(default=None, type='str', required=False),
407447
sparse=dict(default=None, type='bool', required=False),
408-
is_mountpoint=dict(default=None, type='bool', required=False),
448+
is_mountpoint=dict(default=None, type='bool', required=False),
449+
namespace=dict(default=None, type='str', required=False),
450+
subdir=dict(default=None, type='str', required=False),
451+
domain=dict(default=None, type='str', required=False),
452+
share=dict(default=None, type='str', required=False),
453+
409454
)
410455

411456
module = AnsibleModule(
@@ -420,7 +465,8 @@ def main():
420465
["type", "lvmthin", ["vgname", "thinpool", "content"]],
421466
["type", "zfspool", ["pool", "content"]],
422467
["type", "btrfs", ["path", "content"]],
423-
["type", "pbs", ["server", "username", "password", "datastore"]]
468+
["type", "pbs", ["server", "username", "password", "datastore"]],
469+
["type", "cifs", ["server", "share"]],
424470
],
425471
required_by={
426472
"master_pubkey": "encryption_key"

tasks/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,12 @@
333333
vgname: "{{ item.vgname | default(omit) }}"
334334
thinpool: "{{ item.thinpool | default(omit) }}"
335335
sparse: "{{ item.sparse | default(omit) }}"
336+
namespace: "{{ item.namespace | default(omit) }}"
337+
domain: "{{ item.domain | default(omit) }}"
338+
subdir: "{{ item.subdir | default(omit) }}"
339+
share: "{{ item.share | default(omit) }}"
340+
# Set logging to true in production in ypur groupvars
341+
no_log: "{{ no_logging | default(false) }}"
336342
with_items: "{{ pve_storages }}"
337343
when: "not pve_cluster_enabled | bool or (pve_cluster_enabled | bool and inventory_hostname == _init_node)"
338344
tags: storage

0 commit comments

Comments
 (0)