16

I am trying to install a particular rpm using puppet, my init.pp is:

class nmap {
  package {'nmap':
    provider => 'rpm',
    source => "<Local PATH to the RPM>",
  }
}

and the rpm is in ...modules/nmap/files

If i move the rpm to manifests, and provide the rpm name in source => ''

class nmap {
  package {'nmap':
    provider => 'rpm',
    source => "rpm-name.rpm",
  }
}

it works, but how can i specify source path with ../files/ and do puppet apply successfully

When i use :

source => 'puppet:///files/nmap-6.45-1.x86_64.rpm',

i get an error:

Debug: Executing '/bin/rpm -i puppet:///files/nmap-6.45-1.x86_64.rpm' Error: Execution of '/bin/rpm -i puppet:///files/nmap-6.45-1.x86_64.rpm' returned 1: error: open of puppet:///files/nmap-6.45-1.x86_64.rpm failed: No such file or directory

Error: /Stage[main]/Nmap/Package[nmap]/ensure: change from absent to present failed: Execution of '/bin/rpm -i puppet:///files/nmap-6.45-1.x86_64.rpm' returned 1: error: open of puppet:///files/nmap-6.45-1.x86_64.rpm failed: No such file or directory `

when running the command:

sudo puppet apply --modulepath=/home/user1/qa/puppet_qa/modules/ -e "include nmap" --debug

iamauser
  • 11,119
  • 5
  • 34
  • 52
kamal
  • 9,637
  • 30
  • 101
  • 168
  • Sometimes it is easier to test like this: `sudo puppet apply -e "package { ['your-rpm'] : ensure => 'ver.1' ;}` instead of including files. – MarkHu May 31 '16 at 23:26

4 Answers4

18

Unlike the file resource type, the package type has no support for Puppet fileserver URLs. You will need to use a file resource to download the rpm prior to installing it. If this is a recurring problem for you, make a defined type that does those in one go (think macros), e.g.

define fileserver_package($source, $ensure='installed') {
  file { "/my/tmp/dir/$name.rpm": source => $source }
  package { $name:
    ensure => $ensure,
    provider => 'rpm',
    source => "/my/tmp/dir/$name.rpm",
    require => File["/my/tmp/dir/$name.rpm"],
  }
}

Edit: it is generally advisable to use a local yum repo instead, see also the first comment by @rojs below.

Felix Frank
  • 8,125
  • 1
  • 23
  • 30
  • 3
    A correct answer but I would add that storing rpms in your puppet repository and writing file & package resources every time will get old fast. Best to set up your own yum server and dish the rpms out from there. Take some work to set up but once it's going makes things much easier. – rojs Apr 22 '14 at 03:31
  • // , The above works for Puppet with the puppetlabs/centos-6.6-32-puppet vagrant box from vagrantbox.es. – Nathan Basanese Aug 21 '15 at 23:25
  • provider => 'rpm' was missing for me; otherwise yum is searching for the package, first - which fails in my case – Christian Apr 18 '17 at 08:38
4

The RPM package can be installed this way:

 package { 'epel-release-6':
   provider => 'rpm',
   ensure   => 'present',
   source   => '/usr/local/rpms/epel-release-latest-6.noarch.rpm',
 }
E_net4
  • 27,810
  • 13
  • 101
  • 139
Vadim Sluzky
  • 259
  • 1
  • 2
1

It seems the module name you are using is nmap. You can use the same source parameter like this,

source => 'puppet:///modules/nmap/nmap-6.45-1.x86_64.rpm',

The syntax to access a file under a module goes like this,

  puppet:///modules/<modulename>/<file you want to access>

See this link here, http://docs.puppetlabs.com/puppet/latest/reference/modules_fundamentals.html#files

iamauser
  • 11,119
  • 5
  • 34
  • 52
0

Lets start from start :

on server:

$rpm -ivh https://yum.puppetlabs.com/puppetlabs-release-pc1-el-7.noarch.rpm
$yum -y install puppetserver
$vi /etc/sysconfig/puppetserver #change JAVA args
$systemctl start puppetserver
$systemctl enable puppetserver
$vi /etc/puppetlabs/puppet/puppet.conf #Add “dns_alt_names” in [master]

On Agent:

$rpm -ivh https://yum.puppetlabs.com/puppetlabs-release-pc1-el-7.noarch.rpm
$yum -y install puppet-agent
$systemctl start puppet
$systemctl enable puppet
$vi /etc/puppetlabs/puppet/puppet.conf # Add “server = pupmaster” in [main]


puppet cert list
puppet cert sign




/etc/puppetlabs/code/environments/production/manifests/site.pp:

node webserver {
  class { 'apache': }
}

node dbserver {
  class { ‘mysql’: }
}


mkdir –p /etc/puppetlabs/code/environments/production/modules/apache/{manifests, files}

apacheinstall.pp:

  class apache::apacheinstall {

    if $osfamily == 'redhat' {

            package { 'httpd':
                      ensure => 'latest'
                    }

            service {'httpd':
                       ensure => 'running',
                      require => Package["httpd"],
                    }

            file { '/var/www/html/ndex.html':
                    mode => "0644",
                    owner => 'root',
                    group => 'root',
                    source => 'puppet:///modules/apache/index.html',
                  }
    }
    elsif $osfamily == 'debian' {

            package { 'apache2':
                      ensure => 'latest'
                    }

            service {'httpd':
                      ensure => 'running',
                      require => Package["httpd"],
                    }
    }
  }

INIT.pp

  class apache {
    notify { 'Installing and Configuring Webserver for $osfamily': }
    include apache::mysqlinstall
  }

Mysqlinstall.pp:

  class apache::mysqlinstall {

            exec { 'wget':
            path      => [ "/bin/", "/sbin/", "/usr/bin/", "/usr/sbin/" ],
            command   => "/usr/bin/wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm && rpm -ivh /tmp/mysql57-community-release-el7-9.noarch.rpm",
            cwd       => '/tmp/',
            creates   => '/etc/firstruns/p1.done',
            }
  }
Vitaly Migunov
  • 4,297
  • 2
  • 19
  • 23