Handle root as a deployment user better

Currently if you don't specify --deployment-user and for whatever reason
it's run as root (e.g. ansible as root using sudo), the deployment fails
because it attempts to write out to /home/root/. This change updates the
user home root lookup for clouds.yaml and throws a warning about setting
--deployment-user if it's root.

Change-Id: I284b374cc5e6d6a147286f0485832258f93f038f
(cherry picked from commit ff56863b26)
This commit is contained in:
Alex Schultz 2020-10-29 12:23:38 -06:00
parent 9efc5faa51
commit d57af5e77e
2 changed files with 7 additions and 1 deletions

View File

@ -2310,7 +2310,7 @@ def copy_clouds_yaml(user):
:param user: deployment user :param user: deployment user
""" """
clouds_etc_file = '/etc/openstack/clouds.yaml' clouds_etc_file = '/etc/openstack/clouds.yaml'
clouds_home_dir = os.path.join('/home', user) clouds_home_dir = os.path.expanduser("~{}".format(user))
clouds_config_dir = os.path.join(clouds_home_dir, '.config') clouds_config_dir = os.path.join(clouds_home_dir, '.config')
clouds_openstack_config_dir = os.path.join(clouds_config_dir, clouds_openstack_config_dir = os.path.join(clouds_config_dir,
'openstack') 'openstack')

View File

@ -1410,6 +1410,12 @@ class Deploy(command.Command):
def take_action(self, parsed_args): def take_action(self, parsed_args):
self.log.debug("take_action(%s)" % parsed_args) self.log.debug("take_action(%s)" % parsed_args)
if parsed_args.deployment_user == 'root':
self.log.warning(
_("[WARNING] Deployment user is set to 'root'. This may cause "
"some deployment files to be located in /root. Please use "
"--deployment-user to specify the user you are deploying "
"with."))
try: try:
if parsed_args.standalone: if parsed_args.standalone:
self._standalone_deploy(parsed_args) self._standalone_deploy(parsed_args)