Make admin_user plugin more robust

Don't fail if the ec2-get-credentials script is not installed
Don't fail if SSH server is not installed
This commit is contained in:
Anders Ingemann 2013-12-15 19:24:41 +01:00
parent abe6a5fef3
commit 1e0aa634d2
2 changed files with 16 additions and 4 deletions

View file

@ -8,8 +8,11 @@ def validate_manifest(data, schema_validate):
def resolve_tasks(tasklist, manifest): def resolve_tasks(tasklist, manifest):
import tasks import tasks
from providers.ec2.tasks import initd
if initd.AddEC2InitScripts in tasklist.tasks:
tasklist.add(tasks.AdminUserCredentials)
tasklist.add(tasks.AddSudoPackage, tasklist.add(tasks.AddSudoPackage,
tasks.CreateAdminUser, tasks.CreateAdminUser,
tasks.PasswordlessSudo, tasks.PasswordlessSudo,
tasks.AdminUserCredentials,
tasks.DisableRootLogin) tasks.DisableRootLogin)

View file

@ -59,6 +59,15 @@ class DisableRootLogin(Task):
phase = phases.system_modification phase = phases.system_modification
def run(self, info): def run(self, info):
from subprocess import CalledProcessError
from common.tools import log_check_call
try:
log_check_call(['/usr/sbin/chroot', info.root,
'/usr/bin/dpkg-query', '-W', 'openssh-server'])
from common.tools import sed_i from common.tools import sed_i
sshdconfig_path = os.path.join(info.root, 'etc/ssh/sshd_config') sshdconfig_path = os.path.join(info.root, 'etc/ssh/sshd_config')
sed_i(sshdconfig_path, 'PermitRootLogin yes', 'PermitRootLogin no') sed_i(sshdconfig_path, 'PermitRootLogin yes', 'PermitRootLogin no')
except CalledProcessError:
import logging
logging.getLogger(__name__).warn('The OpenSSH server has not been installed, '
'not disabling SSH root login.')