How can I install PHP APC via Pecl with Puppet - vagrant

I am attempting to install PHP APC on Puppet but I do not know how to go about this? Pear is already installed and when I try and execute the command to install PHP APC I presented with an error message.
pecl.pp:
class php::pecl {
include php
exec { "pecl install php-apc":
require => Package["php-pear"]
}
}
pear.pp:
class php::pear {
include php
# upgrade PEAR
exec { "pear upgrade":
require => Package["php-pear"]
}
# install PHPUnit
exec { "pear config-set auto_discover 1":
require => Exec["pear upgrade"]
}
# create pear temp directory for channel-add
file { "/tmp/pear/temp":
require => Exec["pear config-set auto_discover 1"],
ensure => "directory",
owner => "root",
group => "root",
mode => 777
}
# discover channels
exec { "pear channel-discover pear.phpunit.de; true":
require => [File["/tmp/pear/temp"], Exec["pear config-set auto_discover 1"]]
}
exec { "pear channel-discover pear.symfony-project.com; true":
require => [File["/tmp/pear/temp"], Exec["pear config-set auto_discover 1"]]
}
exec { "pear channel-discover components.ez.no; true":
require => [File["/tmp/pear/temp"], Exec["pear config-set auto_discover 1"]]
}
# clear cache before install phpunit
exec { "pear clear-cache":
require => [Exec["pear channel-discover pear.phpunit.de; true"], Exec["pear channel-discover pear.symfony-project.com; true"], Exec["pear channel-discover components.ez.no; true"]]
}
# install phpunit
exec { "pear install -a -f phpunit/PHPUnit":
require => Exec["pear clear-cache"]
}
# install apc
exec { "pear install -a -f pear/php-apc":
require => Exec["pear clear-cache"]
}
}
php init.pp class:
class php {
# package install list
$packages = [
"php5",
"php5-cli",
"php5-mysql",
"php-pear",
"php5-dev",
"php5-gd",
"php5-mcrypt",
"libapache2-mod-php5",
]
package { $packages:
ensure => present,
require => Exec["apt-get update"]
}
}
Error message:
err: /Stage[main]/Php::Pear/Exec[pear install -a -f pear/php-apc]/returns: change from notrun to 0 failed: pear install -a -f pear/php-apc returned 1 instead of one of [0] at /tmp/vagrant-puppet-1/modules-0/php/manifests/pear.pp:52
err: /Stage[main]/Php::Pecl/Exec[pecl install php-apc]/returns: change from notrun to 0 failed: pecl install php-apc returned 1 instead of one of [0] at /tmp/vagrant-puppet-1/modules-0/php/manifests/pecl.pp:5

I would suggest that you use a tried and trusted puppet module which can install PHP and pecl extensions for you.
Have a look at the following puppet module which will most likely help.
https://forge.puppetlabs.com/example42/php

Turns out the package is actually called apc and not php-apc - doh!
Working code:
exec { "pecl install apc":
require => Exec["pear clear-cache"]
}

Related

Post deployment bash script in Bicep file does not execute

I want to deploy an Ubuntu VM on Azure and automatically execute a few lines of Bash code right after the VM is deployed. The Bash code is supposed to install PowerShell on the VM. To do this, I use this Bicep file. Below you can see an extract of that Bicep file where I specify what Bash code I want to be executed post deployment.
resource deploymentscript 'Microsoft.Compute/virtualMachines/runCommands#2022-08-01' = {
parent: virtualMachine
name: 'postDeploymentPSInstall'
location: location
properties: {
source: {
script: '''sudo apt-get update &&\
sudo apt-get install -y wget apt-transport-https software-properties-common &&\
wget -q "https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb" &&\
sudo dpkg -i packages-microsoft-prod.deb &&\
sudo apt-get update &&\
sudo apt-get install -y powershell &&\
pwsh'''
}
}
}
I searched for solutions on the web but only found conflicting explanations. I made the code above with the help of this tutorial. The only difference I see is that I'm using Bash and not PowerShell like the blog post author. Thanks for your help.
To deploy an Ubuntu VM on Azure and automatically execute a few lines of Bash code right after the VM is deployed:
I tried to create a Linux VM and used run command to install PowerShell inside the VM while deployment and was able to achieve the desired results by running below bicep file.
#description('Name of the Network Security Group')
param networkSecurityGroupName string = 'SecGroupNet'
var publicIPAddressName = '${vmName}PublicIP'
var networkInterfaceName = '${vmName}NetInt'
var osDiskType = 'Standard_LRS'
var subnetAddressPrefix = '10.1.0.0/24'
var addressPrefix = '10.1.0.0/16'
var linuxConfiguration = {
disablePasswordAuthentication: true
ssh: {
publicKeys: [
{
path: '/home/${adminUsername}/.ssh/authorized_keys'
keyData: adminPassword
}
]
}
}
resource nic 'Microsoft.Network/networkInterfaces#2021-05-01' = {
name: networkInterfaceName
location: location
properties: {
ipConfigurations: [
{
name: 'ipconfig1'
properties: {
subnet: {
id: subnet.id
}
privateIPAllocationMethod: 'Dynamic'
publicIPAddress: {
id: publicIP.id
}
}
}
]
networkSecurityGroup: {
id: nsg.id
}
}
}
resource nsg 'Microsoft.Network/networkSecurityGroups#2021-05-01' = {
name: networkSecurityGroupName
location: location
properties: {
securityRules: [
{
name: 'SSH'
properties: {
priority: 1000
protocol: 'Tcp'
access: 'Allow'
direction: 'Inbound'
sourceAddressPrefix: '*'
sourcePortRange: '*'
destinationAddressPrefix: '*'
destinationPortRange: '22'
}
}
]
}
}
resource vnet 'Microsoft.Network/virtualNetworks#2021-05-01' = {
name: virtualNetworkName
location: location
properties: {
addressSpace: {
addressPrefixes: [
addressPrefix
]
}
}
}
resource subnet 'Microsoft.Network/virtualNetworks/subnets#2021-05-01' = {
parent: vnet
name: subnetName
properties: {
addressPrefix: subnetAddressPrefix
privateEndpointNetworkPolicies: 'Enabled'
privateLinkServiceNetworkPolicies: 'Enabled'
}
}
resource publicIP 'Microsoft.Network/publicIPAddresses#2021-05-01' = {
name: publicIPAddressName
location: location
sku: {
name: 'Basic'
}
properties: {
publicIPAllocationMethod: 'Dynamic'
publicIPAddressVersion: 'IPv4'
dnsSettings: {
domainNameLabel: dnsLabelPrefix
}
idleTimeoutInMinutes: 4
}
}
resource vm 'Microsoft.Compute/virtualMachines#2021-11-01' = {
name: vmName
location: location
properties: {
hardwareProfile: {
vmSize: vmSize
}
storageProfile: {
osDisk: {
createOption: 'FromImage'
managedDisk: {
storageAccountType: osDiskType
}
}
imageReference: {
publisher: 'Canonical'
offer: 'UbuntuServer'
sku: ubuntuOSVersion
version: 'latest'
}
}
networkProfile: {
networkInterfaces: [
{
id: nic.id
}
]
}
osProfile: {
computerName: vmName
adminUsername: adminUsername
adminPassword: adminPassword
linuxConfiguration: ((authenticationType == 'password') ? null : linuxConfiguration)
}
}
}
resource deploymentscript 'Microsoft.Compute/virtualMachines/runCommands#2022-03-01' = {
parent: vm
name: 'linuxscript'
location: location
properties: {
source: {
script: '''# Update the list of packages
sudo apt-get update;
#Install pre-requisite packages.
sudo apt-get install -y wget apt-transport-https software-properties-common;
#Download the Microsoft repository GPG keys
wget -q "https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb";
#Register the Microsoft repository GPG keys
sudo dpkg -i packages-microsoft-prod.deb;
#Update the list of packages after we added packages.microsoft.com
sudo apt-get update;
#Install PowerShell
sudo apt-get install -y powershell;
#Start PowerShell
pwsh'''
}
}
}
output adminUsername string = adminUsername
output hostname string = publicIP.properties.dnsSettings.fqdn
output sshCommand string = 'ssh $ {adminUsername}#${publicIP.properties.dnsSettings.fqdn}'
Deployed Successfully:
From Azure Portal:
After the deployment, When I ssh’d into my VM and ran Pwsh to check if PowerShell was installed
Installed successfully:
Refer MSDoc, run command template-MSDoc
Your problem is misunderstanding what the && does.
The shell will attempt to run semi-simultaneously all parts, some possibly clobbering others or not having necessary preconditions in place before starting!
Replace all instances of "&&\" with ";\" and your script should work, meaning the commands will run sequentially, waiting for the previous line to complete before attempting the subsequent lines.

vagrant puppet, composer unable to install laravel

I just recently knew about puppet and I'm trying to install laravel while vagrant is provisioning so that everything is already set (can be able to run laravel) when I logged in/ssh to vagrant. But I got stuck, it returned successfully executed but after I do vagrant ssh, laravel command is not available.
php5, php5-cli, etc. composer and other dependencies is already installed before this part of code.
class laravel {
Exec {
path => "/bin:/sbin:/usr/bin:/usr/sbin",
}
exec { "install-laravel" :
command => "/usr/local/bin/composer global require 'laravel/installer'",
require => [Package["php5-cli", "php5-dev"], Exec["install-composer", "set-composer-as-global"]],
cwd => "/home/vagrant/",
environment => ["COMPOSER_HOME=/home/vagrant"],
user => root,
group => root,
}
exec { "add-laravel-command" :
command => "mkdir /usr/local/bin/laravel",
environment => ["LARAVEL_HOME=/home/vagrant"],
onlyif => "test -d /usr/local/bin/composer",
require => Exec["install-laravel"],
user => root,
}
exec { "set-laravel-as-globall" :
command => "mv /home/vagrant/.composer/vendor/bin /usr/local/bin/laravel",
onlyif => "test -d /.composer/vendor/bin",
require => Exec["add-laravel-command"],
user => root,
}
}
Output
==> default: Notice: /Stage[main]/Laravel/Exec[install-laravel]/returns: executed successfully
==> default: Debug: /Stage[main]/Laravel/Exec[install-laravel]: The container Class[Laravel] will propagate my refresh event
==> default: Debug: Exec[add-laravel-command](provider=posix): Executing check 'test -d /usr/local/bin/composer'
==> default: Debug: Executing 'test -d /usr/local/bin/composer'
==> default: Debug: Exec[set-laravel-as-globall](provider=posix): Executing check 'test -d /.composer/vendor/bin'
==> default: Debug: Executing 'test -d /.composer/vendor/bin'
==> default: Debug: Class[Laravel]: The container Stage[main] will propagate my refresh event
Any help would be much appreciated. Thanks
create a file under puppet/modules/laravel/files and name it composer.json with the following content
{
"require": {
"laravel/installer": "^1.3"
}
}
Laravel init.pp file
class laravel {
Exec {
path => "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin",
user => root,
group => root,
}
file { "/usr/local/bin/laravel-devtools" :
ensure => directory,
owner => root,
group => root,
}
file { "/usr/local/bin/laravel-devtools/composer.json" :
source => "puppet:///modules/laravel/composer.json",
require => File["/usr/local/bin/laravel-devtools"],
owner => root,
group => root,
}
exec { "install-laravel" :
command => "sudo composer require 'laravel/installer'",
onlyif => "test -f /usr/local/bin/composer",
require => [
Package["nginx","php5-cli", "php5-dev", "php5-mysql"],
File["/usr/local/bin/laravel-devtools", "/usr/local/bin/laravel-devtools"],
],
environment => ["COMPOSER_HOME=/home/vagrant"],
cwd => "/usr/local/bin/laravel-devtools",
user => root,
group => root,
}
exec { "set-laravel-as-global" :
command => "sudo ln -s /usr/local/bin/laravel-devtools/vendor/laravel/installer/laravel /usr/local/bin/laravel",
require => [
File["/usr/local/bin/laravel-devtools", "/usr/local/bin/laravel-devtools/composer.json"],
Exec["install-laravel"],
],
}
}
Make sure composer is installed first during provision.

Message appears when running scsslint

