62 lines
1.4 KiB
Python
62 lines
1.4 KiB
Python
directories = {}
|
|
users = {}
|
|
files = {}
|
|
groups = {}
|
|
|
|
pkg_apt = {
|
|
'fish': {},
|
|
'tmux': {},
|
|
}
|
|
|
|
users['root'] = {
|
|
'home': '/root',
|
|
'shell': '/bin/bash',
|
|
'password': repo.vault.human_password_for('root on {}'.format(node.name)),
|
|
}
|
|
|
|
files['/etc/bash.bashrc'] = {
|
|
'source': 'bashrc',
|
|
'content_type': 'mako',
|
|
}
|
|
|
|
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', '/bin/bash')
|
|
user['password_hash'] = 'x'
|
|
|
|
if 'groups' in attrs:
|
|
user['groups'] = attrs['groups']
|
|
|
|
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',
|
|
}
|
|
|
|
else:
|
|
files[home + '/.ssh/authorized_keys'] = {'delete': True}
|
|
|
|
files[home + '/.config/fish/config.fish'] = {
|
|
'content_type': 'mako',
|
|
}
|
|
|
|
|
|
for user, config in users.items():
|
|
files[config['home'] + '/.bashrc'] = {
|
|
'delete': True,
|
|
}
|