<commit_before>import requests
from ansible.plugins.action import ActionBase
from ansible.utils.vars import merge_hash


class ActionModule(ActionBase):

    def run(self, tmp=None, task_vars=None):

        results = super(ActionModule, self).run(tmp, task_vars)
        results = merge_hash(results, self._execute_module(tmp=tmp, task_vars=task_vars))
        r = requests.get("https://google.com/")
        results.update({
            "shi": "kaka",
            "status_code": str(r.status_code)
        })
        return results<commit_msg>Adding code showing how to update insights module from action plugin<commit_after>from ansible.plugins.action import ActionBase
from ansible.utils.vars import merge_hash


def update_code(module_location):
    """
    Let's just see if we can execute a module "generated" on-the-fly by an
    action plugin
    """
    with open("insights/insights.py") as fp:
        content = fp.read()
    content = content.replace("regoob", "Content updated!")
    with open(module_location, "w") as fp:
        fp.write(content)


class ActionModule(ActionBase):

    def run(self, tmp=None, task_vars=None):
        results = super(ActionModule, self).run(tmp, task_vars)
        module_location = self._shared_loader_obj.module_loader.find_plugin("insights")
        update_code(module_location)
        results = merge_hash(results, self._execute_module(module_name="insights", tmp=tmp, task_vars=task_vars))
        results.update({
            "shi": "kaka"
        })
        return results
{'fraction_non_alphanumeric': 0.10856769130150425, 'fraction_numerical': 0.0, 'mean_word_length': 3.383954154727794, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3070170', 'n_tokens_mistral': 453, 'n_tokens_neox': 442, 'n_words': 106}