Updated: 28 September 2026 · Applies to: FreeBSD 14.x and 15.x with Ansible

Ansible manages servers over SSH and needs Python on the managed machine. FreeBSD does not include Python by default, so install it first. These steps are for FreeBSD 14.x and 15.x.

On the FreeBSD server

  1. Enable and start SSH (usually done during installation): sysrc sshd_enable=YES && service sshd start.
  2. Install Python and sudo: pkg install python3 sudo.
  3. Create a user for Ansible, add your SSH key to ~/.ssh/authorized_keys, and allow sudo with visudo (for example %wheel ALL=(ALL:ALL) ALL, with the user in the wheel group).

On your Ansible machine

Tell Ansible where Python is on FreeBSD, in the inventory:

[freebsd]
bsd1.example.com

[freebsd:vars]
ansible_user=admin
ansible_python_interpreter=/usr/local/bin/python3
ansible_become=true

Test

ansible freebsd -i inventory.ini -m ping
ansible freebsd -i inventory.ini -m community.general.pkgng -a "name=nginx state=present" -K

The community.general.pkgng module manages FreeBSD packages; ansible.builtin.service works with FreeBSD's rc services.

A first playbook

- hosts: freebsd
  tasks:
    - name: Install and start nginx
      community.general.pkgng:
        name: nginx
        state: present
    - name: Enable nginx at boot
      community.general.sysrc:
        name: nginx_enable
        value: "YES"
    - name: Start nginx
      ansible.builtin.service:
        name: nginx
        state: started

Run it with ansible-playbook -i inventory.ini site.yml -K. Install the collection first if needed: ansible-galaxy collection install community.general.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Managed dedicated servers

our engineers look after the server for you, from $135 a month.

Was this answer helpful?

Still stuck? Open a ticket