Last active
April 26, 2022 11:52
-
-
Save konstruktoid/576846137c523c9a34bd1a65e21f85fa to your computer and use it in GitHub Desktop.
Script to calculate Ansible forks based on the number of CPUs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -eux | |
if nproc &>/dev/null; then | |
CPUS=$(nproc) | |
elif grep -qc processor /proc/cpuinfo; then | |
CPUS=$(grep -c processor /proc/cpuinfo) | |
elif sysctl -n hw.ncpu &>/dev/null; then | |
CPUS=$(sysctl -n hw.ncpu) | |
else | |
CPUS=1 | |
fi | |
FORKS=$(( CPUS * 4 )) | |
if [[ "${FORKS}" -lt 5 ]]; then | |
FORKS=5 | |
fi | |
export ANSIBLE_FORKS="${FORKS}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment