I'm using this Laravel Vagrant: https://github.com/bryannielsen/Laravel4-Vagrant and I want to add PHPUNIT and some other PEAR packages.
I added this line on manifests/phpbase.pp
include pearpackages
I created this file puppet/modules/pearpackages/manifests/init.pp:
class pearpackages {
exec {"pear upgrade":
command => "/usr/bin/pear upgrade",
require => Package['php-pear'],
returns => [ 0, '', ' ']
}
# set channels to auto discover
exec { "pear auto_discover" :
command => "/usr/bin/pear config-set auto_discover 1",
require => [Package['php-pear']]
}
exec { "pear update-channels" :
command => "/usr/bin/pear update-channels",
require => [Package['php-pear']]
}
exec {"pear install phpunit":
command => "/usr/bin/pear install --alldeps pear.phpunit.de/PHPUnit",
creates => '/usr/bin/phpunit',
require => Exec['pear update-channels']
}
# install phploc
exec {"pear install phploc":
command => "/usr/bin/pear install --alldeps pear.phpunit.de/phploc",
creates => '/usr/bin/phploc',
require => Exec['pear update-channels']
}
# install phpcpd
exec {"pear install phpcpd":
command => "/usr/bin/pear install --alldeps pear.phpunit.de/phpcpd",
creates => '/usr/bin/phpcpd',
require => Exec['pear update-channels']
}
# install phpdcd
exec {"pear install phpdcd":
command => "/usr/bin/pear install --alldeps pear.phpunit.de/phpdcd-beta",
creates => '/usr/bin/phpdcd',
require => Exec['pear update-channels']
}
# install phpcs
exec {"pear install phpcs":
command => "/usr/bin/pear install --alldeps PHP_CodeSniffer",
creates => '/usr/bin/phpcs',
require => Exec['pear update-channels']
}
# install phpdepend
exec {"pear install pdepend":
command => "/usr/bin/pear install --alldeps pear.pdepend.org/PHP_Depend-beta",
creates => '/usr/bin/pdepend',
require => Exec['pear update-channels']
}
# install phpmd
exec {"pear install phpmd":
command => "/usr/bin/pear install --alldeps pear.phpmd.org/PHP_PMD",
creates => '/usr/bin/phpmd',
require => Exec['pear update-channels']
}
# install PHP_CodeBrowser
exec {"pear install PHP_CodeBrowser":
command => "/usr/bin/pear install --alldeps pear.phpqatools.org/PHP_CodeBrowser",
creates => '/usr/bin/phpcb',
require => Exec['pear update-channels']
}
}
After, I make a vagrant provision
It seems that is all well configured, but when I go to localhost:8888 the page is always loading and not show me the content.
I don't know what I'm doing bad, but I need your help please, the system configuration is not my specialty
Have you tried using PuPHPet to generate your Puppet manifests? You can enter PEAR modules under the Languages section.
I´ve found the solution.
There are some incompatibility with Vagrant and VirtualBox in some versions. I don´t know if the issue is for the Guests Aditions.
With vagrant 1.6.2 and VirtualBox 4.3.12 works fine.
Related
I'm trying to build a project on a Linux Ubuntu 22.04, under Windows 11 22H2 Wsl2.
But when i run ./vendor/bin/sail up or ./vendor/bin/sail up -d I'm blocked by a infinity step:
[+] Building 663.1s (7/15)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 32B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/ubuntu:22.04 0.8s
=> [ 1/11] FROM docker.io/library/ubuntu:22.04#sha256:4b1d0c4a2d2aaf63b37111f34eb9fa89fa1bf53dd6 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 99B 0.0s
=> CACHED [ 2/11] WORKDIR /var/www/html 0.0s-
=> CACHED [ 3/11] RUN ln -snf /usr/share/zoneinfo/UTC /etc/localtime && echo UTC > /etc/timezone 0.0si
=> [ 4/11] RUN apt-get update && apt-get install -y gnupg gosu curl ca-certificates zip un 662.2s
=> => # Processing triggers for ca-certificates (20211016) ...
=> => # Updating certificates in /etc/ssl/certs...
=> => # 0 added, 0 removed; done.
=> => # Running hooks in /etc/ca-certificates/update.d...
=> => # done.
=> => # gpg: keybox '/root/.gnupg/pubring.kbx' created
Last night I let the build running on this step all night long.
I tried to re-install the packages (php, wsl, ubuntu 22.04 distro, composer and node and npm under nvm), and re-clone the project, but nothing happen.
Thanks for your time.
I have a bash command that will return either 1 or 0. I want to run said command from puppet:
exec { 'Check if Thinkpad':
command => 'sudo dmidecode | grep -q ThinkPad && echo 1 || echo 0',
path => '/usr/bin/:/bin/bash/',
environment => "HOME=/root"
}
Is there a way I can include a file using puppet only if my command returned 1?
file { '/etc/i3/config':
source => 'puppet:///modules/i3/thinkpad',
owner => 'root',
group => 'root',
mode => '0644',
}
You can use an external fact to use the bash script as is. Inside the module's facts.d directory, you could place the script.
#!/bin/bash
if [ dmidecode | grep -q ThinkPad ]
echo 'is_thinkpad=true'
else
echo 'is_thinkpad=false'
fi
You can also use a custom fact inside the lib/facter directory of your module.
Facter.add(:is_thinkpad) do
confine kernel: linux
setcode do
`dmidecode | grep -q ThinkPad && echo true || echo false`
end
end
In both cases, the fact name of is_thinkpad follows the convention for the nomenclature of boolean facts for types of systems. You can then update the code in your manifest for this boolean.
if $facts['is_thinkpad'] == true {
file { '/etc/i3/config':
source => 'puppet:///modules/i3/thinkpad',
owner => 'root',
group => 'root',
mode => '0644',
}
}
This will provide you with the functionality you desire.
https://docs.puppet.com/facter/3.6/custom_facts.html#adding-custom-facts-to-facter
https://docs.puppet.com/facter/3.6/custom_facts.html#external-facts
You will probably need to turn your bash script into a "custom fact" -- which is something I've only done once and don't fully understand enough to teach you how.
I want to say that the easiest way to set up a custom fact is to put your script into /etc/facter/facts.d/ on the agent machine, and make sure it ends with a line that says
echo "thinkpadcheck=1"
or
echo "thinkpadcheck=0"
You can test it with (note: you must be root)
sudo facter -p | grep think
and it should return
thinkpadcheck => 1
But once you have done that, then your puppet script can say
if $thinkpadcheck == 1
{
file { '/etc/i3/config':
source => 'puppet:///modules/i3/thinkpad',
owner => 'root',
group => 'root',
mode => '0644',
}
}
else
{
notify { "thinkpadcheck failed for $hostname" : }
}
I'd like to share another method I found in the Puppet Cookbook 3rd edition (page 118):
message.rb
#!/usr/bin/env ruby
puts "This runs on the master if you are centralized"
Make your script executable with:
sudo chmod +x /usr/local/bin/message.rb
message.pp
$message = generate('/usr/local/bin/message.rb')
notify { $message: }
Then run:
puppet apply message.pp
This example uses a ruby script but any type of script including a basic shell script, as was needed in my case, can be used to set a variable in puppet.
I'm trying to execute a script after deploy with Vagrant + Puppet:
include nginx
$nginx_conf_path = "${files_path}/${fqdn}/etc/nginx/sites-available"
nginx::site { 'test.example.com.conf' :
source => "${nginx_conf_path}/test.example.com.conf",
}
exec { 'install-letsencrypt.sh test.example.com':
require => [Nginx::Site['test.example.com.conf'], Class['profile::ssl']],
command => 'install-letsencrypt.sh test.example.com',
path => '/home/vagrant/bin/'
}
with ssl.pp:
class profile::ssl {
file { "/home/vagrant/bin" :
ensure => "directory",
owner => "vagrant",
group => "vagrant",
}
file { "/home/vagrant/bin/install-letsencrypt.sh":
ensure => "present",
owner => "vagrant",
group => "vagrant",
mode => 700,
source => "puppet:///modules/example/shared/install-letsencrypt.sh"
}
}
And install-letsencrypt.sh:
if [ ! -d "/opt/letsencrypt" ]; then
sudo git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt
fi
# ...etc
The profile::ssl works because /home/vagrant/bin/install-letsencrypt.sh is available, but when I try to exec it in puppet, I get:
==> test.example.com: Error: Deploying Let's encrypt for test.mojjo.fr
==> test.example.com: /home/vagrant/bin/install-letsencrypt.sh: line 11: sudo: command not found
==> test.example.com: /home/vagrant/bin/install-letsencrypt.sh: line 14: mkdir: command not found
==> test.example.com: /home/vagrant/bin/install-letsencrypt.sh: line 17: sudo: command not found
==> test.example.com: /home/vagrant/bin/install-letsencrypt.sh: line 23: sudo: command not found
==> test.example.com: /home/vagrant/bin/install-letsencrypt.sh: line 25: sudo: command not found
What am I doing wrong? I tried with absolute executable paths (/usr/bin/sudo instead of sudo) but it doesn't work either. If I ssh test.example.com and run it there, it also works, so the problème is not in the script.
Thanks in advance
I had this same issue to run some script so I did
exec { 'run-script':
command => "bash -c 'install-letsencrypt.sh test.example.com'",
....
}
I want to call an Exec only when another Exec from a different class is executed successfully.
class mysql {
exec { 'load-sql':
command => 'mysql -uadmi -pxxx general < /vagrant/sites/ddbb/general.sql',
path => ['/bin', '/usr/bin'],
timeout => 0,
onlyif => "test -f /vagrant/sites/ddbb/general.sql",
}
exec { 'delete-general-sql':
command => 'sudo rm /vagrant/sites/ddbb/general.sql',
path => ['/bin', '/usr/bin'],
onlyif => "test -f /vagrant/sites/ddbb/general.sql",
require => Exec['load-sql'],
}
}
class sphinx {
exec { 'sphinx-create-all-index':
command => 'sudo indexer -c /etc/sphinxsearch/sphinx.conf --all --rotate',
require => Exec['load-sql'],
path => '/usr/bin/';
}
}
The command 'delete-general-sql' is executed only if 'load-sql' is executed successfully but 'sphinx-create-all-index'ignores the result of 'load-sql'...
Thanks in advance!
You mess up with require and onlyif.
Read about puppet ordering.
require
Causes a resource to be applied after the target resource.
so
require => Exec['load-sql'],
means, execute resource after execution of exec{'load-sql':} resource.
On the other hand onlyif in exec means:
If this parameter is set, then this exec will only run if the command has an exit code of 0.
So you must add onlyif with proper test (probably onlyif => "test -f /vagrant/sites/ddbb/general.sql) to 'sphinx-create-all-index'.
To make the dependent exec run only once the previous one did run, you can use subscribe and refreshonly.
exec { 'sphinx-create-all-index':
command => 'sudo indexer -c /etc/sphinxsearch/sphinx.conf --all --rotate',
subscribe => Exec['load-sql'],
refreshonly => true,
path => '/usr/bin/';
}
This has some caveats - you may have a hard time to get Puppet to execute this task again if something goes wrong the first time around.
How to exec a command if directory does not exists in puppet file?
exec { "my_exec_task":
command => "tar zxf /home/user/tmp/test.tar.gz",
unless => "test -d /home/user/tmp/new_directory",
path => "/usr/local/bin/:/bin/",
}
I get error: "Could not evaluate: Could not find command 'test'". Also is this the best practice to check if directory does not exists?
test work for me at /usr/bin, so adding it to path could solve error.
unless => 'bash -c "test -d /home/user/tmp/new_directory"',
Should work too. But I think the correct way is to use creates:
exec { "my_exec_task":
command => "tar zxf /home/user/tmp/test.tar.gz",
creates => "/home/user/tmp/new_directory",
path => "/usr/local/bin/:/bin/",
}
Actual problem is in path:
path => [ '/usr/local/bin', '/sbin', '/bin', '/usr/sbin', '/usr/bin' ]