Though Ansible works with both Python 2 and 3 versions, FreeBSD has different packages for each Python version.
So to install you can use:
You can install Ansible on FreeBSD either from a package or from a port. See the FreeBSD handbook `Chapter 4. Installing Applications: Packages and Ports <https://docs.freebsd.org/en/books/handbook/ports/>`_. A best practice is to use the packages on the fresh installation of the system and both update and upgrade from the ports later. It's not recommended to mix the installation from packages and ports, that is, keep updating and upgrading from the ports. See the warning in the FreeBSD handbook `4.5. Using the Ports Collection <https://docs.freebsd.org/en/books/handbook/ports/#ports-using>`_.
..code-block:: bash
$ sudo pkg install py27-ansible
FreeBSD packages
^^^^^^^^^^^^^^^^
or:
The installation from the packages is simpler, compared to the installation from the ports. See the details in the FreeBSD handbook `4.3. Finding Software <https://docs.freebsd.org/en/books/handbook/ports/#ports-finding-applications>`_ and `4.4. Using pkg for Binary Package Management <https://docs.freebsd.org/en/books/handbook/ports/#pkgng-intro>`_. Take a look at available packages, for example:
..code-block:: bash
$ sudo pkg install py37-ansible
shell> pkg search ansible
ansible-sshjail-1.1.0.35 Ansible connector for remote jails
py38-ansible-4.7.0 Radically simple IT automation
py38-ansible-base-2.10.15 Radically simple IT automation
py38-ansible-core-2.11.6 Radically simple IT automation
py38-ansible-iocage-g20200327,1 Ansible module for iocage
py38-ansible-kld-g20200803,1 Ansible module to load kernel modules or update /boot/loader.conf
py38-ansible-lint-5.3.2 Checks playbooks for sub-optimal practices and behaviour
py38-ansible-sysrc-g20200803_1,1 Ansible module to set sysvars in rc.conf
py38-ansible2-2.9.27 Radically simple IT automation
Pick the flavor of the package (only py38 is available in the example above) and install the package (as a root, of course).
..code-block:: bash
shell> pkg install py38-ansible
You may also wish to install from ports, run:
The dependencies will be installed automatically after you approve them. For example, the installation of py38-ansible depends on the packages listed below
..code-block:: bash
$ sudo make -C /usr/ports/sysutils/ansible install
shell> pkg info -d py38-ansible
py38-ansible-4.3.0:
py38-ansible-core-2.11.3
python38-3.8.12
py38-setuptools-57.0.0
You can also choose a specific version, for example ``ansible25``.
Older versions of FreeBSD worked with something like this (substitute for your choice of package manager):
FreeBSD ports
^^^^^^^^^^^^^
The installation from the ports is more complex, compared to the installation from the packages, but flexible. See the details in the FreeBSD handbook `4.5. Using the Ports Collection <https://docs.freebsd.org/en/books/handbook/ports/#ports-using>`_. To install Ansible from a port change the directory and install the port (as a root, of course)
..code-block:: bash
$ sudo pkg install ansible
shell> cd /usr/ports/sysutils/ansible
shell> make install clean
..note::
If you want to learn more about flavors see Porter's Handbook `Chapter 7. Flavors <https://docs.freebsd.org/en/books/porters-handbook/flavors/>`_.