How to prepare FreeBSD server to be managed by Ansible tool?

Ansible is easy to use IT automation and DevOps tool. One can use it for automation tasks. You can easily configure and manage FreeBSD server using Ansible. Ansible works from a control workstation powered by macOS, Linux or *BSD family of operating systems.


 Enable OpenSSH server on FreeBSD box


Verify it with the following command:

% service -e | grep sshdxyz


If OpenSSH server not enabled on FreeBSD box, type the following command to activate at boot time and start it:

# echo 'sshd_enable="YES"' >> /etc/rc.conf
# service sshd start


Installed sudo on FreeBSD server


Run the following command:

% type sudo


If the sudo command not found, install it using the following pkg command:

# pkg install sudo


Allow members of group wheel to execute any command:

# echo '%wheel ALL=(ALL) ALL' >/usr/local/etc/sudoers.d/allow-wheel-user-login


Make sure regular user is part of the wheel group


Use the id command to find user’s group membership:

% id xyz
uid=1001(xyz) gid=1001(xyz) groups=1001(xyz)


As you can see "xyz" user is not part of the wheel group. Add user "xyz" to the wheel group using pw command

# pw usermod -n xyz -G wheel
# id xyz
uid=1001(xyz) gid=1001(xyz) groups=1001(xyz),0(wheel)


Install Python 2.x or Python 3.x


The final requirement is to install Python on FreeBSD box.

# pkg install python3.6


# pkg install python2.7


Please note down the path for Python:

% type python2.7
python2.7 is /usr/local/bin/python2.7
% type python3.6
python3.6 is /usr/local/bin/python3.6


FreeBSD server to be managed by Ansible tool


First, create an inventory file as follows on a control machine:

$ vi hosts


Add hostnames/IP address of all remote FreeBSD/Linux servers:





Test FreeBSD Ansible setup


Let us run the uptime command and hostname command on above two hosts i.e. myhosts group as user xyz:

$ ansible -u xyz -i hosts -m raw -a 'uptime' myhosts
$ ansible -u xyz -i hosts -m raw -a 'hostname' myhosts


That's it !!

Was this answer helpful? 0 Users Found This Useful (1 Votes)