How to use the molecule.util.run_command function in molecule

To help you get started, we’ve selected a few molecule examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ansible / molecule / molecule / verifier / lint / rubocop.py View on Github external
if not len(self._tests) > 0:
            msg = 'Skipping, no tests found.'
            LOG.warn(msg)
            return

        if self._rubocop_command is None:
            self.bake()

        msg = 'Executing RuboCop on files found in {}/...'.format(
            self._config.verifier.directory
        )
        LOG.info(msg)

        try:
            util.run_command(self._rubocop_command, debug=self._config.debug)
            msg = 'Lint completed successfully.'
            LOG.success(msg)
        except sh.ErrorReturnCode as e:
            util.sysexit(e.exit_code)
github ansible / molecule / molecule / verifier / lint / yamllint.py View on Github external
if not len(self._tests) > 0:
            msg = 'Skipping, no tests found.'
            LOG.warn(msg)
            return

        if self._yamllint_command is None:
            self.bake()

        msg = 'Executing Yamllint on files found in {}/...'.format(
            self._config.verifier.directory
        )
        LOG.info(msg)

        try:
            util.run_command(self._yamllint_command, debug=self._config.debug)
            msg = 'Lint completed successfully.'
            LOG.success(msg)
        except sh.ErrorReturnCode as e:
            util.sysexit(e.exit_code)
github ansible / molecule / molecule / provisioner / lint / ansible_lint.py View on Github external
def execute(self):
        if not self.enabled:
            msg = 'Skipping, lint is disabled.'
            LOG.warn(msg)
            return

        if self._ansible_lint_command is None:
            self.bake()

        msg = 'Executing Ansible Lint on {}...'.format(self._playbook)
        LOG.info(msg)

        try:
            util.run_command(self._ansible_lint_command, debug=self._config.debug)
            msg = 'Lint completed successfully.'
            LOG.success(msg)
        except sh.ErrorReturnCode as e:
            util.sysexit(e.exit_code)
github ansible / molecule / contrib / convert.py View on Github external
def _create_scenario(self):
        options = {
            'role_name': self._role_name,
            'scenario_name': 'default',
            'driver_name': 'vagrant',
        }
        cmd = sh.molecule.bake('init', 'scenario', _cwd=self._old_role_dir, **options)
        util.run_command(cmd)
github ansible / molecule / molecule / ansible_playbook.py View on Github external
def execute(self, hide_errors=False):
        """
        Executes ansible-playbook and returns command's stdout.

        :param hide_errors: An optional bool to toggle output of errors.
        :return: The command's output, otherwise sys.exit on command failure.
        """
        if self._ansible is None:
            self.bake()

        try:
            return None, unicode(util.run_command(
                self._ansible, debug=self._debug))
        except sh.ErrorReturnCode as e:
            if not hide_errors:
                util.print_error(str(e))

            return e.exit_code, None
github ansible / molecule / molecule / verifier / ansible_lint.py View on Github external
'ANSIBLE_CONFIG':
            self._molecule.config.config['ansible']['config_file'],
            'HOME': os.environ.get('HOME')
        }

        if 'ansible_lint' not in self._molecule.disabled:
            msg = 'Executing ansible-lint...'
            util.print_info(msg)
            args = [self._playbook]
            [args.extend(["--exclude", path]) for path in self._ignore_paths]
            cmd = sh.ansible_lint.bake(
                *args,
                _env=env,
                _out=util.callback_info,
                _err=util.callback_error)
            util.run_command(cmd, debug=self._debug)