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
- Enable and start SSH (usually done during installation):
sysrc sshd_enable=YES && service sshd start. - Install Python and sudo:
pkg install python3 sudo. - Create a user for Ansible, add your SSH key to
~/.ssh/authorized_keys, and allow sudo withvisudo(for example%wheel ALL=(ALL:ALL) ALL, with the user in thewheelgroup).
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.