def main():
if not PATH_ANSIBLE:
sys.exit("Cannot find ansible-playbook executable.")
logging.basicConfig(
format="%(asctime)s [%(levelname)-5s] %(message)s",
level=logging.DEBUG)
if not os.path.isfile(ANSIBLE_CONFIG_PATH):
LOG.warning("Cannot find Ansible config at %r", ANSIBLE_CONFIG_PATH)
for cluster in get_clusters():
if not cluster["configuration"]:
LOG.info("Skip cluster %s because it has no servers",
cluster["name"])
continue
server = random.choice(cluster["configuration"])
server = server["server_id"]
server = get_server_by_id(server)
commandline = get_ansible_commandline(
server["username"], server["ip"], cluster["name"])
LOG.info("Collect from %s", cluster["name"])
LOG.debug("Execute %s", commandline)
code = execute(commandline)
if code == os.EX_OK:
LOG.info("Collected from %s", cluster["name"])
else:
LOG.warning("Cannot collect from %s: %d", cluster["name"], code)
评论列表
文章目录