Beispiel #1
0
    def generate_retry_inventory(self, replay_hosts):
        '''
        called by /usr/bin/ansible when a playbook run fails. It generates an inventory
        that allows re-running on ONLY the failed hosts.  This may duplicate some
        variable information in group_vars/host_vars but that is ok, and expected.
        '''

        buf = StringIO.StringIO()
        for x in replay_hosts:
            buf.write("%s\n" % x)
        basedir = C.shell_expand_path(C.RETRY_FILES_SAVE_PATH)
        filename = "%s.retry" % os.path.basename(self.filename)
        filename = filename.replace(".yml","")
        filename = os.path.join(basedir, filename)

        try:
            if not os.path.exists(basedir):
                os.makedirs(basedir)

            fd = open(filename, 'w')
            fd.write(buf.getvalue())
            fd.close()
        except:
            ansible.callbacks.display(
                "\nERROR: could not create retry file. Check the value of \n"
                + "the configuration variable 'retry_files_save_path' or set \n"
                + "'retry_files_enabled' to False to avoid this message.\n",
                color='red'
            )
            return None

        return filename
Beispiel #2
0
    def generate_retry_inventory(self, replay_hosts):
        '''
        called by /usr/bin/ansible when a playbook run fails. It generates an inventory
        that allows re-running on ONLY the failed hosts.  This may duplicate some
        variable information in group_vars/host_vars but that is ok, and expected.
        '''

        buf = StringIO.StringIO()
        for x in replay_hosts:
            buf.write("%s\n" % x)
        basedir = C.shell_expand_path(C.RETRY_FILES_SAVE_PATH)
        filename = "%s.retry" % os.path.basename(self.filename)
        filename = filename.replace(".yml", "")
        filename = os.path.join(basedir, filename)

        try:
            if not os.path.exists(basedir):
                os.makedirs(basedir)

            fd = open(filename, 'w')
            fd.write(buf.getvalue())
            fd.close()
        except:
            ansible.callbacks.display(
                "\nERROR: could not create retry file. Check the value of \n" +
                "the configuration variable 'retry_files_save_path' or set \n"
                + "'retry_files_enabled' to False to avoid this message.\n",
                color='red')
            return None

        return filename
Beispiel #3
0
    This uses load_config_file() and get_config() from ansible.constants
    """
    config = AC.load_config_file()
    return AC.get_config(config, DEFAULT_SECTION, key, env_var, default)


DEFAULT_SECTION = "ansiblereport"

DEFAULT_VERBOSE = False

DEFAULT_STRFTIME = "%Y-%m-%d %H:%M:%S"
DEFAULT_SHORT_STRFTIME = "%H:%M:%S"
DEFAULT_FRIENDLY_STRFTIME = "%Y-%m-%d %H:%M"

DEFAULT_TASK_WARN_RESULTS = ["FAILED", "ERROR", "UNREACHABLE"]
DEFAULT_TASK_OKAY_RESULTS = ["OK", "SKIPPED", "CHANGED"]

DEFAULT_TASK_RESULTS = []
DEFAULT_TASK_RESULTS.extend(DEFAULT_TASK_OKAY_RESULTS)
DEFAULT_TASK_RESULTS.extend(DEFAULT_TASK_WARN_RESULTS)

DEFAULT_SMTP_SERVER = get_config_value("smtp.server", None, "localhost")
DEFAULT_SMTP_SUBJECT = get_config_value("smtp.subject", None, "ansible-report")
DEFAULT_SMTP_SENDER = get_config_value("smtp.sender", None, "nobody@{0}".format(socket.getfqdn()))
DEFAULT_SMTP_RECIPIENT = get_config_value("smtp.recipient", None, "root@{0}".format(socket.getfqdn()))

DEFAULT_OUTPUT = ["screen"]
DEFAULT_OUTPUT_PLUGIN_PATH = AC.shell_expand_path(
    get_config_value("output_plugins", "ANSIBLEREPORT_OUTPUT_PLUGINS", "/usr/share/ansible-report/plugins")
)