# Buggy code
def execute(
    self,
    idempotent=False,
    create_instances=True,
    create_inventory=True,
    exit=True,
    hide_errors=True,
):
    """
    Execute the actions necessary to perform a `molecule converge` and
    return a tuple.

    :param idempotent: An optional flag to perform the converge again, and
     parse the output for idempotence.
    :param create_inventory: An optional flag to toggle inventory creation.
    :param create_instances: An optional flag to toggle instance creation.
    :return: Return a tuple of (`exit status`, `command output`), otherwise
     sys.exit on command failure.
    """
    if self.molecule.state.created:
        create_instances = False

    if self.molecule.state.converged:
        create_inventory = False

    if self.molecule.state.multiple_platforms:
        self.command_args["platform"] = "all"
    else:
        if (self.command_args.get("platform") == "all") and self.molecule.state.created:
            create_instances = True
            create_inventory = True

    if create_instances and not idempotent:
        c = create.Create(self.command_args, self.args, self.molecule)
        c.execute()

    if create_inventory:
        self.molecule.create_inventory_file()

    # Install role dependencies only during `molecule converge`
    if (
        not idempotent
        and "requirements_file" in self.molecule.config.config["ansible"]
        and not self.molecule.state.installed_deps
    ):
        galaxy = ansible_galaxy.AnsibleGalaxy(self.molecule.config.config)
        galaxy.install()
        self.molecule.state.change_state("installed_deps", True)

    ansible = ansible_playbook.AnsiblePlaybook(
        self.molecule.config.config["ansible"],
        self.molecule.driver.ansible_connection_params,
    )

    # Target tags passed in via CLI
    if self.command_args.get("tags"):
        ansible.add_cli_arg("tags", self.command_args.get("tags"))

    if idempotent:
        # Don't log stdout/err
        ansible.remove_cli_arg("_out")
        ansible.remove_cli_arg("_err")
        # Disable color for regexp
        ansible.add_env_arg("ANSIBLE_NOCOLOR", "true")
        ansible.add_env_arg("ANSIBLE_FORCE_COLOR", "false")

    ansible.bake()
    if self.args.get("debug"):
        ansible_env = {k: v for (k, v) in ansible.env.items() if "ANSIBLE" in k}
        other_env = {k: v for (k, v) in ansible.env.items() if "ANSIBLE" not in k}
        util.print_debug(
            "OTHER ENVIRONMENT",
            yaml.dump(other_env, default_flow_style=False, indent=2),
        )
        util.print_debug(
            "ANSIBLE ENVIRONMENT",
            yaml.dump(ansible_env, default_flow_style=False, indent=2),
        )
        util.print_debug("ANSIBLE PLAYBOOK", str(ansible._ansible))

    util.print_info("Starting Ansible Run ...")
    status, output = ansible.execute(hide_errors=hide_errors)
    if status is not None:
        if exit:
            util.sysexit(status)
        return status, None

    if not self.molecule.state.converged:
        self.molecule.state.change_state("converged", True)

    return None, output


# Traceback (AttributeError)
+ molecule idempotence
--> Idempotence test in progress (can take a few minutes) ...
--> Starting Ansible Run ...
Idempotence test failed because of the following tasks:
Traceback (most recent call last):
File "/home/leeroy-jenkins/jenkins/workspace/ci-molecule-ansible-systems-cisco.metapod_common/venv/bin/molecule", line 11, in <module>
sys.exit(main())
File "/home/leeroy-jenkins/jenkins/workspace/ci-molecule-ansible-systems-cisco.metapod_common/venv/lib/python2.7/site-packages/molecule/cli.py", line 41, in main
cli(obj={})
File "/home/leeroy-jenkins/jenkins/workspace/ci-molecule-ansible-systems-cisco.metapod_common/venv/lib/python2.7/site-packages/click/core.py", line 716, in __call__
return self.main(*args, **kwargs)
File "/home/leeroy-jenkins/jenkins/workspace/ci-molecule-ansible-systems-cisco.metapod_common/venv/lib/python2.7/site-packages/click/core.py", line 696, in main
rv = self.invoke(ctx)
File "/home/leeroy-jenkins/jenkins/workspace/ci-molecule-ansible-systems-cisco.metapod_common/venv/lib/python2.7/site-packages/click/core.py", line 1060, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/leeroy-jenkins/jenkins/workspace/ci-molecule-ansible-systems-cisco.metapod_common/venv/lib/python2.7/site-packages/click/core.py", line 889, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/leeroy-jenkins/jenkins/workspace/ci-molecule-ansible-systems-cisco.metapod_common/venv/lib/python2.7/site-packages/click/core.py", line 534, in invoke
return callback(*args, **kwargs)
File "/home/leeroy-jenkins/jenkins/workspace/ci-molecule-ansible-systems-cisco.metapod_common/venv/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/home/leeroy-jenkins/jenkins/workspace/ci-molecule-ansible-systems-cisco.metapod_common/venv/lib/python2.7/site-packages/molecule/command/idempotence.py", line 119, in idempotence
util.sysexit(i.execute()[0])
File "/home/leeroy-jenkins/jenkins/workspace/ci-molecule-ansible-systems-cisco.metapod_common/venv/lib/python2.7/site-packages/molecule/command/idempotence.py", line 61, in execute
LOG.error('\n'.join(self._non_idempotent_tasks(output)))
File "/home/leeroy-jenkins/jenkins/workspace/ci-molecule-ansible-systems-cisco.metapod_common/venv/lib/python2.7/site-packages/molecule/command/idempotence.py", line 104, in _non_idempotent_tasks
res.append('* {}'.format(task_name.groups()[0]))
AttributeError: 'NoneType' object has no attribute 'groups'

