Install OCS Inventory Agent on Ubuntu 22.04|20.04|18.04

|
Last Updated:
|
|

How can I install OCS Inventory Agent on Ubuntu 22.04/Ubuntu 20.04/Ubuntu 18.04. This is a step by step guide to take you through this process.

Installing OCS Inventory Agent on Ubuntu 22.04|20.04|18.04

Run system update

apt update

Install OCS Inventory Agent

There are two ways in which you can install OCS inventory agent.

  • Install OCS Inventory Agent from OCS APT Repos
  • Compile and Install OCS Inventory Agent from Source Code

Install OCS Inventory Agent from OCS APT Repos

This is the easiest method to install OCS inventory agent.

Install OCS Inventory Ubuntu APT Repos

To install the OCS Inventory APT repository;

apt install gnupg2 curl wget -y
curl -sS http://deb.ocsinventory-ng.org/pubkey.gpg | \
gpg --dearmor -o /etc/apt/trusted.gpg.d/ocs.gpg
echo "deb http://deb.ocsinventory-ng.org/ubuntu/ jammy main" | \
tee /etc/apt/sources.list.d/ocsinventory.list

Once you have the repositories in place, then proceed to run system package cache update.

apt update

Check the available version of OCS inventory agent package;

apt-cache policy ocsinventory-agent

ocsinventory-agent:
  Installed: (none)
  Candidate: 2:2.10.0
  Version table:
     2:2.10.0 500
...

The current version of OCS inventory agent is v2.10.0 as per releases page.

Install OCS Inventory Agent Interactively

Thus, run the command below to install the agent interactively;

apt install ocsinventory-agent

During the installation, you will be prompted to setup OCS agent.

Go through each prompt and provide your appropriate answer;


Do you want to configure the agent
Please enter 'y' or 'n'?> [y] y
Where do you want to write the configuration file?
 0 -> /etc/ocsinventory
 1 -> /usr/local/etc/ocsinventory
 2 -> /etc/ocsinventory-agent
