【问题标题】:Install Apache from Puppetlabs on Vagrant在 Vagrant 上从 Puppetlabs 安装 Apache
【发布时间】:2014-01-13 22:30:56
【问题描述】:

我是新手,我想我只是错过了一件事来了解问题的真正含义。

我知道我可以创建自己的 puppet 模块,将某些包页面安装到 vagrant 实例。还有一些现成的,比如这个apache。我跑了 vagrant ssh 并使用 puppet module install puppetlabs/apache 安装它。它现在位于/etc/puppet/modules/apache 下。但是,没有安装 apache。

那么,如何安装 apache

在我的 Vagrantfile 中有

config.vm.provision :puppet do |puppet|
  puppet.manifests_path = "puppet/manifests"
  puppet.module_path = "puppet/modules"
  puppet.manifest_file  = "init.pp"
  puppet.options="--verbose --debug"
end

另外,在主 vagrant 目录下,puppet/modules/apache/manifests/init.pp:

class apache2::install {
  package { 'apache2':
    ensure => present,
  }
}

然而,在vagrant provisionvagrant reload 之后没有安装apache,或者我猜,安装过程甚至没有开始。 在vagrant provision 之后登录,我觉得他的消息完全神秘。

[default] Running provisioner: puppet...
Running Puppet with init.pp...
debug: Creating default schedules
debug: Puppet::Type::User::ProviderDirectoryservice: file /usr/bin/dscl does not exist
debug: Puppet::Type::User::ProviderUser_role_add: file rolemod does not exist
debug: Puppet::Type::User::ProviderLdap: true value when expecting false
debug: Puppet::Type::User::ProviderPw: file pw does not exist
debug: Failed to load library 'ldap' for feature 'ldap'
debug: /File[/var/lib/puppet/ssl/certificate_requests]: Autorequiring File[/var/lib/puppet/ssl]
debug: /File[/var/lib/puppet/state/graphs]: Autorequiring File[/var/lib/puppet/state]
debug: /File[/var/lib/puppet/ssl/public_keys]: Autorequiring File[/var/lib/puppet/ssl]
debug: /File[/var/lib/puppet/facts]: Autorequiring File[/var/lib/puppet]
debug: /File[/var/lib/puppet/ssl/private_keys]: Autorequiring File[/var/lib/puppet/ssl]
debug: /File[/var/lib/puppet/client_yaml]: Autorequiring File[/var/lib/puppet]
debug: /File[/var/lib/puppet/state/last_run_report.yaml]: Autorequiring File[/var/lib/puppet/state]
debug: /File[/var/lib/puppet/client_data]: Autorequiring File[/var/lib/puppet]
debug: /File[/var/lib/puppet/state/state.yaml]: Autorequiring File[/var/lib/puppet/state]
debug: /File[/var/lib/puppet/ssl/certs]: Autorequiring File[/var/lib/puppet/ssl]
debug: /File[/var/lib/puppet/lib]: Autorequiring File[/var/lib/puppet]
debug: /File[/var/lib/puppet/ssl/private]: Autorequiring File[/var/lib/puppet/ssl]
debug: /File[/var/lib/puppet/state/last_run_summary.yaml]: Autorequiring File[/var/lib/puppet/state]
debug: /File[/var/lib/puppet/state]: Autorequiring File[/var/lib/puppet]
debug: /File[/var/lib/puppet/clientbucket]: Autorequiring File[/var/lib/puppet]
debug: /File[/var/lib/puppet/ssl]: Autorequiring File[/var/lib/puppet]
debug: Finishing transaction 70208664910260
debug: Loaded state in 0.00 seconds
debug: Loaded state in 0.00 seconds
info: Applying configuration version '1389652562'
debug: /Schedule[daily]: Skipping device resources because running on a host
debug: /Schedule[monthly]: Skipping device resources because running on a host
debug: /Schedule[hourly]: Skipping device resources because running on a host
debug: /Schedule[never]: Skipping device resources because running on a host
debug: /Schedule[weekly]: Skipping device resources because running on a host
debug: /Schedule[puppet]: Skipping device resources because running on a host
debug: Finishing transaction 70208665347780
debug: Storing state
debug: Stored state in 0.00 seconds
notice: Finished catalog run in 0.05 seconds
debug: Finishing transaction 70208665012580
debug: Received report to process from localhost.localdomain
debug: Processing report from localhost.localdomain with processor Puppet::Reports::Store 

