def remove(self): inventory, resources, statuses = self.get_environment_info() okToRemove = True stillExists = [] for r in resources: if statuses[r]["state"] == "deployed": okToRemove = False stillExists.append(r) if okToRemove is True: # uses the inventory included in this repository playbooks = ["remove.yml"] print "running {}".format(playbooks) inventory_path = config["install_path"] + "/inventory/hosts" playbook_context = PlaybookRunner(playbooks, config, inventory_path, self.options, self.extra_vars) playbook_context.run() return {"playbook_results": playbook_context, "env": self} else: raise LifecycleError( """Cannot remove environment '%s' until all resources have been de-provisioned. The following resources still exist: %s\n Hint: Try tearing down the environment first.""" % (self.options.env_name, stillExists))
def teardown(self): playbooks = ["teardown_all.yml"] playbook_context = PlaybookRunner(playbooks, config, self.env_inventory_path, self.options, self.extra_vars) playbook_context.run() return {"playbook_results": playbook_context, "env": self}
def stop_traffic(self): playbooks = ["stop_traffic.yml"] playbook_context = PlaybookRunner(playbooks, config, self.env_inventory_path, self.options, self.extra_vars) playbook_context.run() return {"playbook_results": playbook_context, "env": self}
def stop_traffic(self): playbooks = ["stop_traffic.yml"] playbook_context = PlaybookRunner( playbooks, config, self.env_inventory_path, self.options, self.extra_vars) playbook_context.run() return {"playbook_results": playbook_context, "env": self}
def teardown(self): playbooks = ["teardown_all.yml"] playbook_context = PlaybookRunner( playbooks, config, self.env_inventory_path, self.options, self.extra_vars) playbook_context.run() return {"playbook_results": playbook_context, "env": self}
def deploy(self): """ Run ansible playbooks for deployment, given the ansible inventory created via 'init' """ # make sure the environment has been initialized envs = EnvironmentManager.get_envs() if not self.options.env_name in envs: raise LifecycleError("Environment '{}' does not exist. Has it been initialized?".format( self.options.env_name)) playbooks = [ 'deploy_vpc_cft.yml', 'deploy_az_cft.yml', 'deploy_bigip_cft.yml', 'deploy_gtm_cft.yml', 'deploy_app_cft.yml', 'deploy_client_cft.yml', 'deploy_analytics_cft.yml', 'deploy_app.yml', 'deploy_bigip.yml', 'cluster_bigips.yml', 'deploy_apps_bigip.yml', 'deploy_gtm.yml', 'deploy_apps_gtm.yml', 'deploy_client.yml', 'deploy_analytics.yml' ] if self.extra_vars.get("run_only"): print 'User specified subset of playbooks to run specified by {}'.format( self.extra_vars["run_only"]) matching_playbooks = self.get_matching_playbooks( playbooks, self.extra_vars["run_only"]) else: matching_playbooks = playbooks print 'Running playbooks {}'.format(matching_playbooks) playbook_context = PlaybookRunner( matching_playbooks, config, self.env_inventory_path, self.options, self.extra_vars) playbook_context.run() return {"playbook_results": playbook_context, "env": self}
def init(self): """ To instantiate a new environment, we create a set of inventory files for that environment. See individual playbooks for more info. """ # basic string checking to prevent failures later in playbook if not re.match("^[a-zA-z]{1}[a-zA-Z0-9-]*", self.options.env_name): raise ValidationError( 'The environment name must match the following\ regexp: "[a-zA-z]{1}[a-zA-Z0-9-]*" ') # check to make sure this inventory does not already exist if (os.path.isdir((config['env_path'] + self.options.env_name)) and not self.options.force): raise ValidationError( 'There is already an environment with name "%s". Use -f, --force to \ update the inventory variables for this environment. ' % self.options.env_name) # check that this is one of the working regions if self.extra_vars['region'] not in config['regions']: raise ValidationError( 'Only the following regions are possible when using this tool due to \ availability of the ECS-optimized images used to run the Docker app: {}'. format(config['regions'])) # TODO: validate images, eip and cloudformation limits, EULA # acceptance? playbooks = ["init.yml"] playbook_context = PlaybookRunner(playbooks, config, self.proj_inventory_path, self.options, self.extra_vars) playbook_context.run() return {"playbook_results": playbook_context, "env": self}
def deploy(self): """ Run ansible playbooks for deployment, given the ansible inventory created via 'init' """ # make sure the environment has been initialized envs = EnvironmentManager.get_envs() if not self.options.env_name in envs: raise LifecycleError( "Environment '{}' does not exist. Has it been initialized?". format(self.options.env_name)) playbooks = [ 'deploy_vpc_cft.yml', 'deploy_az_cft.yml', 'deploy_bigip_cft.yml', 'deploy_gtm_cft.yml', 'deploy_app_cft.yml', 'deploy_client_cft.yml', 'deploy_analytics_cft.yml', 'deploy_app.yml', 'deploy_bigip.yml', 'cluster_bigips.yml', 'deploy_apps_bigip.yml', 'deploy_gtm.yml', 'deploy_apps_gtm.yml', 'deploy_client.yml', 'deploy_analytics.yml' ] if self.extra_vars.get("run_only"): print 'User specified subset of playbooks to run specified by {}'.format( self.extra_vars["run_only"]) matching_playbooks = self.get_matching_playbooks( playbooks, self.extra_vars["run_only"]) else: matching_playbooks = playbooks print 'Running playbooks {}'.format(matching_playbooks) playbook_context = PlaybookRunner(matching_playbooks, config, self.env_inventory_path, self.options, self.extra_vars) playbook_context.run() return {"playbook_results": playbook_context, "env": self}
def init(self): """ To instantiate a new environment, we create a set of inventory files for that environment. See individual playbooks for more info. """ # basic string checking to prevent failures later in playbook if not re.match("^[a-zA-z]{1}[a-zA-Z0-9-]*", self.options.env_name): raise ValidationError( 'The environment name must match the following\ regexp: "[a-zA-z]{1}[a-zA-Z0-9-]*" ') # check to make sure this inventory does not already exist if (os.path.isdir((config['env_path'] + self.options.env_name)) and not self.options.force): raise ValidationError( 'There is already an environment with name "%s". Use -f, --force to \ update the inventory variables for this environment. ' % self.options.env_name) # check that this is one of the working regions if self.extra_vars['region'] not in config['regions']: raise ValidationError( 'Only the following regions are possible when using this tool due to \ availability of the ECS-optimized images used to run the Docker app: {}'.format( config['regions'])) # TODO: validate images, eip and cloudformation limits, EULA # acceptance? playbooks = ["init.yml"] playbook_context = PlaybookRunner( playbooks, config, self.proj_inventory_path, self.options, self.extra_vars) playbook_context.run() return {"playbook_results": playbook_context, "env": self}
def remove(self): inventory, resources, statuses = self.get_environment_info() okToRemove = True stillExists = [] for r in resources: if statuses[r]["state"] == "deployed": okToRemove = False stillExists.append(r) if okToRemove is True: # uses the inventory included in this repository playbooks = ["remove.yml"] print "running {}".format(playbooks) inventory_path = config["install_path"] + "/inventory/hosts" playbook_context = PlaybookRunner( playbooks, config, inventory_path, self.options, self.extra_vars) playbook_context.run() return {"playbook_results": playbook_context, "env": self} else: raise LifecycleError("""Cannot remove environment '%s' until all resources have been de-provisioned. The following resources still exist: %s\n Hint: Try tearing down the environment first.""" % ( self.options.env_name, stillExists))