如何使用puppet安装本地rpm

时间:2014-04-20 07:23:28

标签: puppet

我正在尝试使用puppet安装特定的rpm,我的init.pp是:

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

且rpm在...modules/nmap/files

如果我将rpm移动到清单,并在source =&gt;中提供rpm名称''

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

它有效,但我怎样才能用../files/指定源路径并成功应用木偶

当我使用时:

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

我收到错误:

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 `

运行命令时:

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

4 个答案:

答案 0 :(得分:16)

file资源类型不同,package类型不支持Puppet fileserver URLs。在安装之前,您需要使用file资源下载rpm。如果这对您来说是一个反复出现的问题,请创建defined type一次性完成这些问题(想想宏),例如

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"],
  }
}

编辑:通常建议您使用本地yum repo,另请参阅@rojs下面的第一条评论。

答案 1 :(得分:4)

“rpm”包可以这样安装:

 package{'epel-release-6':
            provider => 'rpm',
            ensure => 'present',
            source => '/usr/local/rpms/epel-release-latest-6.noarch.rpm',
        }

编辑:更正错误确认

答案 2 :(得分:1)

您使用的模块名称似乎是nmap。您可以使用相同的source参数,例如

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

访问模块下的文件的语法是这样的,

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

点击此处链接http://docs.puppetlabs.com/puppet/latest/reference/modules_fundamentals.html#files

答案 3 :(得分:0)

让我们从头开始:

在服务器上:

$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]

代理人:

$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',
            }
  }