【问题讨论】:

    标签: apache vagrant puppet puppetlabs-apache


    【解决方案1】:

    你告诉 Vagrant 它应该在 puppet/manifests(相对于你的 Vagrant 目录)中查找清单,并且它应该根据 init.pp 中的任何内容配置机器,它将在 @987654324 中查找@(根据您的指示)。也就是说,Vagrant 将安装puppet/manifests/init.pp 中的任何内容。它不会看puppet/modules/apache/manifests/init.pp(至少一开始不会)。

    puppet/manifests/init.pp 中添加类似以下内容,它应该可以正确安装。

    class {'apache':}
    

    除了 apache 模块之外,请确保在您的 puppet/modules 目录中也安装了所有依赖项(在本例中是来自 Puppetlabs 的 stdlib 和 concat 模块)。

    【讨论】:

    • 在模块页面forge.puppetlabs.com/puppetlabs/apache#setup 开头告诉我class { 'apache': }。但是我把它放在哪里了?我不在我的主要 init.pp 中工作
    • class {'apache':} 在您的<vagrant dir>/puppet/manifests/init.pp 文件中应该可以工作。确保在 <vagrant dir>/puppet/modules/ 目录中有 stdlib 和 concat 的副本(我只是从它们各自的 Github 存储库中克隆这些副本)。
    • 谢谢,有帮助。我现在实际上是从 puppetforge 安装它们。
    • 没问题。根据 apache 模块自述文件更新了使用基本 apache 类的答案,并且还包括了有关依赖项的注释。乐意接受吗?
    【解决方案2】:

    我选择了一个我不太喜欢的解决方案,因为它会覆盖任何不是由 puppet 配置的设置。但是,嘿,它可以顺利完成工作。

    我的流浪文件:

    VAGRANTFILE_API_VERSION = "2"
    
    Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
    
      config.vm.box = "base"
      #config.vm.box_url = "http://domain.com/path/to/above.box"
    
      config.vm.network :forwarded_port, guest: 80, host: 5656, auto_correct: true
    
      config.vm.provision :shell do |shell|
        shell.inline = "mkdir -p /etc/puppet/modules;
                        puppet module install puppetlabs-concat --force --modulepath '/vagrant/puppet/modules'
                        puppet module install puppetlabs-stdlib --force --modulepath '/vagrant/puppet/modules'
                        puppet module install puppetlabs-apache --force --modulepath '/vagrant/puppet/modules'"
      end
    
    
      config.vm.provision :puppet do |puppet|
        puppet.manifests_path = "puppet/manifests"
        puppet.module_path = "puppet/modules"
        puppet.manifest_file  = "init.pp"
        puppet.options="--verbose --debug"
      end
    
    end
    

    注意:脚本实际上也可以在没有--force --modulepath '/vagrant/puppet/modules 的情况下工作

    我的puppet/manifests/init.pp

    node default {
        class { 'apache':  }
    }
    

    感谢https://stackoverflow.com/a/21105703/2066118 为我指明了正确的方向。

    【讨论】:

    • 无需在 VM 内运行 shell 命令。 VM 上的 /vagrant/puppet/modules/ 只是 Vagrant 文件中的 puppet.module_path 设置所指向的主机主机上目录的副本。在<vagrant dir>/puppet/modules/ 中安装(我通常只是从他们的 Github 存储库中克隆它们的副本)这些模块,它们将可供您的 VM 使用。 Afaik 这是标准操作程序。
    • 另外,在node default 节点内声明你的类是行不通的,但没必要这样做:)
    • 到目前为止,您的建议非常有帮助。感谢那。在使用librarian-puppet 时,我在掌握项目的正确组织(和自写模块的使用)方面仍然存在一个小问题。您能抽出几分钟时间来回答几个理论问题吗?
    • 当然。只需将它们作为问题提交并在 puppet 下标记它们,当它们出现时我会回答它们。
    【解决方案3】:

    我不确定 Vagrant,但在 puppet 中,您需要在“/etc/puppet/manifests/site.pp”文件的节点中提及需要安装的内容。

    所以会是这样的。

    节点'hosts.fqdn' {

    include apache2 
    

    }

    欲了解更多信息:http://docs.puppetlabs.com/puppet/2.7/reference/lang_node_definitions.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-08
      • 1970-01-01
      • 2017-10-22
      • 1970-01-01
      • 1970-01-01
      • 2016-12-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多