Skip to content

Instantly share code, notes, and snippets.

@ishad0w
Last active November 12, 2024 08:37
Show Gist options
  • Save ishad0w/e5b566c65afa0ce21d51a7f38d827fc7 to your computer and use it in GitHub Desktop.
Save ishad0w/e5b566c65afa0ce21d51a7f38d827fc7 to your computer and use it in GitHub Desktop.
Ansible with Mitogen (venv) for macOS / Linux
#!/bin/bash
python3 -m venv ~/.venvs/ansible-mitogen
source ~/.venvs/ansible-mitogen/bin/activate
pip install --upgrade \
pip cffi jmespath \
boto3 pywinrm \
mitogen==0.3.18 \
ansible-core==2.17.6 \
ansible==10.6.0 \
ansible-lint==24.9.2
# add only 'ansible*' bins to 'PATH'
mkdir -p ~/.venvs/ansible-mitogen/abin/
ln -s ~/.venvs/ansible-mitogen/bin/ansible* ~/.venvs/ansible-mitogen/abin/
mitogen_path=$(find $(python -c "import site; print(site.getsitepackages()[0])") -type d -name 'ansible_mitogen' | head -n 1)/plugins/strategy && echo $mitogen_path
# ansible.cfg with mitogen strategy
cat <<EOL > ~/.ansible.cfg
[defaults]
strategy_plugins = $mitogen_path
strategy = mitogen_linear
EOL
# add to .zshrc or .bashrc
export PATH="$HOME/.venvs/ansible-mitogen/abin:$PATH"
# smoke
cat ~/.ansible.cfg
ansible --version
ansible-playbook --version
# venv 'deactivate'
deactivate
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment