The solution below solved one problem but another has popped up:
Here is the code:
exec { "Download Phalcon":
path => ["/usr/bin/", "/home/cphalcon/build"],
command => "git clone git://github.com/phalcon/cphalcon.git /home/cphalcon",
require => [Package["git"], Package["php5-fpm"]]
}
exec { "Build Phalcon":
require => Exec["Download Phalcon"],
command => "./install",
# creates => "/home/cphalcon/build",
cwd => "/home/cphalcon/build",
path => ["/usr/bin", "/home/cphalcon/build"]
}
Here are the errors:
==> default: Error: ./install: line 38: rm: command not found
==> default: ./install: line 64: phpize: command not found
==> default: Error: /Stage[main]/Main/Exec[Build Phalcon]/returns: change from notrun to 0 failed: ./install: line 38: rm: command not found
==> default: ./install: line 64: phpize: command not found
Any ideas? phpize is not missing when I manually invoke ./install from the CLI - why would it be missing now?
The exec command does not work that way when it comes to the cwd parameter. It sets the current directory, but does not allow commands to be ran relative to that directory.
You need to also set the path parameter (so path => ['/home/cphalcon/build'] in your case). Take a look at this documentation
Related
i'm running neovim 0.5 with fzf-vim on windows 10 and can't seem to make preview to work.
my init.vim per below:
call plug#begin('~/AppData/Local/nvim/plugged')
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
call plug#end()
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.9 } }
let $FZF_DEFAULT_OPTS="--ansi --preview-window 'right:60%' --layout reverse --margin=1,4"
Error msg i got when previewing files using :Files or :Rg command: /mnt/c/Users/XXXXX/AppData/Local/nvim/plugged/fzf.vim/bin/preview.sh: line 2: $'\r': command not found
/mnt/c/Users/XXXXX/AppData/Local/nvim/plugged/fzf.vim/bin/preview.sh: line 5: $'\r': command not found
/mnt/c/Users/XXXXX/AppData/Local/nvim/plugged/fzf.vim/bin/preview.sh: line 40: syntax error near unexpected token
/mnt/c/Users/XXXXX/AppData/Local/nvim/plugged/fzf.vim/bin/preview.sh: line 40: ` elif [ -n "$MSWINHOME" ]; then
have confirmed that bash.exe from c:\Program Files\Git\bin\ is in PATH.
Install Git for Windows if you haven't already installed it.
Add the following line to your init.vim file.
let $PATH = "C:\\Program Files\\Git\\usr\\bin;" . $PATH
Save and Reload NeoVim.
i solved it adding "C:\Program Files\Git\usr\bin" to the PATH environment variable in Windows 10
I'm trying to execute the following module in Puppet this and got the error:
[root#localhost modules]# puppet apply jenkin_install.pp
Error: Could not parse for environment production: Syntax error at '8080' at /etc/puppetlabs/code/modules/jenkin_install.pp:41:52 on node localhost.localdomain
Here's the code:
exec { 'Change the port from 8080 to 8000':
command => 'sed -i'.original' 's/JENKINS_PORT="8080"/JENKINS_PORT="8000"/' /etc/sysconfig/jenkins',
path => '/usr/local/bin/:/bin/',
logoutput => true,
onlyif => 'grep "8000" /etc/sysconfig/jenkins',
}
I'm wondering how to solve the syntax error in the command?
Thanks
The problem is that you are quoting the command string using single quotes when the command itself contain single quotes. The parser can't tell the difference between the two, so ends up interpreting bits of the command as Puppet code.
The easiest and clearest fix is to use heredoc strings:
exec { 'Change the port from 8080 to 8000':
command => #(END),
sed -i'.original' 's/JENKINS_PORT="8080"/JENKINS_PORT="8000"/' /etc/sysconfig/jenkins
| END
path => '/usr/local/bin/:/bin/',
logoutput => true,
onlyif => 'grep "8000" /etc/sysconfig/jenkins',
}
Although, as another commenter says, this resource should be recoded as a file_line resource.
file_line { 'set_JENKINS_PORT':
ensure => present,
path => '/etc/sysconfig/jenkins',
match => 'JENKINS_PORT=',
line => 'JENKINS_PORT="8000"',
}
I am new to puppet and I have two questions. I want to execute 2 successive custom bash scripts:
file{ 'deploy_0':
ensure => 'file',
path => '/home/user_name/scripts/deploy_0.sh',
...
notify => Exec['deploy_core']
}
file{ 'deploy_1':
ensure => 'file',
path => '/home/user_name/scripts/deploy_1.sh',
...
notify => Exec['deploy_core_api']
}
exec { 'deploy_core':
command => '/bin/bash -c "/home/user_name/scripts/deploy_0"',
}
exec { 'deploy_core_api':
command => '/bin/bash -c "/home/user_name/scripts/deploy_1.sh"',
onlyif => 'deploy_core'
}
But this does not work
I know I can put for the onlyif paramter a bash command such as /bin/bash -c "/home/user_name/scripts/deploy_0.sh, but I prefer to declare a file resource.
You used the notify metaparameters correctly and well to specify the scripts needed to be deployed before execution (file before corresponding exec) and should be executed again if the file content changes. You need similar metaparameters for application order on the exec resources if you want similar functionality there. Note that onlyif is an exec attribute that executes a local command on the client and causes the resource to be considered already in sync (not applied due to idempotence) during catalog application if it returns something falsey.
Since you do not need refreshing here from one exec to the other like you did with the file resource, we can use require or before instead.
# before
exec { 'deploy_core':
command => '/bin/bash -c "/home/user_name/scripts/deploy_0"',
before => File['deploy_core_api'],
}
exec { 'deploy_core_api':
command => '/bin/bash -c "/home/user_name/scripts/deploy_1.sh"',
}
# require
exec { 'deploy_core':
command => '/bin/bash -c "/home/user_name/scripts/deploy_0"',
}
exec { 'deploy_core_api':
command => '/bin/bash -c "/home/user_name/scripts/deploy_1.sh"',
require => File['deploy_core'],
}
This will give you the behavior you are looking for.
I am trying to write a puppet script which will install a module by un-tar. I want puppet to fail if it is already un tar. I tried to do below code but it always fails even if directory is absent.
I am checking if /opt/sk is present then fail otherwise proceed on installation.
define splunk::fail($target)
{
$no = 'true'
case $no {
default : { notice($no) }#fail('sk is already installed.')}
}
}
define splunk::forwarder( $filename , $target )
{
file{"$target/sk":
ensure => present
}
splunk::fail{"NO":
target => '/opt/',
require => File[$target],
}
file{"$target/A.tgz":
source => $filename ,
replace => false ,
}
exec{"NO1":
command => "tar xzvf A.tgz" ,
cwd => $target ,
require => File["$target/A.tgz"] ,
}
exec{"Clean":
command => "rm -rf A.tgz" ,
cwd => target ,
require => Exec["NO1"],
}
}
splunk::forwarder {"non":
filename => 'puppet:///modules/splunk/files/NO.tgz' ,
target => '/opt/',
}
Thanks
Define custom_fact and use it combined with fail resource.
In your ruby directory e.g /usr/lib/ruby/vendor_ruby/facter define file tmp_exist.rb with content:
# tmp_exist.rb
Facter.add('tmp_exist') do
setcode do
File.exist? '/root/tmp'
end
end
Next use it in puppet manifest. E.g I combined it with str2bool function from stdlib:
class test {
if !str2bool($::tmp_exist) {
fail('TMP NOT EXIST')
}
if !str2bool($::foo_exist) {
fail('FOO NOT EXIST')
}
}
include test
In /root create only tmp file.
In result you will have:
Error: FOO NOT EXIST at /etc/puppet/deploy/tests/test.pp:8 on node dbmaster
UPDATED: I updated my answer. Chris Pitman was right, my previous solution works only on puppet master or with puppet apply.
I have also found an article describing how to define custom function file_exists in puppet. That also might be helpful.
You should use "creates" attribute of exec, for example:
exec { 'install':
command => "tar zxf ${package}",
cwd => $some_location,
path => $path,
creates => "${some_location}/my_package",
}
Puppet will only execute 'install' if "${some_location}/my_package" doesn't exist.
I have a sequence of exec in my Puppet manifest:
The first one downloads ZIP file with binary (unless the binary has already been installed) and saves it to /tmp.
The second one unzips it.
When I apply the manifest for the first time, it works correctly. However, when I clean my /tmp and apply the manifest again, it fails because the first exec doesn't executed (that is correct), but the second still tries to execute and fails because ZIP file is not present.
How do I modify the manifest to skip the second exec if the first one doesn't download file?
exec { 'ngrok-download':
command => 'wget https://dl.ngrok.com/linux_386/ngrok.zip -O /tmp/ngrok.zip',
unless => 'which ngrok',
path => ['/bin', '/usr/bin'],
}
exec { 'ngrok-unzip':
command => 'unzip ngrok.zip',
cwd => '/tmp',
path => ['/usr/bin'],
require => Exec['ngrok-download'],
}
Try this:
exec { 'ngrok-download':
command => 'wget https://dl.ngrok.com/linux_386/ngrok.zip -O /tmp/ngrok.zip',
unless => 'which ngrok',
path => ['/bin', '/usr/bin'],
notify => Exec['ngrok-unzip'],
}
exec { 'ngrok-unzip':
command => 'unzip ngrok.zip',
cwd => '/tmp',
path => ['/usr/bin'],
refreshonly => true,
require => Exec['ngrok-download'],
}
This will result in the unzip exec only running when the wget exec actually does something -- which it won't if ngrok is found.
Normally I would wget it to a more permanent location and leave it there. Then instead of the unless => 'which ngrok' check, replace with creates => '/path/to/zip.file'. The result being as long as the file is still there, none of the execs fire.
Comes in handy when you version the zip files and want to change versions.
You could also try easier approach:
exec { 'ngrok-download':
command => 'wget https://dl.ngrok.com/linux_386/ngrok.zip -O /tmp/ngrok.zip',
unless => 'which ngrok',
path => ['/bin', '/usr/bin'],
} ~>
exec { 'ngrok-unzip':
command => 'unzip ngrok.zip',
cwd => '/tmp',
path => ['/usr/bin'],
refreshonly => true,
}
Where Exec['ngrok-download'] notifies Exec['ngrok-unzip'] if applied and Exec['ngrok-unzip'] refresh its state only if needed
Same thing can be achieved by doing following:
exec { 'ngrok-download':
command => 'wget https://dl.ngrok.com/linux_386/ngrok.zip -O /tmp/ngrok.zip',
unless => 'which ngrok',
path => ['/bin', '/usr/bin'],
}
exec { 'ngrok-unzip':
command => 'unzip ngrok.zip',
cwd => '/tmp',
path => ['/usr/bin'],
refreshonly => true,
}
Exec['ngrok-download'] ~> Exec['ngrok-unzip']
Hope this helps.