I am following the step by step on https://www.npmjs.com/package/grunt-scss-lint
I have installed everything, and seems to be working fine when I type in Terminal 'scss-lint'.
However I want this to be running in Grunt
Gruntfile:
scsslint: {
allFiles: [
'src/scss/**/*.scss',
],
options: {
bundleExec: true,
config: '.scss-lint.yml',
reporterOutput: 'scss-lint-report.xml',
colorizeOutput: true
}
},
grunt.registerTask('default', ['js', 'html', 'scsslint',]);
so I type in grunt in terminal which will run the tasks and in terminal - this pops up:
Running "scsslint:allFiles" (scsslint) task
Running scss-lint on allFiles
Please make sure you have ruby installed: ruby -v
Install the scss-lint gem by running:
gem update --system && gem install scss-lint
Running through grunt does not work but typing scss-lint in terminal works.
I did the following message but this message does not disappear
Your problem is related to the bundleExec parameter. If you set it to true, the plugin will expect the gem to be installed via bundler.
Set it to false, and it will work.
scsslint: {
allFiles: [
'src/scss/**/*.scss',
],
options: {
bundleExec: false,
config: '.scss-lint.yml',
reporterOutput: 'scss-lint-report.xml',
colorizeOutput: true
}
},
grunt.registerTask('default', ['js', 'html', 'scsslint',]);

Vagrant/Puppet - Provision Failing (MySQL Not Working)

I have tried different virtual boxes, I have changed tons of configurations (probably recreated, reloaded and reprovisioned 50-100 times) -- it has to do with the MySQL module from Puppet -- which is apparently working for tens of thousands of others, so something I am doing is wrong.
VagrantFile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "puppetlabs/ubuntu-14.04-64-puppet"
# Was necessary
#vagrant plugin install vagrant-vbguest
# Networking
config.vm.network "forwarded_port", guest: 80, host: 8000
# config.vm.network "private_network", ip: "192.168.33.10"
# Synced folders
config.vm.synced_folder ".", "/var/www"
# Update
config.vm.provision "shell", inline: "apt-get -y update"
# Provisioning
config.vm.provision :shell do |shell|
shell.inline = "mkdir -p /etc/puppet/modules;
(puppet module install example42-puppi; true)
(puppet module install example42-apache; true)
(puppet module install example42-php; true)
(puppet module install puppetlabs-stdlib; true)
(puppet module install puppetlabs-mysql; true)
(puppet module install saz-vim; true)
(puppet module install saz-timezone; true)
(puppet module install puppetlabs-git; true)
(puppet module install tPl0ch-composer; true)
"
end
config.vm.provision "puppet" do |puppet|
puppet.facter = {
"fqdn" => "development.mydomain.com",
"aliases" => "*.development.mydomain.com",
"hostname" => "www",
"docroot" => '/var/www/html/',
}
puppet.hiera_config_path = "manifests/hiera.yaml"
puppet.working_directory = "/etc/puppet"
end
end
Puppet File: default.pp
###########################
# MySite Puppet Config #
###########################
# OS : Ubuntu 14 #
# Database : MySQL 5 #
# Web Server : Apache 2 #
# PHP version : 5.4 #
###########################
# Vim
class { 'vim': }
# Set Timezone
class { 'timezone':
timezone => 'America/Chicago',
}
# Puppi
class { 'puppi': }
# Apache setup
class { "apache":
puppi => true,
puppi_helper => "myhelper",
}
apache::vhost { $fqdn :
docroot => $docroot,
server_name => $fqdn,
serveraliases => $aliases,
priority => '',
template => 'apache/virtualhost/vhost.conf.erb',
}
apache::module { 'rewrite': }
apache::module { 'headers': }
# PHP Extensions
class {"php":}
php::module { ['xdebug', 'mysql', 'curl', 'gd', 'mcrypt']:
notify => Service['apache2']
}
# MySQL Server
class { '::mysql::server':
package_ensure => present,
root_password => '[root_password]',
override_options => { 'mysqld' => { 'default_time_zone' => 'America/Chicago' } },
}
class { 'mysql::client':}
mysql::db { '[db_name]':
user => '[user]',
password => '[password]',
host => 'localhost',
grant => ['ALL'],
charset => 'utf8',
}
exec { "database_import":
timeout => 300,
command => "/bin/gzip -dc /vagrant/manifests/provision.sql.gz | /usr/bin/mysql -u root -p[root_password]";
}
mysql::db { '[db_test]':
user => '[user_test]',
password => '[password_test]',
host => 'localhost',
grant => ['ALL'],
charset => 'utf8',
sql => "/var/www/test/db-schema.sql",
}
# Install Composer components
include composer
composer::exec { 'install':
cmd => 'install', # REQUIRED
cwd => '/var/www', # REQUIRED
dev => true, # Install dev dependencies
}
# Git
include git
# MySite Setup
file { $docroot:
ensure => 'directory',
}
$writeable_dirs = ["${docroot}cache/", "${docroot}cache/css/", "${docroot}cache/css/js/"]
file { $writeable_dirs:
ensure => "directory",
mode => '0777',
require => File[$docroot],
}
file { '/var/www/cl/':
ensure => directory
}
file { 'errors_log':
path => "/var/www/cl/errors.log",
ensure => present,
mode => 0777,
}
# Cron Jobs
cron { thirty_minutes:
command => "/usr/bin/php ${docroot}cl-load.php crons/thirty_minutes/",
user => root,
minute => '*/30'
}
cron { hourly:
command => "/usr/bin/php ${docroot}cl-load.php crons/hourly/",
user => root,
hour => '*',
minute => 0,
}
cron { four_hours:
command => "/usr/bin/php ${docroot}cl-load.php crons/four_hours/",
user => root,
hour => '*/4',
minute => 0,
}
cron { daily:
command => "/usr/bin/php ${docroot}cl-load.php crons/daily/",
user => root,
monthday => '*',
hour => '0',
minute => 0,
}
Here is the error message I am receiving (the first):
==> ==> default: Error: Could not start Service[mysqld]: Execution of '/sbin/start mysql' returned 1:
It seems that Puppet is trying to import the database before installing the MySQL server package.
Keep in mind that Puppet don't care about which resources you write first, if you need to manage something in a specific order you have to declare relationships explicitly. So in your case the following statement:
exec { "database_import":
timeout => 300,
command => "/bin/gzip -dc /vagrant/manifests/provision.sql.gz | /usr/bin/mysql -u root -p[root_password]",
require => Class['::mysql::server']
}
Could set the correct order for that resource. Possibly you'll need to declare additional relationships in a similar manner.

