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.
This commit is contained in:
parent
717feea0d3
commit
1225279614
1 changed files with 5 additions and 19 deletions
|
@ -1,21 +1,7 @@
|
||||||
#!/usr/bin/python -tt
|
#! /bin/sh
|
||||||
import os
|
|
||||||
import os.path
|
|
||||||
import subprocess
|
|
||||||
|
|
||||||
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 $rootpath/hosts $rootpath/groups -type f -name '*.yml' |
|
||||||
# Find all the .yml files under playbooks/groups and hosts and run ansible-playbook on them
|
xargs -I'{}' -P $parallel ansible-playbook '{}' --check --diff
|
||||||
# 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()
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue