我正在使用puppet 3.8.7。我想在单个清单文件中编写以下所有代码并运行它。每个代码都可以单独运行。它可能吗?首先,我想安装nodejs,然后更新我的nodejs,然后运行我的bashscript,然后安装git并下载git repo
安装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',
}
答案 0 :(得分:1)
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',
}
}
请注意我已经更改了您的资源名称。您不能在同一模块中两次包含相同的资源。