Vagrant using Ruby 1.9.3 as default

Hey all i am trying to build a vagrant vm. i am using chef-solo for provisioning and chef-rbenv to manage my versions. so in the vagrantfile i specify
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "cookbooks"
chef.add_recipe "ruby_build"
chef.add_recipe "rbenv::system"
chef.add_recipe "rbenv::vagrant"
...
chef.json = {
"rbenv" => {
"rubies" => [ "1.9.3-p327" ],
"global" => "1.9.3-p327",
"gems" => {
"1.9.3-p327" => [
{ "name" => "bundler" }
]
}
}
}
end
so that the default ruby version will be 1.9.3-p327, but it crashes
Error executing action `install` on resource 'rbenv_ruby[1.9.3-p327] (system)'
and if i dont specify the version in the vagrant file(as seen above), and go with the default rbenv that chef builds so that i can install it once i am in the vm. then i get this
vagrant#precise64:/vagrant$ rbenv install 1.9.3-p327
Downloading yaml-0.1.4.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/36c852831d02cf90508c29852361d01b
Installing yaml-0.1.4...
BUILD FAILED
...
it works when i run sudo rbenv install 1.9.3-p327 but then when running anything i have to prefix it with sudo even ruby -v
vagrant#precise64:~$ ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [x86_64-linux]
vagrant#precise64:~$ sudo ruby -v
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.3.0]
how can i get it installed with chef-solo. i have tried all week and cant get it working at all.
The json requires you to specify for chef the rbenv location that your installing ruby to. since the recipes call that you install rbenv on a system level and then a user lvl in this case vagrant.
chef.add_recipe "rbenv::system"
chef.add_recipe "rbenv::vagrant"
So i went and changed the json to this:
chef.json = {
'rbenv' => {
'user_installs' => [
{
'user' => 'vagrant',
'rubies' => ['1.9.3-p327'],
'global' => '1.9.3-p327',
'gems' => {
'1.9.3-p327' => [
{ 'name' => 'bundler' },
{ 'name' => 'rake' }
]
}
}
]
}
}
Also the current rbenv cookbook often has bugs so its good to reference the latest taged version of the cookbook in the cheffile.
cookbook 'rbenv', git: 'git://github.com/fnichol/chef-rbenv.git', ref: "v0.7.2"
like so.

Resources