add users bundle
This commit is contained in:
parent
3934414140
commit
ebf7f7ada9
2 changed files with 47 additions and 0 deletions
36
bundles/users/items.py
Normal file
36
bundles/users/items.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
directories = {}
|
||||
users = {}
|
||||
files = {}
|
||||
groups = {}
|
||||
|
||||
pkg_apt = {
|
||||
'fish': {},
|
||||
'tmux': {},
|
||||
}
|
||||
|
||||
for username, attrs in node.metadata['users'].items():
|
||||
home = attrs.get('home', '/home/{}'.format(username))
|
||||
|
||||
if attrs.get('delete', False):
|
||||
users[username] = {'delete': True}
|
||||
directories[home] = {'delete': True}
|
||||
|
||||
else:
|
||||
user = users.setdefault(username, {})
|
||||
|
||||
user['home'] = home
|
||||
user['shell'] = attrs.get('shell', '/usr/bin/fish')
|
||||
user['password'] = repo.vault.human_password_for('user {} on {}'.format(username, node.name))
|
||||
|
||||
directories[home] = {
|
||||
'owner': username,
|
||||
'mode': '0700',
|
||||
}
|
||||
|
||||
if 'ssh_pubkey' in attrs:
|
||||
files[home + '/.ssh/authorized_keys'] = {
|
||||
'content': "\n".join(attrs['ssh_pubkey']),
|
||||
'owner': username,
|
||||
'mode': '0600',
|
||||
}
|
||||
|
11
bundles/users/metadata.py
Normal file
11
bundles/users/metadata.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
@metadata_processor
|
||||
def root_user(metadata):
|
||||
return {
|
||||
'users': {
|
||||
'root': {
|
||||
'home': '/root',
|
||||
'ssh_pubkey': [],
|
||||
'shell': '/bin/bash',
|
||||
},
|
||||
},
|
||||
}, DEFAULTS, DONE
|
Loading…
Reference in a new issue