I am trying to install the pear package "HTTP_Request2" using puppet. The target OS is RHEL 7.
I have come across 2 puppet modules that I believe should be able to do this
https://forge.puppetlabs.com/rafaelfc/pear
https://forge.puppetlabs.com/example42/php
Ideally I would like to use the refaelfc module as it seems more specialized for this task. The problem I have with this is that to gain internet access on the target server you need to go through a proxy, I can't seem to find anything in this module to set this. Without this set puppet just times out when trying to install the module.
Using option 2 I add the following to my manifest:
include php
php::pear::config { http_proxy: value => "http://xx.xx.xx.xx:xxxx" }
php::pear::module { 'HTTP_Request2':
repository => 'pear.phpunit.de',
alldeps => 'true',
require => Php::Pear::Config['http_proxy'],
}
When doing this I get the error:
Error: Execution of '/bin/yum -d 0 -e 0 -y list php-pear-HTTP_Request2' returned 1: Error: No matching Packages to list
It doesn't seem right to be that it should be calling on yum? How can I get puppet to install this pear package?
Managed to get it working using a combination of the example42/php module and a custom script:
include php
php::pear::config { http_proxy:
value => "http://xx.xx.xx.xx:xxxx",
}
exec { 'HTTP_Request2':
command => '/usr/bin/pear install HTTP_Request2',
unless => '/usr/bin/pear info HTTP_Request2',
require => Php::Pear::Config['http_proxy'],
}
Related
I've created a puppet script to install Azure client and in the last step before using yum install, I want to make sure that the package haven't installed before for prevent from duplicate install.
My concept is
Execute the script if the output from az --help give nothing (which mean there's no Azure install)
or if you guys have any better choices please guide me, thanks!
And my code is
#install azure client
exec { 'install-azure':
command => '/bin/yum install azure-cli -y',
path => '/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:',
unless => 'az --help',
#require => Exec['yumrepolist']
}
It seems like there're something wrong with the code, I've checked a particular agent by using
puppet agent -t
Notice:
/Stage[main]/Os_preparation::Azure_install/Exec[yumrepolist]/returns:
executed successfully Error:
/Stage[main]/Os_preparation::Azure_install/Exec[install-azure]: Could
not evaluate: Could not find command 'az'
Any ideas? Thanks
You should install azure-cli using a package resource. Also, you should add its Yum repository as a yumrepo resource.
Try something like the following, which replicates the instructions on https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-yum?view=azure-cli-latest.
yumrepo { 'azure-cli':
descr => 'Azure CLI',
baseurl => 'https://packages.microsoft.com/yumrepos/azure-cli',
enabled => 1,
gpgcheck => 1,
gpgkey => 'https://packages.microsoft.com/keys/microsoft.asc',
}
package { 'azure-cli':
ensure => installed,
require => Yumrepo['azure-cli'],
}
I'm installing the latest sensu-plugins-mysql with the following puppet code successfully:
ensure_packages('sensu-plugins-mysql', { provider => sensu_gem, ensure => latest})
But I want to use my fork nagyt234/sensu-plugins-mysql, created from sensu-plugins/sensu-plugins-mysql, how to do it? The source option doesn't work:
ensure_packages('sensu-plugins-mysql', { provider => sensu_gem, source => 'https://github.com/nagyt234/sensu-plugins-mysql.git', ensure => latest})
The problem is, that sensu_gem is not able to install a gem directly from a github repository, so the sensu-plugins-mysql was always installed from rubygem.org. I had to generate my own gem with a different name and publish it to rubygem.org.
I have an existing puppet manifest which installs a bunch of php5 packages and only after being installed restarts apache. The simplified manifest is something like
package { 'apache-php':
name => $modules,
ensure => installed
}
exec {'enable-mod-php':
command => $enable_cmd,
refreshonly => true
}
Package['apache-php'] ~> Exec['enable-mod-php'] ~> Service['apache']
After a system upgrade catalog runs have started failing with the following error message:
Error: Failed to apply catalog: Parameter name failed on Package[apache-php]: Name must be a String not Array at /etc/puppet/modules/apache/manifests/php.pp:22
I found out that I was using an undocumented feature/bug: Puppet 3.4.0 name as an array in package.
However, I'm having a hard time finding out how to redo my setup after the upgrade. How can I rewrite this manifest so that it works with more recent puppet versions?
Instead of using an arbitrary title for the package define in your example. (eg. apache-php) and using a name parameter, you can do the following:
$modules = ['foo','bar','baz']
package { $modules:
ensure => present
notify => Exec['enable-mod-php']
}
exec {'enable-mod-php':
command => $enable_cmd,
refreshonly => true,
notify => Service['apache']
}
service { 'apache':
# your apache params
}
I haven't looked at the code for the package provider, but can verify that the above works. You should also note that chaining arrows are all well and good, but according to the Puppet style guide, metaparameters are preferred.
Hope this helps.
I'm trying to set up a VM to use python-nvd3 and using puppet to provision the machine. I've got node.js/npm to go in ok but then I get an error trying to install packages using bower:
package { 'bower':
provider => npm
}
exec { 'install d3':
command => '/usr/local/bin/bower install d3#3.3.8',
require => Package["bower"]
}
exec { 'install nvd3':
command => '/usr/local/bin/bower install nvd3#1.1.12-beta',
require => Package["bower"]
}
err: /Stage[main]/Infinite_interns::Box::Tm351d001r/Exec[install d3]/returns: change from notrun to 0 failed: /usr/local/bin/bower install d3#3.3.8 returned 1 instead of one of [0] at /vagrant/modules/infinite_interns/manifests/box/tm351d001r.pp:39
If I ssh in to the VM, and try to run a bower command I get a y/n prompt to ask if I want to allow error logging. In this case I don't want to and I don't want my provisioner to fall over because it can't answer the question (if this is the problem that's causing the above puppet error).
You have to set the CI environment variable to true or use the config.interactive=false bower flag to avoid interactive operations. Example:
exec { 'install d3':
command => '/usr/local/bin/bower install d3#3.3.8 --config.interactive=false',
require => Package["bower"]
}
Reference:
https://github.com/bower/bower#running-on-a-continuous-integration-server
I'm trying to getting support for augeas on my Vagrant machine.
I tried to install some package with these directives:
package { "augeas-tools": ensure => installed }
package { "libaugeas-dev": ensure => installed }
package { "libaugeas-ruby": ensure => installed }
When i try to use augeas on my manifests, after the vm boot i receive this error:
err: Could not find a suitable provider for augeas
I'm using the precise32 official box with Vagrant 1.0.3.
Vagrant 1.0.3 has ruby 1.8.7 and puppet 2.7.14
$ ruby -v
$ ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-linux]
$ puppet help
$ Puppet v2.7.14
This is my little manifest with php class, included after apache class, mysql and other classes tested separately.
All things works correctly excepting for the augeas command.
class php {
exec { "apt-update":
command => "/usr/bin/apt-get update",
refreshonly => true;
}
package { "augeas-tools": ensure => installed }
package { "libaugeas-dev": ensure => installed }
package { "libaugeas-ruby": ensure => installed }
package { "php5": ensure => installed }
package { "php5-cli": ensure => installed }
package { "php5-xdebug": ensure => installed }
package { "php5-curl": ensure => installed }
package { "php5-intl": ensure => installed }
package { "php5-imap": ensure => installed }
package { "php5-mcrypt": ensure => installed }
package { "php5-imagick": ensure => installed }
package { "php5-sqlite": ensure => installed }
package { "php5-gd": ensure => installed }
package { "php-apc": ensure => installed }
package {
"libapache2-mod-php5" :
ensure => installed,
require => Package["php5"]
}
augeas { "php-cli":
require => [
Package["php5"],
Package["augeas-tools"],
Package["libaugeas-dev"],
Package["libaugeas-ruby"],
],
context => "/etc/php5/cli/php.ini",
changes => [
"set date.timezone Europe/Rome",
"set short_open_tag Off",
];
}
augeas { "php-apache":
require => [
Package["php5"],
Package["augeas-tools"],
Package["libaugeas-dev"],
Package["libaugeas-ruby"],
],
context => "/etc/php5/apache2/php.ini",
changes => [
"set date.timezone Europe/Rome",
"set short_open_tag Off",
];
}
}
After installation of packages, logging in the vagrant machine with "vagrant ssh", i launch:
vagrant#precise32:~$ ruby -raugeas -e "puts Augeas.open"
#<Augeas:0xb77a3598>
Thanks in advance!
I added the following to my Vagrantfile and it augeas started working.
Before declaring puppet provisioner add the following line, if on ubuntu:
config.vm.provision :shell, :inline => "sudo apt-get update && sudo apt-get install puppet -y"
This will update your apt packages and then update puppet client whose latest version already has a fix.
It turns out that this wasn't fixed in bug #6907 that I referenced in my other answer. That fix only worked for Puppet providers that depended on commands that were then supplied during the run.
For the Augeas provider, it uses an internal Puppet called "features" to check if the ruby-augeas library is available or not. Features are only being checked once and the results cached, so even after installing the library, this meant the feature still evaluated to false.
I filed this upstream as bug #14822 and have sent a pull request with a fix. Testing with the patch, I now get this successful run:
notice: /Stage[main]//Package[ruby-augeas]/ensure: created
notice: /Stage[main]//Augeas[test]/returns: executed successfully
I'm not familiar with Vagrant, but I think you'll need to find a workaround to install the libaugeas-ruby package before the Puppet run in the meantime.
On Puppet 2.7.14, this should work as the dependencies for providers will only be evaluated when they're needed - i.e. when Puppet needs to run those Augeas resources.
Without the full Puppet log file to confirm, I suspect that it's because you're missing explicit dependencies between the Augeas package(s) and the Augeas resources that need them. Remember, listing the resources in the manifest in that order doesn't mean Puppet executes it that way.
You could either add requires parameters to every Augeas resource:
augeas { "php-cli":
require => [ Package["php5"], Package["libaugeas-ruby"] ],
# ...
}
Or use the chaining syntax to automatically make every Augeas resource depend on a package. Add this on a line inside the class, but not inside any resource:
Package["libaugeas-ruby"] -> Augeas <| |>
After reading answer from #m0dlx I inspect /home/vagrant/postinstall.sh file and found that Vagrant uses own copy of Ruby:
# The base path to the Ruby used for the Chef and Puppet gems ruby_home="/opt/vagrant_ruby"
After that I find file augeas.rb at /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.19/lib/puppet/provider/augeas/augeas.rb and edit it, by changing line
confine :true => Puppet.features.augeas?
to
confine :true => :augeas
(Shortly speaking I partially apply patch from #m0dlx.)
After that this error is gone.