import statements fail - deployment

I'm a Puppet newbie. I'm trying to setup a chef-style deployment environment. I have a puppet-master server set up, and I'd like to be able to configure/deploy to two nodes that I set up simultaneously.
What I'm expecting with my puppet setup right now is for my two servers (called img01 and img02) to automatically create a file called /tmp/test_file.txt.
I'm not even sure how to really "load in" a manifest. I just assumed that anything in site.pp would automatically get loaded, but that doesn't seem to be the case. When I run "puppet apply /etc/puppet/manifests/site.pp", I get the following:
Error: Could not parse for environment production: No file(s) found for import of 'test' at /etc/puppet/manifests/site.pp:3 on node puppet.lgwp.com
Error: Could not parse for environment production: No file(s) found for import of 'test' at /etc/puppet/manifests/site.pp:3 on node puppet.lgwp.com
This is what my manifest setup looks like right now:
Cert list on the puppet-master server:
+ "img01.lgwp.com.com" (SHA256) (omitted)
+ "img02.lgwp.com" (SHA256) (omitted)
+ "puppet.lgwp.com" (SHA256) (omitted) (alt names: "DNS:puppet.lgwp.com")
/etc/puppet/manifest/site.pp:
import "test"
import "nodes"
Exec { path => "/usr/bin:/usr/sbin/:/bin:/sbin" }
/etc/puppet/manifest/nodes.pp:
import "test"
node "imageserver" {
include "tempfile"
}
node 'img01.lgwp.com' inherits imageserver {
}
node 'img02.lgwp.com' inherits imageserver {
}
/etc/puppet/modules/test/manifests/test.pp:
class test {
package { test: ensure => latest }
file { "test_file":
path => '/tmp/test_file.txt',
ensure => present,
mode => 0755,
content => 'hola world',
source => "puppet:///modules/test/test_file",
require => Package["test"],
}
}

Don't use import. Just don't.
Remove the existing import statements and change the manifest setting in your puppet.conf to include all files in /etc/puppet/manifests.
[main]
manifest=/etc/puppet/manifests/
include tempfile makes no sense either, unless you have a tempfile module. Try
include test
Other classes in the test module should be named test::something and can also just be included. Puppet locates the manifests in the according modules. There is literally no need to use import anymore.

Related

Passing parameters to puppet manifest via command line

