From 1225279614bdfeda73a240714d7868658a6ded88 Mon Sep 17 00:00:00 2001 From: "Frank Ch. Eigler" Date: Tue, 6 Sep 2022 08:19:54 -0400 Subject: [PATCH] ansible-playbook-check-diff: rewrite as find|xargs one-liner Taking advantage of xargs's -P option to limit concurrency while executing all the ansible-playbook --check jobs ensures that batcave01 is not overstressed during these checks. --- scripts/ansible-playbook-check-diff | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/scripts/ansible-playbook-check-diff b/scripts/ansible-playbook-check-diff index 0fe46b72a7..10ddba53cf 100755 --- a/scripts/ansible-playbook-check-diff +++ b/scripts/ansible-playbook-check-diff @@ -1,21 +1,7 @@ -#!/usr/bin/python -tt -import os -import os.path -import subprocess +#! /bin/sh -rootpath = "/srv/web/infra/ansible/playbooks" +rootpath="/srv/web/infra/ansible/playbooks" +parallel=8 # limit since ansible-playbook takes O(1GB) RAM each on batcave -# -# Find all the .yml files under playbooks/groups and hosts and run ansible-playbook on them -# With --check and --diff for now. We don't run the 'manual' subdir ones. - -for dir in ("hosts", "groups"): - hostsplaybookspath = os.path.join(rootpath, dir) - for path, dirs, files in os.walk(hostsplaybookspath): - for file in files: - if not file.endswith(".yml"): - continue - playbookpath = os.path.join(path, file) - cmd = ("ansible-playbook", playbookpath, "--check", "--diff") - ansibleprocess = subprocess.Popen(cmd) - ansibleprocess.communicate() +find $rootpath/hosts $rootpath/groups -type f -name '*.yml' | + xargs -I'{}' -P $parallel ansible-playbook '{}' --check --diff