diff --git a/.gitignore b/.gitignore index ee96af7..73c7f09 100644 --- a/.gitignore +++ b/.gitignore @@ -7,10 +7,10 @@ drivers/ansible_shellPackage/Resource Drivers - Python/*.zip .eggs/ cloudshell_cm_ansible.egg-info/ package/cloudshell_cm_ansible.egg-info/ -drivers/ansible_shell.zip *.zip .vscode/ venv .venv* dist/ -package/build/ \ No newline at end of file +package/build/ +driver/*.zip \ No newline at end of file diff --git a/drivers/ansible_shell.zip b/drivers/ansible_shell.zip deleted file mode 100644 index f5516b6..0000000 Binary files a/drivers/ansible_shell.zip and /dev/null differ diff --git a/drivers/ansible_shellPackage/Resource Drivers - Python/Ansible Shell Driver.zip b/drivers/ansible_shellPackage/Resource Drivers - Python/Ansible Shell Driver.zip deleted file mode 100644 index 0a0e8ce..0000000 Binary files a/drivers/ansible_shellPackage/Resource Drivers - Python/Ansible Shell Driver.zip and /dev/null differ diff --git a/package/cloudshell/cm/ansible/ansible_shell.py b/package/cloudshell/cm/ansible/ansible_shell.py index 5561a8d..21d2616 100644 --- a/package/cloudshell/cm/ansible/ansible_shell.py +++ b/package/cloudshell/cm/ansible/ansible_shell.py @@ -6,7 +6,7 @@ from cloudshell.cm.ansible.domain.exceptions import AnsibleException from cloudshell.cm.ansible.domain.ansible_command_executor import AnsibleCommandExecutor, ReservationOutputWriter from cloudshell.cm.ansible.domain.ansible_config_file import AnsibleConfigFile -from cloudshell.cm.ansible.domain.ansible_configuration import AnsibleConfigurationParser +from cloudshell.cm.ansible.domain.ansible_configuration import AnsibleConfigurationParser, AnsibleConfiguration from cloudshell.cm.ansible.domain.file_system_service import FileSystemService from cloudshell.cm.ansible.domain.filename_extractor import FilenameExtractor from cloudshell.cm.ansible.domain.host_vars_file import HostVarsFile @@ -19,6 +19,7 @@ from cloudshell.core.context.error_handling_context import ErrorHandlingContext from cloudshell.shell.core.session.cloudshell_session import CloudShellSessionContext from cloudshell.shell.core.session.logging_session import LoggingSessionContext +from cloudshell.shell.core.driver_context import ResourceCommandContext class AnsibleShell(object): @@ -52,10 +53,13 @@ def execute_playbook(self, command_context, ansi_conf_json, cancellation_context """ with LoggingSessionContext(command_context) as logger: logger.debug('\'execute_playbook\' is called with the configuration json: \n' + ansi_conf_json) - + attrs = command_context.resource.attributes + verify_certificate = attrs.get("Verify Certificate", "True") + is_verify_certificate = True if verify_certificate == "True" else False with ErrorHandlingContext(logger): with CloudShellSessionContext(command_context) as api: ansi_conf = AnsibleConfigurationParser(api).json_to_object(ansi_conf_json) + ansi_conf.verify_certificate = is_verify_certificate output_writer = ReservationOutputWriter(api, command_context) cancellation_sampler = CancellationSampler(cancellation_context) @@ -92,8 +96,8 @@ def _add_host_vars_files(self, ansi_conf, logger): """ for host_conf in ansi_conf.hosts_conf: with HostVarsFile(self.file_system, host_conf.ip, logger) as file: - file.add_vars(host_conf.parameters) file.add_connection_type(host_conf.connection_method) + file.add_vars(host_conf.parameters) ansible_port = self.ansible_connection_helper.get_ansible_port(host_conf) file.add_port(ansible_port) @@ -112,6 +116,7 @@ def _add_host_vars_files(self, ansi_conf, logger): def _download_playbook(self, ansi_conf, cancellation_sampler, logger): """ + :param AnsibleConfiguration ansi_conf :type ansi_conf: AnsibleConfiguration :type cancellation_sampler: CancellationSampler :type logger: Logger @@ -119,7 +124,7 @@ def _download_playbook(self, ansi_conf, cancellation_sampler, logger): """ repo = ansi_conf.playbook_repo auth = None - if ansi_conf.playbook_repo.username or ansi_conf.playbook_repo.token: + if ansi_conf.playbook_repo.username or ansi_conf.playbook_repo.token or ansi_conf.playbook_repo.password: auth = HttpAuth(repo.username, repo.password, repo.token) logger.info('Verify certificate: ' + str(ansi_conf.verify_certificate)) diff --git a/package/cloudshell/cm/ansible/domain/host_vars_file.py b/package/cloudshell/cm/ansible/domain/host_vars_file.py index f54bf54..b36162f 100644 --- a/package/cloudshell/cm/ansible/domain/host_vars_file.py +++ b/package/cloudshell/cm/ansible/domain/host_vars_file.py @@ -33,7 +33,8 @@ def __exit__(self, type, value, traceback): with self.file_system.create_file(self.file_path) as file_stream: lines = ['---'] for key, value in sorted(self.vars.items()): - lines.append(str(key) + ': "' + str(value) + '"') + # lines.append(str(key) + ": '" + str(value) + "'") + lines.append("{}: '{}'".format(str(key), str(value))) file_stream.write(bytes(os.linesep.join(lines), 'utf-8')) self.logger.debug(os.linesep.join(lines)) self.logger.info('Done.') diff --git a/package/cloudshell/cm/ansible/domain/playbook_downloader.py b/package/cloudshell/cm/ansible/domain/playbook_downloader.py index ea3ffcc..a5d4377 100644 --- a/package/cloudshell/cm/ansible/domain/playbook_downloader.py +++ b/package/cloudshell/cm/ansible/domain/playbook_downloader.py @@ -67,10 +67,11 @@ def _download(self, url, auth, logger, cancel_sampler, verify_certificate): if not response_valid and auth is None: raise Exception('Please make sure the URL is valid, and the credentials are correct and necessary.') + generic_auth = auth.token if auth.token else auth.password # repo is private and token provided - if not response_valid and auth.token is not None: + if not response_valid and generic_auth is not None: logger.info("Token provided. Starting download script with Token...") - headers = {"Authorization": "Bearer %s" % auth.token } + headers = {"Authorization": "Bearer %s" % generic_auth } response = self.http_request_service.get_response_with_headers(url, headers, verify_certificate) response_valid = self._is_response_valid(logger, response, "Token") @@ -79,9 +80,9 @@ def _download(self, url, auth, logger, cancel_sampler, verify_certificate): file_name = self.filename_extractor.get_filename(response) # try again with authorization {"Private-Token": "%s" % token}, since gitlab uses that pattern - if not response_valid and auth.token is not None: + if not response_valid and generic_auth is not None: logger.info("Token provided. Starting download script with Token (private-token pattern)...") - headers = {"Private-Token": "Bearer %s" % auth.token } + headers = {"Private-Token": "Bearer %s" % generic_auth } response = self.http_request_service.get_response_with_headers(url, headers, verify_certificate) response_valid = self._is_response_valid(logger, response, "Token") diff --git a/package/version.txt b/package/version.txt index 10bf840..4dd0c8d 100644 --- a/package/version.txt +++ b/package/version.txt @@ -1 +1 @@ -2.0.1 \ No newline at end of file +2.0.1.1 \ No newline at end of file