I have been searching for an answer to this question with no luck, but is there a way to pass parameters into puppet manifests when running the 'apply' command, in a similar way to the way you pass parameters when running a UNIX script on the command line?
The suggestions I see mention either keeping variables at the top of the manifest for use later, or to store them in a hiera file. But neither really answer the question I am posing?
Any guidance on how to do this would be greatly appreciated?
Edit:
An example of what I have been doing is:
$doc_root = "/var/www/example"
exec { 'apt-get update':
command => '/usr/bin/apt-get update'
}
package { 'apache2':
ensure => "installed",
require => Exec['apt-get update']
}
file { $doc_root:
ensure => "directory",
owner => "www-data",
group => "www-data",
mode => 644
}
file { "$doc_root/index.html":
ensure => "present",
source => "puppet:///modules/main/index.html",
require => File[$doc_root]
}
As you can see the variable is hardcoded at the top, whereas whilst I am trying to use the variable in the same way, I need to be able to pass the value in when running the apply command.
Using lookup functions in conjunction with hiera.yaml files doesn't fulfil my requirements for the same reason.
The only thing I can think may be a work around is to create a UNIX script that accepts parameters, saves those values in a yaml file, and then have the script execute the .pp file.
But I'm hoping that puppet has a way to do this directly.
The common procedure for passing variables into a classless manifest for use with the puppet apply subcommand would be to assign the value to a Facter fact from the CLI, and then resolve its value inside the manifest. You would begin with removing the hardcoded variable doc_root from the head of the manifest. Then, you would modify the variable into a fact like:
file { $facts['doc_root']:
...
file { "${facts['doc_root']}/index.html":
...
require => File["${facts['doc_root']}"] <-- interpolation required due to Puppet DSL inability to resolve hash value as first class expression
You would then pass the Facter value from the puppet apply subcommand like:
FACTER_doc_root=/var/www/example puppet apply manifest.pp
Note this also causes FACTER_doc_root to be temporarily set as an environment variable as a side effect.

Import a cert file as a string using webpack

I was really hoping I'd be able to use webpack to load a certificate file containing text using the raw-loader. Unfortunately it fails at the -'s in the first line: -----BEGIN CERTIFICATE-----. As a test I removed the first -----, and then it fails at a " " (space) character.
Seemed like a much simpler solution than using fs and a callback.
To clarify, i'd like to be able to do this:
import caCert from './cacert';
If you want to load some file via loader, add loader name as prefix to your import:
import caCert from 'raw!./cacert';
Also, you can setup your loader in webpack config to match appropriate files by their names
module: {
loaders: [
{
test: /cacert$/,
loaders: [ 'raw-loader' ]
}
]
}

Protobufs import from another directory

While trying to compile a proto file named UserOptions.proto which has an import named Account.proto using the below command
protoc --proto_path=/home/project_new1/account --java_out=/home/project_new1/source /home/project_new1/settings/Useroptions.proto
I get the following error :
/home/project_new1/settings/UserOpti‌​ons.proto: File does not reside within any path specified using --proto_path (or -I). You must specify a --proto_path which encompasses this file.
PS: UserOptions.proto present in the directory /home/project_new1/settings
imports Account.proto present in the directory
/home/project_new1/account
Proto descriptor files:
UserOptions.proto
package settings;
import "Account.proto";
option java_outer_classname = "UserOptionsVOProto";
Account.proto
package account;
option java_outer_classname = "AccountVOProto";
message Object
{
optional string userId = 1;
optional string service = 2;
}
As the error message states, the file you pass on the command line needs to be in one of the --proto_paths. In your case, you have only specified one --proto_path of:
/home/project_new1/
But the file you're passing is:
/home/project_new1/settings/UserOpti‌ons.proto
Notice that the file is not in the account subdirectory; it's in settings instead.
You have two options:
(Not recommended) Pass a second --proto_path argument to add .../settings to the path.
(Recommended) Use the root of your source tree as the proto path. E.g.:
protoc --proto_path=/home/project_new1/ --java_out=/home/project_new1 /home/project_new1/settings/UserOpti‌ons.proto
In this case, to import Account.proto, you'll need to write:
import "acco‌​unt/Account.proto";
For those of us who want this really spelled out, here is an example where I have installed the protoc beta for gRPC using NuGet Packages Google.Protobuf, Grpc.Core and Grpc.Tools. My solution packages are one level above my Grpc directory (i.e. at BruTrader\packages). My .proto files are at BruTrader\Grpc\protos.
1. My .proto file:
syntax = "proto3";
import "timestamp.proto";
import "enums.proto";
package BruTrader.Grpc;
message DividendMessage {
double amount = 1;
google.protobuf.Timestamp dateUnix = 2;
}
2. my GenerateProto.bat file:
..\packages\Google.Protobuf.3.0.0-beta2\tools\protoc.exe -I..\Grpc\protos -I..\packages\Google.Protobuf.3.0.0-beta2\tools\google\protobuf --csharp_out=..\Grpc\Generated --grpc_out=..\Grpc\Generated --plugin=protoc-gen-grpc=..\packages\Grpc.Tools.0.13.0\tools\grpc_csharp_plugin.exe %1
3. my BuildProtos.bat
call GenerateProto ..\Grpc\protos\masterinstrument.proto
call GenerateProto .\protos\instrument.proto
etc.
4. BuildProtos.bat is executed as a Pre-build event on my Grpc project like this:
CD $(ProjectDir)
CALL "$(ProjectDir)BuildProtos.bat"
For my environment, Windows 10 Pro operating system and C++ programming languaje, I used the protoc-3.12.2-win64.zip that you can downloat it from here. You should open a Windows PowerShell inside the protoc-3.12.2-win64\bin path and then you must execute one of the next commands:
.\protoc.exe -I=C:\Users\UserName\Desktop\SRC --cpp_out=C:\Users\UserName\Desktop\DST C:\Users\UserName\Desktop\SRC\addressbook.proto
Or
.\protoc.exe --proto_path=C:\Users\UserName\Desktop\SRC --cpp_out=C:\Users\UserName\Desktop\DST C:\Users\UserName\Desktop\SRC\addressbook.proto
Note:
1- My source folder is in: C:\Users\UserName\Desktop\SRC
2- My destination folder is in: C:\Users\UserName\Desktop\DST
3- My .proto file is in: C:\Users\UserName\Desktop\SRC\addressbook.proto

Laravel 4 - how to use the package class as a queue worker

I have built my first Laravel 4 package.
I have used artisan to create the structure.
I need to use the package to process a queue (as the worker).
I am using the builtin Beanstalk queue and have it configured and I am able to add to the queue.
What is the correct syntax to add the correct path to the class that I would like to use to process the queue.
I can get this working if the class is saved here /app/controllers/TestClass.php ( beacuse this gets autoloaded)
Example:
Route::get('/addtoqueue', function()
{
$message = "This is a test message";
Queue::push('TestClass', array('message' => $message));
return 'Added to Queue';
});
But what should I put in as the class in the queue if the class is in a package?
This file is in workbench:
workbench\vendor\package\src\Vendor\Package
My package composer file contains
"autoload": {
"psr-0": {
"Qwickli\\Tika": "src/"
}
},
Eg.
Queue::push('vendor\package\TestClass', array('message' => $message));
When I run php artisan queue:listen it correctly picks up the items in the queue and but it does NOT find the class (in the package) that I would like to use process the queue.
For some reason the class is not being loaded (or autoloaded) and I don't know how to make that happen.
Thanks for all and any help
Looks like your package classes are not been autoloaded.
Try to access your package folder, workbench/vendor/package and run a compsoer update. If your composer "autoload" settings are correct, this should work.

can't get the require work with file in puppet module

i try to get the following code to run:
class common
{
...
# common packages
package
{
["lsb-release", "figlet"]: ensure => installed,
}
# Print some information if someone logs in:
file { "/etc/motd":
#require => [ Package["figlet"], File["/usr/bin/figlet"] ],
require => Package["figlet"],
content => generate('/usr/bin/env', '/usr/bin/figlet','-w', '186', '-p', '-f', 'banner', "$hostname"),
}
....
}
should't this work?
i get the following error:
err: Could not retrieve catalog from remote server: Error 400 on SERVER: Failed to execute generator /usr/bin/env: Execution of '/usr/bin/env /usr/bin/figlet -w 186 -p -f banner hostname' returned 127: /usr/bin/env: /usr/bin/figlet: No such file or directory
at /etc/puppet/modules/common/manifests/init.pp:37 on node puppetmaster.local
warning: Not using cache on failed catalog
err: Could not retrieve catalog; skipping run
first i had no require (row 12) and no package (row 5-8) in the code, to fix the errors i thought to i can simply add the row 12 (require package figlet) but it does not work. so i added the package figlet, but the the error does not go away.
how to add this dependency? shouldn't puppet run through the code and don't skip the run totally?
generate() runs on the server, not the client. (It's a parser function so it has to run on the server)
The class as you've written it will ensure that clients get figlet installed on them, but then tries to run figlet on the puppetmaster. Just install figlet on your puppetmasters and you won't need the package resources.
Also use smslant font, not banner :)