Puppet 在清单文件中合并傀儡代码

Puppet 在清单文件中合并傀儡代码,puppet,Puppet,我正在使用puppet 3.8.7。我想在一个清单文件中编写以下所有代码并运行它。每个代码都可以单独运行。是否可能?首先,我想安装nodejs,然后更新nodejs,然后运行bashscript,然后安装git并下载gitrepo 安装nodejs: class { 'nodejs': repo_url_suffix => '6.x', } 然后更新节点js: exec { 'install-node-version-manager': cwd => '/', pa

我正在使用puppet 3.8.7。我想在一个清单文件中编写以下所有代码并运行它。每个代码都可以单独运行。是否可能?首先,我想安装nodejs,然后更新nodejs,然后运行bashscript,然后安装git并下载gitrepo

安装nodejs:

class { 'nodejs':
  repo_url_suffix => '6.x',
}
然后更新节点js:

exec { 'install-node-version-manager':
cwd       => '/',
path      => '/usr/bin:/bin:/usr/local/bin:/usr/lib/node_modules/npm/bin',
logoutput => 'on_failure',
command   => 'npm install -g n',
}


exec { 'install-node-version-manager':
cwd       => '/',
path      => '/usr/bin:/bin:/usr/local/bin:/usr/lib/node_modules/npm/bin',
logoutput => 'on_failure',
command   => 'n latest',

}
然后运行bash_script.sh

file {'/home/ec2-user/my_bash_script.sh':
 source => "puppet:///modules/mymodule/my_bash_script.sh",
 mode => '755',

}

exec {'/home/ec2-user/my_bash_script.sh':
    refreshonly => 'true',
    require => File["/home/ec2-user/my_bash_script.sh"],
    subscribe => File["/home/ec2-user/my_bash_script.sh"],
  }
然后安装git并下载repo

package 
    { 'git':
      ensure => 'latest',
    }

vcsrepo { "/nodejs-helloworld":
        ensure   => latest,
        provider => git,
        require  => [ Package["git"] ],
        source   => "git@gitlab.dev.abc.net:hello-world/nodejs-helloworld.git",
        revision => 'master',
}

Puppet提供了在资源之间建立关系和排序的各种方法。 您可以使用元参数,例如require、before、notify、subscribe。您还可以使用链接箭头来控制执行流。 这是您的代码,在一个模块中-

 class installnodejs{

  class { 'nodejs':
    repo_url_suffix => '6.x',
    before          => Exec['install-node-version-manager-global'],
  }

  exec { 'install-node-version-manager-global':
    cwd       => '/',
    path      => '/usr/bin:/bin:/usr/local/bin:/usr/lib/node_modules/npm/bin',
    logoutput => 'on_failure',
    command   => 'npm install -g n',
    before    => Exec['install-node-version-manager-latest'],
  }

  exec { 'install-node-version-manager-latest':
    cwd       => '/',
    path      => '/usr/bin:/bin:/usr/local/bin:/usr/lib/node_modules/npm/bin',
    logoutput => 'on_failure',
    command   => 'n latest',
    before    => File['/home/ec2-user/my_bash_script.sh'],
  }

  file {'/home/ec2-user/my_bash_script.sh':
    source => "puppet:///modules/mymodule/my_bash_script.sh",
    mode   => '755',
    before => Exce['/home/ec2-user/my_bash_script.sh'], 
  }

  exec {'/home/ec2-user/my_bash_script.sh':
    refreshonly => 'true',
    require   => File["/home/ec2-user/my_bash_script.sh"],
    subscribe => File["/home/ec2-user/my_bash_script.sh"],
    before    => Vcsrepo['/nodejs-helloworld'],
  }

  package { 'git':
    ensure => 'latest',
  }

  vcsrepo { "/nodejs-helloworld":
    ensure   => latest,
    provider => git,
    require  => [ Package["git"] ],
    source   => "git@gitlab.dev.uberops.net:hello-world/nodejs-helloworld.git",
    revision => 'master',
  }

}

请注意,我已更改了您资源的名称。同一模块中不能包含同一资源两次。

尽管存在风格和效率问题,但所有这些的实质内容都是完全正确的。为什么不把所有这些都放在一个清单中,并根据需要指定依赖项呢?@Ishwarya,你试过了吗?是的,我试过了,把所有东西都放在一个清单文件中就行了。