I am trying to rewrite a file using puppet with the following function.
If the file exists I still want the file to be rewrite from the source. Will this be achieved with the following method?
define setup_sysctl_conf( $dependence=File[$dummy_dependence_file] )
{
file { $name:
path => '/etc/sysctl.conf',
ensure => present,
mode => 0777,
source => '/vagrant/files/sysctl.conf',
require => $dependence,
}
}
The file: /etc/sysctl.conf will already be present on your host (created by the initscripts package).
I would recommend to modify existing files with puppet using augeas instead of replacing them.
Example (changes net.ipv4.ip_forward to 1):
class sysctl_augeas_example {
augeas{"Set net.ipv4.ip_forward to 1":
context => "/files",
changes => [
"set etc/sysctl.conf/net.ipv4.ip_forward 1",
]
}
}
include sysctl_augeas_example
Save this example as test.pp and run it with puppet apply test.pp
Related
I'm using nWidart's laravel-modules for a project. The idea is great but I don't like having the modules directory starting with a capital letter (Modules).
I decided to change the directory name in the configuration file:
/config/modules.php
I kept the namespace as Modules, but I changed path:
return [
'namespace' => 'Modules',
'paths' => [
'modules' => base_path('modules'), // Used to be ('Modules')
]
];
I added this to the composer.json file:
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"Modules\\": "modules/"
}
},
Now, I created a Module called Media:
php artisan module:make Media
And also created a model Media:
php artisan module:make-model Media media
My model goes like this:
<?php
namespace Modules\Media\Entities;
use Illuminate\Database\Eloquent\Model;
class Media extends Model{
//
public function categories(){
return $this->belongsToMany( Category::class, 'category_media' );
}
}
Everything works fine, but when I go to tinker
php artisan tinker
And I try to load an Object (which exists) from the database:
$file = \Modules\Media\Entities::find( 1 );
or
$file = Modules\Media\Entities::find( 1 );
or
$file = modules\Media\Entities::find( 1 );
or
$file = \modules\Media\Entities::find( 1 );
I get this error:
PHP Fatal error: Class 'Modules\Media\Entities' not found in eval()'d code on line 1
Any ideas on what might be causing the problem? was it the changeof the directory name? Am I missing something in the composer.json configuration? I have no idea.
After reading my own code, I figured out that I was not referencing the Class, but only the namespace. The correct way to call the Media class was:
$file = \Modules\Media\Entities\Media::find( 1 );
(Notice that this time I end with \Media)
And of course, the result is the expected:
=> Modules\Media\Entities\Media {#857
id: 1,
filename: "my_file.jpg",
properties: "[]",
mime: "image\jpg",
extension: "jpg",
created_at: "2017-05-21 04:37:28",
updated_at: "2017-05-21 04:37:28",
published: 0,
published_at: "2017-05-20 23:37:28",
}
I need to validate agent like memory, processor, and port connectivity before running my other manifest files. So I've created a manifest like following by keeping global facts with and statement and exec resource.
class vc {
#Validateing Infra Before applying chnages
if $::facts['memorysize'] >= '4.00 GiB'and $::facts['processorcount'] >= 2 and Exec['port_connectivity'] {
notify { "Infra validated" : }
include vc::configs
}
else {
notify { "Infra not meeting requirements" : }
}
# Checking port connecitivity to puppet master
exec { 'port_connectivity':
command => 'New-Item c:\debug.txt -type file -Force',
unless => 'if((New-Object System.Net.Sockets.TcpClient ("linux-NAS-storage.com",6163)).connected -eq $true) { exit 1 }',
provider => powershell,
}
}
my theme is puppet should only execute if this if $::facts['memorysize'] >= '4.00 GiB'and $::facts['processorcount'] >= 2 and Exec['port_connectivity'] condition was successful. If exec command was successful and facter returns true then only it should execute, but following manifest executing individually without checking whether that exec statement true or not. My main purpose I need to validate ports before running puppet manifest. Can any please help
I am trying to provision an EC2 instance using puppet. In the process I have downloaded the puppetlabs-postgresql module from puppetlabs. Since I'm fairly new to puppet, i do not want to manage my database by creating classes in my site.pp file located in /etc/puppet/manifests/site.pp. Rather I want to have a module call database in /etc/puppet/modules/database.
What I have done so far is create an init.pp file in /etc/puppet/modules/database. Below is the content of my init.pp file :
class database {
# resources
postgresql::globals{'globals':
version => '9.3',
manage_package_repo => true,
encoding => 'UTF8',
locale => 'it_IT.utf8',
}
postgresql::server{'server':
ensure => 'present',
listen_addresses => '*',
manage_firewall => true,
}
postgresql::server::contrib{'contrib':
package_ensure => 'present',
}
}
And then in my /etc/puppet/manifests/site.pp file i have included the database class as below :
node default {
include localusers
include database
}
However i keep getting an error :
Error: Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type postgresql::globals at /etc/puppet.manifests/init.pp:12
Please what is the correct way to make use of the postgresql classes and resources in my own module and create a database in the module as well ?
You're on the right track, but there are a few issues with how you're using the postgresql module. The reason you're getting the Invalid resource type error is that you're trying to use postgresql::globals as a defined type when it's actually a class. You have the same issue with the other two classes you're using. Try this...
class database {
# set global defaults before creating server
class { 'postgresql::globals':
version => '9.3',
manage_package_repo => true,
encoding => 'UTF8',
locale => 'it_IT.utf8',
}->
class { 'postgresql::server':
listen_addresses => '*',
manage_firewall => true,
}
# install the postgresql contrib package
class { 'postgresql::server::contrib':
package_ensure => 'present',
}
# create database with user and default permissions
postgresql::server::db { 'my_awesome_db':
user => 'my_db_user',
password => 'puppetRocks',
}
}
In the reference section of the module documentation, there's a breakdown of the classes and resources (a.k.a. defined types). The postgresql::server::db type that I used is the simplest way to create a database, user, and permissions all at once. There are separate types available for each of those to provide more fine-grained control.
I'm using the puppet-postgresql module to manage PostgreSQL. That part of the manifest looks like this:
class { 'postgresql::server':
postgres_password => 'postgres',
}
postgresql::server::db { $db_name:
user => $db_user,
password => postgresql_password($db_user, $db_password),
}
Works fine but I get the annoying warning:
Warning: Scope(Class[Postgresql::Server]): Passing "version" to postgresql::server is deprecated; please use postgresql::globals instead.
EDIT:
I even added the version to the globals, but I'm still getting the warning:
class { 'postgresql::globals':
version => '9.3',
}->
class { 'postgresql::server':
postgres_password => 'postgres',
}
postgresql::server::db { $db_name:
user => $db_user,
password => postgresql_password($db_user, $db_password),
}
But I'm not passing any 'version' to postgresql::server. What I'm doing wrong here?
Docs https://forge.puppetlabs.com/puppetlabs/postgresql didn't helped me in this case...
It's a bug in the puppetlabs-postgresql module in the 3.4.x series. It's since been fixed in PR 471 which will be released in the next major version (4.0.0 by the looks of it).
If you don't specify the version, a default version is selected by the module in the file manifests/globals.pp. So you can either edit this file to specify a newer version for your OS or pass the version in parameter when calling postgresql::server
As the title describes I am having an issue provisioning a box successfully. I am trying to install a development box (Apache, PHP and XDebug)
Everything works fine except for the point where I have to include the XDebug functionality, since it is not supplied in the original REPO I am installing it through the Example42/puppet-yum REPO manager.
In this part there is a mistake, since when I try to build the box from scratch I get the the error that package php-perl-xdebug is not available. This is because the repo's are not yet initialized. I have tried several ways to make sure that it would update the repo's before doing any other action. Referencing the classes by -> but this would yield in a looped block. Going through Google did not yield any practical results that would make sure that some commands are ran before others.
I believe it is possible to do this wit the "Required" command, but I could't find a way to use it.
Side note: We're mostly using example42 modules for our building.
Thanks in advance:
The following is the default.pp manifest for the application service.
default.pp
Exec { path => [ "/bin/", "/sbin/" , "/usr/bin/", "/usr/sbin/" ] }
class system-setup {
service { "iptables":
ensure => stopped,
}
}
class php-setup{
php::module { "pdo": }
php::module { "gd": }
# php::module { "fpm": }
php::module { "mysql": }
php::module { "soap": }
# php::module { "zts": }
# php::module { "pecl-apc": }
php::module { "pecl-memcache": }
php::module { "xml": }
php::module{ "pecl-xdebug": }
}
class apache-vhost {
apache::vhost { 'trunk.project.dev':
docroot => '/var/www/html/',
port => '80',
}
}
class { 'yum':
extrarepo => [ 'epel' ],
}
class { 'apache':
source => [ "puppet:///modules/apache/httpd.conf-project" , "puppet:///modules/apache/httpd.conf" ],
}
class { 'php' :
source => ["/vagrant/files/php.ini", "puppet:///modules/php/php.ini"],
}
include php-setup
include apache-vhost
You can put this somewhere:
Class['yum'] -> Package <||>
This is using a resource collector to make sure Class yum is done before any package is installed.