2020-03-28 11:56:45 +00:00
|
|
|
from os.path import join, exists
|
|
|
|
|
2020-02-29 12:30:21 +00:00
|
|
|
directories = {}
|
|
|
|
users = {}
|
|
|
|
files = {}
|
|
|
|
groups = {}
|
|
|
|
|
|
|
|
pkg_apt = {
|
|
|
|
'fish': {},
|
|
|
|
'tmux': {},
|
|
|
|
}
|
|
|
|
|
2020-02-29 12:38:27 +00:00
|
|
|
users['root'] = {
|
|
|
|
'home': '/root',
|
|
|
|
'shell': '/bin/bash',
|
|
|
|
'password': repo.vault.human_password_for('root on {}'.format(node.name)),
|
|
|
|
}
|
|
|
|
|
2020-03-27 13:33:37 +00:00
|
|
|
files['/etc/bash.bashrc'] = {
|
|
|
|
'source': 'bashrc',
|
|
|
|
'content_type': 'mako',
|
|
|
|
}
|
|
|
|
|
2020-03-28 12:01:30 +00:00
|
|
|
files['/etc/tmux.conf'] = {
|
|
|
|
'source': 'tmux.conf',
|
|
|
|
'content_type': 'mako',
|
|
|
|
}
|
|
|
|
|
2020-02-29 12:30:21 +00:00
|
|
|
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
|
2020-02-29 14:47:41 +00:00
|
|
|
user['shell'] = attrs.get('shell', '/bin/bash')
|
2020-03-27 11:28:44 +00:00
|
|
|
user['password_hash'] = 'x'
|
2020-02-29 12:30:21 +00:00
|
|
|
|
2020-02-29 12:38:27 +00:00
|
|
|
if 'groups' in attrs:
|
|
|
|
user['groups'] = attrs['groups']
|
|
|
|
|
2020-02-29 12:30:21 +00:00
|
|
|
directories[home] = {
|
|
|
|
'owner': username,
|
2020-04-04 16:15:08 +00:00
|
|
|
'mode': attrs.get('home-mode', '0700'),
|
2020-02-29 12:30:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if 'ssh_pubkey' in attrs:
|
|
|
|
files[home + '/.ssh/authorized_keys'] = {
|
|
|
|
'content': "\n".join(attrs['ssh_pubkey']),
|
|
|
|
'owner': username,
|
|
|
|
'mode': '0600',
|
|
|
|
}
|
|
|
|
|
2020-02-29 13:09:14 +00:00
|
|
|
else:
|
|
|
|
files[home + '/.ssh/authorized_keys'] = {'delete': True}
|
|
|
|
|
2020-04-04 15:54:26 +00:00
|
|
|
if attrs.get('deploy_configs', True):
|
|
|
|
if exists(join(repo.path, 'data', 'users', 'files', 'tmux', '{}.conf'.format(username))):
|
|
|
|
files[home + '/.tmux.conf'] = {
|
|
|
|
'content_type': 'mako',
|
|
|
|
'source': 'tmux/{}.conf'.format(username),
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
files[home + '/.tmux.conf'] = {
|
|
|
|
'delete': True,
|
|
|
|
}
|
|
|
|
|
|
|
|
if exists(join(repo.path, 'data', 'users', 'files', 'fish', '{}.conf'.format(username))):
|
|
|
|
fish_src = 'fisk/{}.conf'.format(username)
|
|
|
|
else:
|
|
|
|
fish_src = 'fish.conf'
|
|
|
|
|
|
|
|
files[home + '/.config/fish/config.fish'] = {
|
2020-03-28 12:01:30 +00:00
|
|
|
'content_type': 'mako',
|
2020-04-04 15:54:26 +00:00
|
|
|
'source': fish_src
|
2020-03-28 12:01:30 +00:00
|
|
|
}
|
2020-03-28 11:56:45 +00:00
|
|
|
|
2020-04-04 15:54:26 +00:00
|
|
|
if exists(join(repo.path, 'data', 'users', 'files', 'bash', '{}.bashrc'.format(username))):
|
|
|
|
files[home + '/.bashrc'] = {
|
|
|
|
'content_type': 'mako',
|
|
|
|
'source': 'bash/{}.bashrc'.format(username),
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
files[home + '/.bashrc'] = {
|
|
|
|
'delete': True,
|
|
|
|
}
|