?>  2
Do you want to create the directory /etc/ocsinventory-agent?
Please enter 'y' or 'n'?> [y] y
Should the old unix_agent settings be imported ?
Please enter 'y' or 'n'?> [y] n
[info] The config file will be written in /etc/ocsinventory-agent/ocsinventory-agent.cfg,
What is the address of your ocs server?>  asset-mgr.kifarunix-demo.com
Do you need credential for the server? (You probably don't)
Please enter 'y' or 'n'?> [n] n
Do you want to apply an administrative tag on this machine
Please enter 'y' or 'n'?> [y] y
tag?>  ubuntu12
Do yo want to install the cron task in /etc/cron.d
Please enter 'y' or 'n'?> [y] y
Where do you want the agent to store its files? (You probably don't need to change it)?> [/var/lib/ocsinventory-agent] 
Do you want to create the /var/lib/ocsinventory-agent directory?

Please enter 'y' or 'n'?> [y] y
Should I remove the old unix_agent
Please enter 'y' or 'n'?> [n] y
Do you want to activate debug configuration option ?
Please enter 'y' or 'n'?> [y] n
Do you want to use OCS Inventory NG UNix Unified agent log file ?
Please enter 'y' or 'n'?> [y] y
Specify log file path you want to use?>  /var/log/ocs-agent.log
Do you want disable SSL CA verification configuration option (not recommended) ?
Please enter 'y' or 'n'?> [n] y
Do you want to set CA certificates file path ?
Please enter 'y' or 'n'?> [y] n
Do you want to use OCS-Inventory software deployment feature?
Please enter 'y' or 'n'?> [y] n
Do you want to use OCS-Inventory SNMP scans feature?
Please enter 'y' or 'n'?> [y] y
Do you want to send an inventory of this machine?
Please enter 'y' or 'n'?> [y] y
Setting OCS Inventory NG server address...

And that is it.

The package will also install a cronjob that iventories your system on daily basis;

cat /etc/cron.d/ocsinventory-agent
PATH=/usr/sbin:/usr/bin:/sbin:/bin
15 9 * * * root /usr/bin/ocsinventory-agent --lazy > /dev/null 2>&1

It will also create configs under /etc/ocsinventory-agent/ocsinventory-agent.cfg.

cat /etc/ocsinventory-agent/ocsinventory-agent.cfg

basevardir=/var/lib/ocsinventory-agent
logfile=/var/log/ocs-agent.log
ssl=0
server=http://asset-mgr.kifarunix-demo.com/ocsinventory
debug=
tag=ubuntu12
Install OCS Inventory Agent NON-Interactively

If you want to configure the agent manually yourself, you can run non-interactive installation. This comes in handy especially if you want to script the installation.

DEBIAN_FRONTEND=noninteractive apt install ocsinventory-agent -y

You can then configure the agent yourself.

Create the agent configuration (update the settings below as per your setup);

vim /etc/ocsinventory-agent/ocsinventory-agent.cfg

logfile=/var/log/ocsinventory-agent.log
basevardir=/var/lib/ocsinventory-agent
ssl=0
server=http://192.168.58.31/ocsinventory
debug=0
tag=ubuntu20.04

Compile and Install OCS Inventory Agent from Source Code

This method guarantees the installation of a specific version, including new release versions.

Install Required Libraries

To install OCS Inventory agent will all the required packages, run the command below;

apt install make gcc libmodule-install-perl dmidecode libxml-simple-perl \
libcompress-zlib-perl openssl libnet-ip-perl libwww-perl libdigest-md5-perl \
libdata-uuid-perl libcrypt-ssleay-perl libnet-snmp-perl libproc-pid-file-perl \
libproc-daemon-perl net-tools libsys-syslog-perl pciutils smartmontools read-edid \
nmap libnet-netmask-perl

To install a newer version of OCS Agent, navigate to the OCS Inventory downloads page and grab the source file for the new version.

For example, this guide uses OCS Agent v2.10.0 and can be downloaded as follows;

wget https://github.com/OCSInventory-NG/UnixAgent/releases/download/v2.10.0/Ocsinventory-Unix-Agent-2.10.0.tar.gz

Once the download is done, extract the source code.

tar xzf Ocsinventory-Unix-Agent-2.10.0.tar.gz
Install OCS Inventory Agent from Source code

Navigate to OCS Inventory agent source directory

cd Ocsinventory-Unix-Agent-2.10.0

OCS Agent can be installed interactively or non-interactively.

Install OCS Agent from Source Interactively

To install OCS agent interactively, simply run the commands below;

sudo perl Makefile.PL
sudo make
sudo make install

While setting up the address of your ocs server, if you are using hostname, ensure that it is resolvable.


...
Do you want to configure the agent
Please enter 'y' or 'n'?> [y] y
Where do you want to write the configuration file?
 0 -> /etc/ocsinventory
 1 -> /usr/local/etc/ocsinventory
 2 -> /etc/ocsinventory-agent
?>  2
Do you want to create the directory /etc/ocsinventory-agent?
Please enter 'y' or 'n'?> [y] y
Should the old unix_agent settings be imported ?
Please enter 'y' or 'n'?> [y] y
[info] The config file will be written in /etc/ocsinventory-agent/ocsinventory-agent.cfg,
What is the address of your ocs server?>  https://asset-mgr.kifarunix-demo/ocsinventory        
Do you need credential for the server? (You probably don't)
Please enter 'y' or 'n'?> [n] n
Do you want to apply an administrative tag on this machine
Please enter 'y' or 'n'?> [y] y
tag?>  test-deb10  
Do yo want to install the cron task in /etc/cron.d
Please enter 'y' or 'n'?> [y] y
Where do you want the agent to store its files? (You probably don't need to change it)?> [/var/lib/ocsinventory-agent] 
Do you want to create the /var/lib/ocsinventory-agent directory?

Please enter 'y' or 'n'?> [y] y
Should I remove the old unix_agent
Please enter 'y' or 'n'?> [n] y
Do you want to activate debug configuration option ?
Please enter 'y' or 'n'?> [y] n
Do you want to use OCS Inventory NG UNix Unified agent log file ?
Please enter 'y' or 'n'?> [y] y
Specify log file path you want to use?>  /var/log/ocs-agent.log
Do you want disable SSL CA verification configuration option (not recommended) ?
Please enter 'y' or 'n'?> [n] 
Do you want to set CA certificate chain file path ?
Please enter 'y' or 'n'?> [y] 
Specify CA certificate chain file path?>  /etc/ocsinventory-agent/cacert.pem              
Do you want to use OCS-Inventory software deployment feature?
Please enter 'y' or 'n'?> [y]  
Do you want to use OCS-Inventory SNMP scans feature?
Please enter 'y' or 'n'?> [y] 
Do you want to send an inventory of this machine?
Please enter 'y' or 'n'?> [y]
...
Install OCS Agent from Source NON-Interactively

To install OCS agent non-interactively, simply run the commands below;

sudo env PERL_AUTOINSTALL=1 perl Makefile.PL
sudo make
sudo make install

Then you can configure it (update your configs accordingly);


perl postinst.pl --nowizard \
--server=http://asset-mgr.kifarunix-demo.com/ocsinventory \
--crontab \
--nossl \
--verbose \
--now \
--tag=ubuntu22.04

OCS Inventory Agent-Server Communication

By default, OCS inventory agent is set to communicate with the server once a day via the daily cron job, /etc/cron.d/ocsinventory-agent.

To force the agent to communicate to the server immediately, you can run;

ocsinventory-agent

Or specify address of the server;

ocsinventory-agent --server http://ocsinv.example.com/ocsinventory

Verify Assets Details on OCS Inventory Servery

You can now login to your OCS Inventory server and verify that the assets have been inventoried.

Install OCS Inventory Agent on Ubuntu

Click on All Computers tab to see a list your assets.

Install OCS Inventory Agent on Ubuntu

You can also configure OCS Agent to inventory the system hourly via the cron job.

mv /etc/cron.daily/ocsinventory-agent /etc/cron.hourly

Well, that is just it on how to install OCS Agent on Ubuntu 22.04/Ubuntu 20.04/Ubuntu 18.04. Feel free to explore this tool further.

Reference;

OCS Inventory NG Agent

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
Kifarunix
Linux Certified Engineer, with a passion for open-source technology and a strong understanding of Linux systems. With experience in system administration, troubleshooting, and automation, I am skilled in maintaining and optimizing Linux infrastructure.

Leave a Comment