This page contains an example of a Manifest that installs the Cmd agent via Puppet.

Puppet is commonly used in a client-server model, but this example uses a standalone model wherein puppet configures the virtual machine where it is running. 

Before reading this page, you should know how to automate agent deployment, and may want to review how to deploy the agent in containers

Last-tested version of Puppet:

This was last tested with Puppet v7.0.0.

 
The example manifest

What the example does:

  • First, it uses your Cmd API key to download the Cmd agent installation package (please note the download URL is subject to change in future releases).
  • Second, it installs the package.

You can adapt it for non-Debian/Ubuntu systems by referring to the inline code comments.

The manifest:

#######-CONFIGURATION-#############
node puppet-agent {
$cmd_api_key = 'EXAMPLEKEY'
$cmd_hostname = 'puppet-agent'
$cmd_arch = "amd64" #Supported values: amd64
$cmd_format = "deb" #Supported values: deb, rpm
$cmd_version = '' #Supported values: a supported version number, or empty for the latest version
$cmd_agent_type = 'ccf' #Supported values: cmd, ccf
$cmd_sub = 'sub2' #Your Cmd web app subdomain (e.g. sub1, sub2, sub3)
$cmd_config_file = "server_name=${cmd_hostname}
groups=
http_proxy=
url=https://${cmd_sub}.c-app.cmd.com/ws
sos_url=https://${cmd_sub}.sos-app.cmd.com
"
###################################
exec { "/tmp/${cmd_agent_type}-${cmd_version}.${cmd_format}":
command => "/usr/bin/curl -s -L -o /tmp/${cmd_agent_type}-${cmd_version}.${cmd_format} -H 'project-key: ${cmd_api_key}' \"https://${cmd_sub}.c-app.cmd.com/download/${cmd_agent_type}?architecture=${cmd_arch}&format=${cmd_format}&version=${cmd_version}\"",
creates => "/tmp/${cmd_agent_type}-${cmd_version}.${cmd_format}"
}
package { "${cmd_agent_type}":
#Note: Upgrading the agent can be done through the WebUI, so we recommend 'installed' here
ensure => 'installed',
provider => 'dpkg',
source => "/tmp/${cmd_agent_type}-${cmd_version}.${cmd_format}",
require => Exec["/tmp/${cmd_agent_type}-${cmd_version}.${cmd_format}"]
}
file { '/etc/cmd/config.ini':
notify => Service['cmd'],
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
content => $cmd_config_file,
require => Package["${cmd_agent_type}"],
}
file { '/etc/cmd/cmd.prj':
notify => Service['cmd'],
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
content => $cmd_api_key,
require => File['/etc/cmd/config.ini'],
}
service { 'cmd':
ensure => 'running',
enable => true,
require => File['/etc/cmd/cmd.prj'],
}
}

   
 

How to use the example manifest

Required configuration
Input values for: 

  •  cmd_api_key  — your project key.  
  •  cmd_hostname  — Up to 128 characters that identify a server in the web app.
  •  cmd_project_id  — a code found in the URL of a project's Sessions page, for example, in the url  app.cmd.com/sources/PRJ-4N2/  the ID is  PRJ-4N2 .
  • cmd_arch — Currently, the only valid value is amd64 .
  • cmd_format — Either deb or rpm , depending on the target OS.
  • cmd_version — The version of the agent you wish to download. Use a supported version number, or leave it blank for the latest version.
  • cmd_agent_type — Choose whether to install the Cmd Control or Cmd Audit agent. Use ccf for the Cmd Control agent, or cmd for the Cmd Audit agent. (Make sure that the version number you specify matches the agent_type .)
  • cmd_sub — Your Cmd instance's subdomain. For example if your Cmd web app is at sub1.app.cmd.com , it should be "sub1". If it's at sub2.app.cmd.com , it should be "sub2".

Also,

  • The hostname of the VM defined in the vagrantfile (see below) must match the hostname in the ‘node’ section at the top of the puppet manifest file.
     

Optional configuration
Input values for: 

  •  groups  
  •  https_proxy  

By adding a value for groups, new servers can be added to one or more server groups. Group names with spaces are not valid. For multiple server groups, use a comma-delimited list with no spaces, e.g.:  groups=Test1,Test2,Test3 .

 
 

How the example was tested

This was tested using puppet in standalone mode by:

  • Creating a VM with vagrant 
  • Setting the hostname to puppet-agent 
  • Installing puppet 
  • Writing the above manifest to /etc/puppet/manifests/site.pp 
  • Installing the stdlib module with  puppet module install puppetlabs-stdlib  
  • Running it with puppet apply --test /etc/puppet/manifests/site.pp 

Testing took place on Ubuntu 16.04 Xenial with following vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.define "agent" do |agent|
    agent.vm.network "private_network", ip: "192.168.50.5"
    agent.vm.box = "ubuntu/xenial64"
    agent.vm.hostname = "puppet-agent"
   
    agent.vm.provider 'virtualbox' do |vb|
      # Growing the VM to match the puppet defaults is easier than adjusting them all
      vb.memory = 3096

      # speed up the vagrant-up process
      vb.linked_clone = true
    end

    # Add names to hosts file
    agent.vm.provision "shell", inline: "sudo hostname puppet-agent"

    # Apply any pending upgrades
    agent.vm.provision "shell", inline: "sudo apt-get update; sudo apt-get upgrade -y"

    # Add the puppetlabs repo to /etc/apt/sources.list.d/puppetlabs-pc1.list
    agent.vm.provision "shell", inline: "curl -O https://apt.puppetlabs.com/puppetlabs-release-pc1-xenial.deb"
    agent.vm.provision "shell", inline: "sudo dpkg -i puppetlabs-release-pc1-xenial.deb"

    # Install puppetagent
    agent.vm.provision "shell", inline: "sudo apt-get update"
    agent.vm.provision "shell", inline: "sudo apt-get install puppet-agent -y"
  end
end
Did this answer your question?