Installing and configuring a Networker client is very easy. In case of Linux OS it could be as easy as running “rpm” or “dpkg” command after login to the server and start the “networker” service.
However when you have to do it on hundreds of systems, it is no fun.
So what are the options?
- Manual Installation: SSH to those hundreds of systems and install is manually. Of course, it is a tiresome and boring task.
- Scripted Installation: Good idea. However someone has to write, test and manage the script. And when the script owner is not around, others may have to be ready to debug the script if required.
- Use a Configuration Management Tool: These tools allow organizations to control the exact configuration of as many as thousands of nodes from a single central server. Puppet, Chef and Ansible are popular Opensource tools around. These tools also ensure that service and configuration of the clients remain in desired state.
For new installation of servers you may add the Networker client in the golden image for your OS however there might be some work to clear peer information (in some cases). However additional advantage of configuration management tools is that it also maintains the desired state of client service and configuration. Let’s see this in action.
You can find number of posts about comparison of these tool on internet. I am going to use Puppet to install and configure Networker client on four Linux servers. Puppet can run in Standalone or in Master-Agent mode.
I am using Master-Agent/Client mode and here is my setup. Each client contacts the server periodically (every half hour, by default), downloads the latest configuration, and makes sure it is in sync with that configuration. Once done, the client can send a report back to the server indicating if anything needed to change.
Puppet Setup (if puppet is not setup in your environment)
Puppet Master:
Enable the Puppet Labs repository and install Puppet Server
- # rpm -ivh https://yum.puppetlabs.com/puppetlabs-release-pc1-el-7.noarch.rpm
- # yum -y install puppetserver
Sample puppet configuration file
- # cat /etc/puppetlabs/puppet/puppet.conf
- # This file can be used to override the default puppet settings.
- # See the following links for more details on what settings are available:
- # - https://docs.puppetlabs.com/puppet/latest/reference/config_important_settings.html
- # - https://docs.puppetlabs.com/puppet/latest/reference/config_about_settings.html
- # - https://docs.puppetlabs.com/puppet/latest/reference/config_file_main.html
- # - https://docs.puppetlabs.com/puppet/latest/reference/configuration.html
- [main]
- certname = <puppetmaster-fqdn>
- server = <puppetmaster>
- environment = production
- runinterval = 1h
- strict_variables = true
-
- [master]
- dns_alt_names = <any other dns names for puppet master>
- vardir = /opt/puppetlabs/server/data/puppetserver
- logdir = /var/log/puppetlabs/puppetserver
- rundir = /var/run/puppetlabs/puppetserver
- pidfile = /var/run/puppetlabs/puppetserver/puppetserver.pid
- codedir = /etc/puppetlabs/code
- #
Start the server and enable autostart at server boot
- # systemctl start puppetserver
- # systemctl enable puppetserver
Puppet Agent:
Enable the Puppet Labs repository and install Puppet Agent
- # rpm -ivh https://yum.puppetlabs.com/puppetlabs-release-pc1-el-7.noarch.rpm
- # yum -y install puppet-agent
Sample puppet configuration file
- # cat /etc/puppetlabs/puppet/puppet.conf
- # This file can be used to override the default puppet settings.
- # See the following links for more details on what settings are available:
- # - https://docs.puppetlabs.com/puppet/latest/reference/config_important_settings.html
- # - https://docs.puppetlabs.com/puppet/latest/reference/config_about_settings.html
- # - https://docs.puppetlabs.com/puppet/latest/reference/config_file_main.html
- # - https://docs.puppetlabs.com/puppet/latest/reference/configuration.html
- [main]
- certname = <puppetagent-fqdn>
- server = <puppetmaster>
- environment = production
- runinterval = 1h
- #
Start the agent
- # /opt/puppetlabs/bin/puppet resource service puppet ensure=running enable=true
- Notice: /Service[puppet]/ensure: ensure changed 'stopped' to 'running'
- service { 'puppet':
- ensure => 'running',
- enable => 'true',
- }
- #
SSL Certificate:
Before Puppet agent nodes can retrieve their configuration catalogs, they need a signed certificate from the local Puppet certificate authority (CA). When using Puppet’s built-in CA, agents will submit a certificate signing request (CSR) to the CA Puppet master and will retrieve a signed certificate once one is available.
List the unsigned certificates on puppet master
- # /opt/puppetlabs/bin/puppet cert list
- "pupetagent-01" (SHA256) 0B:78:EF:AC:A5:AC:13:35:61:C9:1B:54:CF:31:C9:1E:B5:8B:D1:1F:FE:00:43:16:CA:19:3D:E0:7F:9B:0F:87
- #
Sign the certificate request on puppet master
- # /opt/puppetlabs/bin/puppet cert sign "pupetagent-01"
- Signing Certificate Request for:
- " pupetagent-01" (SHA256) CF:B6:29:52:F9:BF:30:20:F8:9B:58:0A:F7:BC:4E:FC:B6:93:0F:86:8A:C8:39:FE:C4:6E:00:BF:5E:C3:07:1C
- Notice: Signed certificate request for puppetagent-01
- Notice: Removing file Puppet::SSL::CertificateRequest pupetagent-01
- at '/etc/puppetlabs/puppet/ssl/ca/requests/ pupetagent-01.pem'
- #
You may sign all the certs at one go
- # /opt/puppetlabs/bin/puppet cert sign –all
With this, we are ready to use puppet as we desire.
Sample Puppet Manifest
Puppet uses manifest file for configuration on agent. Here is the sample manifest file.
- # cat /etc/puppetlabs/code/environments/production/manifests/sample.pp
- node 'puppetagent-01’ {
- file {'/tmp/file1' : # resource type file and filename
- ensure => present, # make sure it exists
- mode => '0644', # file permissions
- content => "Any Content", # content of the file
- }
- }
- node default {}
- #
This will ensure that the file “/tmp/file1” with be present on the node “puppetagent-01” with desired permission and content. If the content or the permission is changed on the agent or if the file is deleted, puppet will ensure that it will be recreated with the desired state.
This manifest manages the “resource” named “file”. Other valid resources are cron, mount, service, package etc. Multiple resources can be combined under “class” and multiple classes can be stored under a “module”.
Puppet Module for Networker Client
With this background of Puppet, let us write manifest file to install the Networker client. Do remember that Puppet is very particular about file names and its location.
Let us create our own module..
- # puppet module generate bh-mynetworker
- We need to create a metadata.json file for this module. Please answer the
- following questions; if the question is not applicable to this module, feel free
- to leave it blank.
-
- Puppet uses Semantic Versioning (semver.org) to version modules.
- What version is this module? [0.1.0]
- -->
-
- Who wrote this module? [bh]
- -->
-
- What license does this module code fall under? [Apache-2.0]
- -->
-
- How would you describe this module in a single sentence?
- -->
-
- Where is this module's source code repository?
- -->
-
- Where can others go to learn more about this module?
- -->
-
- Where can others go to file issues about this module?
- -->
-
- ----------------------------------------
- {
- "name": "bh-mynetworker",
- "version": "0.1.0",
- "author": "bh",
- "summary": null,
- "license": "Apache-2.0",
- "source": "",
- "project_page": null,
- "issues_url": null,
- "dependencies": [
- {"name":"puppetlabs-stdlib","version_requirement":">= 1.0.0"}
- ],
- "data_provider": null
- }
- ----------------------------------------
-
- About to generate this metadata; continue? [n/Y]
- -->
-
- Notice: Generating module at /etc/puppetlabs/code/environments/production/modules/mynetworker...
- Notice: Populating templates...
- Finished; module generated in mynetworker.
- mynetworker/Gemfile
- mynetworker/Rakefile
- mynetworker/examples
- mynetworker/examples/init.pp
- mynetworker/manifests
- mynetworker/manifests/init.pp
- mynetworker/spec
- mynetworker/spec/classes
- mynetworker/spec/classes/init_spec.rb
- mynetworker/spec/spec_helper.rb
- mynetworker/README.md
- mynetworker/metadata.json
- #
This generates a module named “mynetworker”, its directory tree and a blank “mynetworker/manifests/init.pp” as below
- # cat mynetworker/manifests/init.pp
- class mynetworker {
-
- }
- #
Create a directory called “files” under the module name and store the networker client rpm package under it.
- # ls -l mynetworker/files/
- total 55980
- -rw-r--r-- 1 root root 57319869 Dec 7 2015 lgtoclnt-9.0.0.2-1.x86_64.rpm
- #
So the url to access above file would be “puppet:///modules/mynetworker/lgtoclnt-9.0.0.2-1.x86_64.rpm”
Let’s fill up the content of init.pp as below
- # cat mynetworker/manifests/init.pp
- class mynetworker {
-
- #step01 - copy the rpm package
- file {'/tmp/lgtoclnt-9.0.0.2-1.x86_64.rpm': # resource type file and filename on puppetagent
- ensure => present, # make sure it exists
- source => 'puppet:///modules/mynetworker/lgtoclnt-9.0.0.2-1.x86_64.rpm', # source location on the puppetmaster
- }
-
- #step02 - install the package
- package {'lgtoclnt-9.0.0.2-1.x86_64': # package name to be installed
- provider => 'rpm',
- ensure =>installed,
- install_options => ['--nodeps'],
- source => '/tmp/lgtoclnt-9.0.0.2-1.x86_64.rpm', # source of the package
- require => File['/tmp/lgtoclnt-9.0.0.2-1.x86_64.rpm'], # dependency
- }
-
- #step03 - start the networker service
- service {'networker': # service name
- ensure => running, # desired state
- enable => true, # desired state at server boot
- require => Package['lgtoclnt-9.0.0.2-1.x86_64'], # dependency
- }
- }
** Of course if you have private yum repository setup, step01 can be avoided and step02 can be modified to install the package using yum. **
With this our module “mynetworker” is ready and it can be used in the manifest files for your environment.
In my setup, I have include it in the site.pp file as below
- # pwd
- /etc/puppetlabs/code/environments/production/manifests
- # cat site.pp
- node 'puppetagent-01','puppetagent-02',‘puppetagent-03’,’puppetagent-04’ {
- include mynetworker
- }
-
- node default {}
- #
This will automate the installation of Networker client on the four puppet agent servers as specified.
If there is a need to troubleshoot or manually test the agent, use the following command
- # /opt/puppetlabs/bin/puppet agent --test --verbose
- Info: Using configured environment 'production'
- Info: Retrieving pluginfacts
- Info: Retrieving plugin
- Info: Loading facts
- Info: Caching catalog for puppetagent-01
- Info: Applying configuration version '1472969856'
- Notice: /Stage[main]/Mynetworker/Service[networker]/ensure: ensure changed 'stopped' to 'running'
- Info: /Stage[main]/Mynetworker/Service[networker]: Unscheduling refresh on Service[networker]
- Notice: Applied catalog in 241.67 seconds
- #
And the result………..
- # ls -l /tmp/lgtoclnt-9.0.0.2-1.x86_64.rpm
- -rw-r--r-- 1 root root 57319869 Sep 4 14:51 /tmp/lgtoclnt-9.0.0.2-1.x86_64.rpm
- # rpm -qa | grep -i lgt
- lgtoclnt-9.0.0.2-1.x86_64
- # ps -aef | grep -i nsr
- root 22015 1 3 14:46 ? 00:00:41 /usr/sbin/nsrexecd
- root 23046 20899 0 15:08 pts/0 00:00:00 grep --color=auto -i nsr
- #
I have tested above on CentOS7 and it's working fine. If your Linux flavor is different, little modification may be required in above code.
Hope this will be useful to automate the installation of Networker client on hundreds of servers where Puppet is already configured.
Do share your feedback. Thank you!