How to install Ansible in Gentoo Linux - Ansible install
By Luca Berton · Published 2024-01-01 · Category: installation
The easier way to install and maintain up-to-date Ansible inside Gentoo Linux using the \"portage\" package manager.

How to install Ansible in Gentoo Linux? Today we're going to talk about the easier way to install and maintain Ansible inside Gentoo using the default "portage" package manager. I'm Luca Berton and welcome to today's episode of Ansible Pilot.
How to install Ansible in Gentoo Linux
• Included in "app-admin/ansible" of PortageToday we're talking about How to install Ansible in Gentoo. The good news is that Ansible is included in the "app-admin/ansible" repository so you could install it simply with your usual package manager "emerge" for Portage. You could expect the latest version of Ansible to maintain up-to-date with Portage.
See also: How to Run Linux Fedora Workstation 39 on an Apple Mac
Links
• https://packages.gentoo.org/packages/app-admin/ansible • https://wiki.gentoo.org/wiki/Ansible## Playbook
Let's jump in a quick live Playbook of how to install the latest version of Ansible using emerge for Portage.
code
• Install-Ansible-Gentoo.sh#!/bin/bash
$ sudo emerge --sync
$ sudo emerge --ask app-admin/ansible
$ sudo emerge -pv app-admin/ansible
execution
$ ssh devops@gentoo.example.com
devops@gentoo ~ $ sudo su
gentoo /home/devops # cat /etc/os-release
NAME=Gentoo
ID=gentoo
PRETTY_NAME="Gentoo/Linux"
ANSI_COLOR="1;32"
HOME_URL="https://www.gentoo.org/"
SUPPORT_URL="https://www.gentoo.org/support/"
BUG_REPORT_URL="https://bugs.gentoo.org/"
gentoo /home/devops # cat /etc/gentoo-release
Gentoo Base System release 2.7
gentoo /home/devops # uname -a
Linux gentoo 5.10.76-gentoo-r1 #1 SMP Tue Nov 23 04:46:43 PST 2021 x86_64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz GenuineIntel GNU/Linux
gentoo /home/devops # emerge --sync
>>> Syncing repository 'gentoo' into '/usr/portage'...
* Using keys from /usr/share/openpgp-keys/gentoo-release.asc
* Refreshing keys via WKD ... [ ok ]
>>> Starting rsync with rsync://81.91.253.252/gentoo-portage...
>>> Checking server timestamp ...
Welcome to starling.gentoo.org / rsync.gentoo.org
Server Address : 81.91.253.252, 2a01:90:200:10::1a
Contact Name : mirror-admin@gentoo.org
Hardware : 2 x Intel(R) Xeon(R) CPU E5-2470 0 @ 2.30GHz, 3946MB RAM
Sponsor : Qube Managed Services Limited, Zurich, Switzerland, EU
Please note: common gentoo-netiquette says you should not sync more
than once a day. Users who abuse the rsync.gentoo.org rotation
may be added to a temporary ban list.
MOTD autogenerated by update-rsync-motd on Fri Aug 20 06:43:59 AM UTC 2021
receiving incremental file list
timestamp.chk
Number of files: 1 (reg: 1)
Number of created files: 0
Number of deleted files: 0
Number of regular files transferred: 1
Total file size: 32 bytes
Total transferred file size: 32 bytes
Literal data: 32 bytes
Matched data: 0 bytes
File list size: 42
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 104
Total bytes received: 133
sent 104 bytes received 133 bytes 474.00 bytes/sec
total size is 32 speedup is 0.14
Welcome to starling.gentoo.org / rsync.gentoo.org
Server Address : 81.91.253.252, 2a01:90:200:10::1a
Contact Name : mirror-admin@gentoo.org
Hardware : 2 x Intel(R) Xeon(R) CPU E5-2470 0 @ 2.30GHz, 3946MB RAM
Sponsor : Qube Managed Services Limited, Zurich, Switzerland, EU
Please note: common gentoo-netiquette says you should not sync more
than once a day. Users who abuse the rsync.gentoo.org rotation
may be added to a temporary ban list.
MOTD autogenerated by update-rsync-motd on Fri Aug 20 06:43:59 AM UTC 2021
receiving incremental file list
deleting gentoo-20211122.tar.xz.md5sum
deleting gentoo-20211122.tar.xz.gpgsig
Manifest
Manifest.files.gz
acct-user/Manifest.gz
deleting acct-user/subsonic/subsonic-0.ebuild
acct-user/root/Manifest
deleting app-accessibility/kontrast/kontrast-21.04.3.ebuild
deleting app-admin/ansible-molecule/ansible-molecule-3.5.2.ebuild
deleting app-admin/ansible-molecule/ansible-molecule-3.3.4.ebuild
deleting app-admin/awscli/awscli-1.22.9.ebuild
deleting app-admin/awscli/awscli-1.22.8.ebuild
[...]
Number of files: 147,832 (reg: 121,023, dir: 26,809)
Number of created files: 2,543 (reg: 2,449, dir: 94)
Number of deleted files: 2,304 (reg: 2,262, dir: 42)
Number of regular files transferred: 8,900
Total file size: 238.58M bytes
Total transferred file size: 32.41M bytes
Literal data: 32.41M bytes
Matched data: 0 bytes
File list size: 3.78M
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 202.85K
Total bytes received: 36.66M
sent 202.85K bytes received 36.66M bytes 1.71M bytes/sec
total size is 238.58M speedup is 6.47
* Manifest timestamp: 2021-12-04 08:09:13 UTC
* Valid OpenPGP signature found:
* - primary key: DCD05B71EAB94199527F44ACDB6B8C1F96D8BF6D
* - subkey: E1D6ABB63BFCFB4BA02FDF1CEC590EEAC9189250
* - timestamp: 2021-12-04 08:09:13 UTC
* Verifying /usr/portage/.tmp-unverified-download-quarantine ... [ ok ]
=== Sync completed for gentoo
Performing Global Updates
(Could take a couple of minutes if you have a lot of binary packages.)
.='update pass' *='binary update' #='/var/db update' @='/var/db move'
s='/var/db SLOT move' %='binary move' S='binary SLOT move'
p='update /etc/portage/package.*'
/usr/portage/profiles/updates/2Q-2016.......................................................
/usr/portage/profiles/updates/4Q-2021....
Action: sync for repo: gentoo, returned code = 0
gentoo /home/devops # emerge --ask app-admin/ansible
These are the packages that would be merged, in order:
Calculating dependencies... done!
[ebuild N ] dev-python/ptyprocess-0.7.0 USE="-test" PYTHON_TARGETS="python3_8 (-pypy3) -python3_9 (-python3_10)"
[ebuild N ] dev-python/pexpect-4.8.0-r2 USE="-doc -examples -test" PYTHON_TARGETS="python3_8 (-pypy3) -python3_9 (-python3_10)"
[ebuild N ] dev-python/six-1.16.0 USE="-doc -test" PYTHON_TARGETS="python3_8 (-pypy3) -python3_9 (-python3_10)"
[ebuild N ] dev-python/httplib2-0.19.1-r1 USE="-test" PYTHON_TARGETS="python3_8 (-pypy3) -python3_9 (-python3_10)"
[ebuild N ] dev-python/netaddr-0.8.0 USE="-doc -test" PYTHON_TARGETS="python3_8 -python3_9 (-python3_10)"
[ebuild N ] dev-python/resolvelib-0.5.4 PYTHON_TARGETS="python3_8 -python3_9 (-python3_10)"
[ebuild N ] dev-python/ply-3.11-r1 USE="-examples" PYTHON_TARGETS="python3_8 (-pypy3) -python3_9 (-python3_10)"
[ebuild N ] dev-python/cython-0.29.24-r1 USE="-doc -emacs -test" PYTHON_TARGETS="python3_8 (-pypy3) -python3_9 (-python3_10)"
[ebuild R ] dev-python/markupsafe-2.0.1 PYTHON_TARGETS="python3_8* -python3_9*"
[ebuild N ] dev-python/pyasn1-0.4.8-r1 USE="-doc" PYTHON_TARGETS="python3_8 (-pypy3) -python3_9 (-python3_10)"
[ebuild R ] dev-python/jinja-3.0.2 PYTHON_TARGETS="python3_8* -python3_9*"
[ebuild N ] dev-python/pycparser-2.20-r1 PYTHON_TARGETS="python3_8 (-pypy3) -python3_9 (-python3_10)"
[ebuild N ] dev-python/cffi-1.15.0 USE="-doc -test" PYTHON_TARGETS="python3_8 -python3_9 (-python3_10)"
[ebuild N ] dev-python/cryptography-3.4.7-r2 USE="-test" PYTHON_TARGETS="python3_8 (-pypy3) -python3_9 (-python3_10)"
[ebuild N ] dev-python/bcrypt-3.2.0 USE="-test" PYTHON_TARGETS="python3_8 (-pypy3) -python3_9 (-python3_10)"
[ebuild N ] dev-python/pynacl-1.4.0 USE="-test" PYTHON_TARGETS="python3_8 -python3_9 (-python3_10)"
[ebuild N ] dev-python/paramiko-2.8.0 USE="-doc -examples (-server) -test" PYTHON_TARGETS="python3_8 -python3_9 (-python3_10)"
[ebuild N ] dev-libs/libyaml-0.2.5 USE="-doc -static-libs -test"
[ebuild N ] dev-python/pyyaml-6.0 USE="-examples -test" PYTHON_TARGETS="python3_8 (-pypy3) -python3_9 (-python3_10)"
[ebuild N ] net-misc/sshpass-1.06
[ebuild N ] app-admin/ansible-base-2.11.6-r1 USE="-test" PYTHON_TARGETS="python3_8 -python3_9"
[ebuild N ] app-admin/ansible-4.6.0 PYTHON_TARGETS="python3_8 -python3_9"
Would you like to merge these packages? [Yes/No] Yes
>>> Verifying ebuild manifests
>>> Emerging (1 of 22) dev-python/ptyprocess-0.7.0::gentoo
>>> Emerging (2 of 22) dev-python/six-1.16.0::gentoo
>>> Emerging (3 of 22) dev-python/httplib2-0.19.1-r1::gentoo
>>> Emerging (4 of 22) dev-python/netaddr-0.8.0::gentoo
>>> Emerging (5 of 22) dev-python/resolvelib-0.5.4::gentoo
>>> Emerging (6 of 22) dev-python/ply-3.11-r1::gentoo
>>> Emerging (7 of 22) dev-python/cython-0.29.24-r1::gentoo
>>> Emerging (8 of 22) dev-python/markupsafe-2.0.1::gentoo
>>> Installing (1 of 22) dev-python/ptyprocess-0.7.0::gentoo
>>> Installing (2 of 22) dev-python/six-1.16.0::gentoo
>>> Installing (5 of 22) dev-python/resolvelib-0.5.4::gentoo
>>> Installing (3 of 22) dev-python/httplib2-0.19.1-r1::gentoo
>>> Installing (4 of 22) dev-python/netaddr-0.8.0::gentoo
>>> Installing (6 of 22) dev-python/ply-3.11-r1::gentoo
>>> Installing (8 of 22) dev-python/markupsafe-2.0.1::gentoo
>>> Emerging (9 of 22) dev-python/pexpect-4.8.0-r2::gentoo
>>> Emerging (10 of 22) dev-python/pyasn1-0.4.8-r1::gentoo
>>> Emerging (11 of 22) dev-python/jinja-3.0.2::gentoo
>>> Installing (9 of 22) dev-python/pexpect-4.8.0-r2::gentoo
>>> Installing (11 of 22) dev-python/jinja-3.0.2::gentoo
>>> Emerging (12 of 22) dev-python/pycparser-2.20-r1::gentoo
>>> Emerging (13 of 22) dev-libs/libyaml-0.2.5::gentoo
>>> Emerging (14 of 22) net-misc/sshpass-1.06::gentoo
>>> Installing (10 of 22) dev-python/pyasn1-0.4.8-r1::gentoo
>>> Installing (7 of 22) dev-python/cython-0.29.24-r1::gentoo
>>> Installing (14 of 22) net-misc/sshpass-1.06::gentoo
>>> Installing (12 of 22) dev-python/pycparser-2.20-r1::gentoo
>>> Emerging (15 of 22) dev-python/cffi-1.15.0::gentoo
>>> Installing (13 of 22) dev-libs/libyaml-0.2.5::gentoo
>>> Emerging (16 of 22) dev-python/pyyaml-6.0::gentoo
>>> Installing (15 of 22) dev-python/cffi-1.15.0::gentoo
>>> Emerging (17 of 22) dev-python/cryptography-3.4.7-r2::gentoo
>>> Emerging (18 of 22) dev-python/bcrypt-3.2.0::gentoo
>>> Emerging (19 of 22) dev-python/pynacl-1.4.0::gentoo
>>> Installing (16 of 22) dev-python/pyyaml-6.0::gentoo
>>> Installing (18 of 22) dev-python/bcrypt-3.2.0::gentoo
>>> Installing (19 of 22) dev-python/pynacl-1.4.0::gentoo
>>> Installing (17 of 22) dev-python/cryptography-3.4.7-r2::gentoo
>>> Emerging (20 of 22) dev-python/paramiko-2.8.0::gentoo
>>> Installing (20 of 22) dev-python/paramiko-2.8.0::gentoo
>>> Emerging (21 of 22) app-admin/ansible-base-2.11.6-r1::gentoo
>>> Installing (21 of 22) app-admin/ansible-base-2.11.6-r1::gentoo
>>> Emerging (22 of 22) app-admin/ansible-4.6.0::gentoo
>>> Installing (22 of 22) app-admin/ansible-4.6.0::gentoo
>>> Recording app-admin/ansible in "world" favorites file...
>>> Jobs: 22 of 22 complete Load avg: 1.22, 1.40, 0.75
* Messages for package dev-python/netaddr-0.8.0:
* Install additional packages for optional runtime features:
* dev-python/ipython for CLI support
* Messages for package dev-python/jinja-3.0.2:
* For i18n support, please emerge dev-python/Babel.
>>> Auto-cleaning packages...
>>> No outdated packages were found on your system.
* GNU info directory index is up-to-date.
gentoo /home/devops # ansible --version
ansible [core 2.11.6]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.8/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/lib/python-exec/python3.8/ansible
python version = 3.8.12 (default, Nov 22 2021, 23:02:16) [GCC 11.2.0]
jinja version = 3.0.2
libyaml = True
gentoo /home/devops # emerge -pv ansible
These are the packages that would be merged, in order:
Calculating dependencies... done!
[ebuild R ] app-admin/ansible-4.6.0::gentoo PYTHON_TARGETS="python3_8 -python3_9" 0 KiB
Total: 1 package (1 reinstall), Size of downloads: 0 KiB
gentoo /home/devops #
before execution
# emerge -pv ansible
These are the packages that would be merged, in order:
Calculating dependencies... done!
[ebuild N ] dev-python/ptyprocess-0.7.0::gentoo USE="-test" PYTHON_TARGETS="python3_8 (-pypy3) -python3_9 (-python3_10)" 70 KiB
[ebuild N ] dev-python/pexpect-4.8.0-r2::gentoo USE="-doc -examples -test" PYTHON_TARGETS="python3_8 (-pypy3) -python3_9 (-python3_10)" 154 KiB
[ebuild N ] dev-python/six-1.16.0::gentoo USE="-doc -test" PYTHON_TARGETS="python3_8 (-pypy3) -python3_9 (-python3_10)" 34 KiB
[ebuild N ] dev-python/httplib2-0.19.1-r1::gentoo USE="-test" PYTHON_TARGETS="python3_8 (-pypy3) -python3_9 (-python3_10)" 258 KiB
[ebuild N ] dev-python/netaddr-0.8.0::gentoo USE="-doc -test" PYTHON_TARGETS="python3_8 -python3_9 (-python3_10)" 1,914 KiB
[ebuild N ] dev-python/resolvelib-0.5.4::gentoo PYTHON_TARGETS="python3_8 -python3_9 (-python3_10)" 15 KiB
[ebuild N ] dev-python/ply-3.11-r1:0/3.11::gentoo USE="-examples" PYTHON_TARGETS="python3_8 (-pypy3) -python3_9 (-python3_10)" 156 KiB
[ebuild N ] dev-python/cython-0.29.24-r1::gentoo USE="-doc -emacs -test" PYTHON_TARGETS="python3_8 (-pypy3) -python3_9 (-python3_10)" 2,049 KiB
[ebuild N ] dev-python/pyasn1-0.4.8-r1::gentoo USE="-doc" PYTHON_TARGETS="python3_8 (-pypy3) -python3_9 (-python3_10)" 144 KiB
[ebuild N ] dev-python/pycparser-2.20-r1::gentoo PYTHON_TARGETS="python3_8 (-pypy3) -python3_9 (-python3_10)" 158 KiB
[ebuild N ] dev-python/cffi-1.15.0:0/1.15.0::gentoo USE="-doc -test" PYTHON_TARGETS="python3_8 -python3_9 (-python3_10)" 473 KiB
[ebuild N ] dev-python/cryptography-3.4.7-r2::gentoo USE="-test" PYTHON_TARGETS="python3_8 (-pypy3) -python3_9 (-python3_10)" 535 KiB
[ebuild N ] dev-python/bcrypt-3.2.0::gentoo USE="-test" PYTHON_TARGETS="python3_8 (-pypy3) -python3_9 (-python3_10)" 42 KiB
[ebuild N ] dev-python/pynacl-1.4.0::gentoo USE="-test" PYTHON_TARGETS="python3_8 -python3_9 (-python3_10)" 45,310 KiB
[ebuild N ] dev-python/paramiko-2.8.0::gentoo USE="-doc -examples (-server) -test" PYTHON_TARGETS="python3_8 -python3_9 (-python3_10)" 325 KiB
[ebuild N ] dev-libs/libyaml-0.2.5::gentoo USE="-doc -static-libs -test" 84 KiB
[ebuild N ] dev-python/pyyaml-6.0::gentoo USE="-examples -test" PYTHON_TARGETS="python3_8 (-pypy3) -python3_9 (-python3_10)" 118 KiB
[ebuild N ] net-misc/sshpass-1.06::gentoo 110 KiB
[ebuild N ] app-admin/ansible-base-2.11.6-r1::gentoo USE="-test" PYTHON_TARGETS="python3_8 -python3_9" 6,836 KiB
[ebuild N ] app-admin/ansible-4.6.0::gentoo PYTHON_TARGETS="python3_8 -python3_9" 34,810 KiB
Total: 20 packages (20 new), Size of downloads: 93,582 KiB
gentoo /home/devops #
after execution
# ansible --version
ansible [core 2.11.6]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.8/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/lib/python-exec/python3.8/ansible
python version = 3.8.12 (default, Nov 22 2021, 23:02:16) [GCC 11.2.0]
jinja version = 3.0.2
libyaml = True
gentoo /home/devops # emerge -pv ansible
These are the packages that would be merged, in order:
Calculating dependencies... done!
[ebuild R ] app-admin/ansible-4.6.0::gentoo PYTHON_TARGETS="python3_8 -python3_9" 0 KiB
Total: 1 package (1 reinstall), Size of downloads: 0 KiB
gentoo /home/devops #
Troubleshooting Common Installation Issues
If ansible --version fails or ansible localhost -m ping returns errors after installing on Gentoo Linux, the most common root causes are:
1. Wrong Python interpreter
Ansible runs on Python 3. If python3 is not in PATH or points to an old version, Ansible imports may fail. Check with:
python3 --version
which python3
ansible --version | grep "python version"
If the reported Python version is older than 3.10, install a newer interpreter via your distribution's package manager and either re-create your virtualenv or set ansible_python_interpreter in your inventory.
2. SELinux / AppArmor blocking ansible
On security-hardened distributions, mandatory access control can deny Ansible's working directories or block become privilege escalation. Symptoms include "Permission denied" on operations that succeed manually. Check with:
getenforce # SELinux: should report Permissive or Enforcing
sudo aa-status # AppArmor: lists profiles in enforce mode
Temporarily set SELinux to permissive (sudo setenforce 0) to confirm whether it's the cause; for production, write a tailored policy rather than disabling enforcement.
3. SSH key authentication failing
If ansible all -m ping works locally but fails for remote managed nodes, the issue is almost always SSH. Verify:
ssh -v user@managed-node 'echo ok'
ansible all -m ping -vvv
The verbose output will show whether the connection drops at TCP, key exchange, or authentication. Common fixes: copy your public key with ssh-copy-id, ensure PubkeyAuthentication yes in /etc/ssh/sshd_config on the managed node, and check that the user exists.
4. pip install conflicts with system packages
If you used pip instead of the system package manager and see "ModuleNotFoundError: No module named 'ansible'", the install likely landed in a virtualenv or user-site directory not on PATH. Check:
pip show ansible-core
pip show ansible
echo $PATH
Install inside a virtualenv to keep system Python clean:
python3 -m venv ~/.venvs/ansible
source ~/.venvs/ansible/bin/activate
pip install ansible
See also: Run RHEL 9.2 on Mac Using VMware Fusion: A Step-by-Step Guide
Frequently Asked Questions
What's the difference between ansible and ansible-core?
ansible-core is the engine plus the ansible.builtin collection (~50 modules). The ansible PyPI package bundles ansible-core plus hundreds of community collections, so ansible-galaxy collection list shows everything pre-installed. For minimal Execution Environments and CI, prefer ansible-core and explicitly list collections in requirements.yml.
Should I install Ansible from the package manager or pip?
The system package manager (apt/dnf/apk/pacman) is best for getting started — it installs to PATH and updates with the rest of the OS. Use pip inside a virtualenv when you need a specific version, want to install collections without root, or are building reproducible CI environments. Mixing both on the same system causes PATH ambiguity and is a frequent troubleshooting trap.
How do I update Ansible after the initial install on Gentoo Linux -?
If installed via package manager, sudo dnf update ansible (or sudo apt upgrade ansible on Debian-family). If installed via pip, pip install --upgrade ansible inside the same virtualenv. Always read the changelog before crossing a minor version boundary (e.g. 2.18 → 2.19) — there are sometimes deprecation warnings to address before the next major.
Do I need to install anything on the managed nodes?
For Linux managed nodes: only Python 3 and an SSH server. Ansible is "agentless" — it copies its modules over SSH and runs them on the target. For Windows managed nodes you need WinRM or PSRP configured plus PowerShell 5.1+. No Ansible installation is ever required on the target.
Why does ansible localhost -m ping say "SUCCESS"? It's not a real ping.
The ansible.builtin.ping module does not send ICMP. It tests that Ansible can connect to the target, copy a Python module, execute it, and parse the JSON response. A "SUCCESS" reply means the entire transport pipeline works — which is exactly what you want to confirm after install.
What's Next
Now that Ansible is installed on Gentoo Linux, build on it:
• Write your first playbook
• Ansible inventory: organize your hosts
• Ansible variables and facts explained
• Privilege escalation with become
• Browse all Ansible tutorials
See also: How to Upgrade Ansible on macOS Using Homebrew
Conclusion
Now you know how to install the latest version of Ansible in Gentoo using the Portage package manager.
Related Articles
• AWS automation with Ansible • creating an Ansible role from scratchCategory: installation
Watch the video: How to install Ansible in Gentoo Linux - Ansible install — Video Tutorial