# Fixed code
def execute(
    self,
    idempotent=False,
    create_instances=True,
    create_inventory=True,
    exit=True,
    hide_errors=True,
):
    """
    Execute the actions necessary to perform a `molecule converge` and
    return a tuple.

    :param idempotent: An optional flag to perform the converge again, and
     parse the output for idempotence.
    :param create_inventory: An optional flag to toggle inventory creation.
    :param create_instances: An optional flag to toggle instance creation.
    :return: Return a tuple of (`exit status`, `command output`), otherwise
     sys.exit on command failure.
    """
    if self.molecule.state.created:
        create_instances = False

    if self.molecule.state.converged:
        create_inventory = False

    if self.molecule.state.multiple_platforms:
        self.command_args["platform"] = "all"
    else:
        if (self.command_args.get("platform") == "all") and self.molecule.state.created:
            create_instances = True
            create_inventory = True

    if create_instances and not idempotent:
        c = create.Create(self.command_args, self.args, self.molecule)
        c.execute()

    if create_inventory:
        self.molecule.create_inventory_file()

    # Install role dependencies only during `molecule converge`
    if (
        not idempotent
        and "requirements_file" in self.molecule.config.config["ansible"]
        and not self.molecule.state.installed_deps
    ):
        galaxy = ansible_galaxy.AnsibleGalaxy(self.molecule.config.config)
        galaxy.install()
        self.molecule.state.change_state("installed_deps", True)

    ansible = ansible_playbook.AnsiblePlaybook(
        self.molecule.config.config["ansible"],
        self.molecule.driver.ansible_connection_params,
    )

    # Target tags passed in via CLI
    if self.command_args.get("tags"):
        ansible.add_cli_arg("tags", self.command_args.get("tags"))

    if idempotent:
        # Don't log stdout/err
        ansible.remove_cli_arg("_out")
        ansible.remove_cli_arg("_err")
        # Idempotence task regexp cannot handle diff
        ansible.remove_cli_arg("diff")
        # Disable color for regexp
        ansible.add_env_arg("ANSIBLE_NOCOLOR", "true")
        ansible.add_env_arg("ANSIBLE_FORCE_COLOR", "false")

    ansible.bake()
    if self.args.get("debug"):
        ansible_env = {k: v for (k, v) in ansible.env.items() if "ANSIBLE" in k}
        other_env = {k: v for (k, v) in ansible.env.items() if "ANSIBLE" not in k}
        util.print_debug(
            "OTHER ENVIRONMENT",
            yaml.dump(other_env, default_flow_style=False, indent=2),
        )
        util.print_debug(
            "ANSIBLE ENVIRONMENT",
            yaml.dump(ansible_env, default_flow_style=False, indent=2),
        )
        util.print_debug("ANSIBLE PLAYBOOK", str(ansible._ansible))

    util.print_info("Starting Ansible Run ...")
    status, output = ansible.execute(hide_errors=hide_errors)
    if status is not None:
        if exit:
            util.sysexit(status)
        return status, None

    if not self.molecule.state.converged:
        self.molecule.state.change_state("converged", True)

    return None, output