How should I structure my hiera for systemd limits? - puppet

I am trying to use https://github.com/camptocamp/puppet-systemd.
I want to setup some systemd limits for a service so I have included ...
include ::systemd
... in my manifest. And I have this hiera data:
systemd::service_limits:
'openstack-nova-compute.service':
limits:
LimitNOFILE: 32768
But when puppet on my node I get this error:
Error while evaluating a Function Call, Class[Systemd]: parameter 'service_limits' unrecognized key 'openstack-nova-compute.service' at ...
I have looked at the docs and they do not explain how to form the hash in hiera, they just give this example:
::systemd::service_limits { 'foo.service':
limits => {
'LimitNOFILE' => 8192,
'LimitNPROC' => 16384,
}
}
So how would I do that in hiera/yaml?

Related

How to create a custom blueprint?

I'm trying to create a customized JHipster blueprint for my organization.
I've started my journey:
Installed Yeoman v4.3.0
Installed Jhipster v7.9.3
Created a directory for my future blueprint mkdir mygenerator && cd mygenerator
Executed the command to create a new blueprint: jhipster generate-blueprint
selected only the sub-generator server
add a cli: Y
Is server generator a side-by-side blueprint: Y
Is server generator a cli command: N
selected the tasks: initializing, prompting and configuring
From this point, I've opened the generated blueprint project with VS Code and noticed a first problem, some jhipster packages can't be resolved:
Unable to resolve path to module 'generator-jhipster/esm/generators/server'
Unable to resolve path to module 'generator-jhipster/esm/priorities'
I also noticed that the generator created for me has a small difference from the existing generators in the JHipster Github, such as jhipster-dotnetcore, generator-jhipster-quarkus, generator-jhipster-nodejs: the returned functions are async while in the cited repos they are regular functions (sync):
get [INITIALIZING_PRIORITY]() {
return {
async initializingTemplateTask() {},
};
}
Does it make any difference in this Jhipster version or there is no problem if I return the same way as jhipster-dotnetcore:
get initializing() {
return {
...super._initializing(),
setupServerConsts() {
this.packagejs = packagejs;
...
I've assumed that this detail is not important and followed with async function and write my prompting function to get some input from the user/developer in order to replace values in the template files :
get [PROMPTING_PRIORITY]() {
return {
...super._prompting(),
async promptingTemplateTask() {
const choices = [
{
name: 'OAuth 2.0 Protocol',
value: 'oauth2',
},
{
name: 'CAS Protocol',
value: 'cas',
},
];
const PROMPTS = {
type: 'list',
name: 'authenticationProtocol',
message: 'Which authentication protocol do you want to use?',
choices,
default: 'oauth2',
};
const done = this.async();
if (choices.length > 0) {
this.prompt(PROMPTS).then(prompt => {
this.authenticationProtocol = this.jhipsterConfig.authenticationProtocol = prompt.authenticationProtocol;
done();
});
} else {
done();
}
},
};
}
<%_ if (authenticationProtocol == 'oauth2') { _%>
security:
enable-csrf: true
oauth2:
client:
clientId: ${this.baseName}
clientSecret: Z3ByZXBmdGVy
accessTokenUri: http://localhost:8443/oauth2.0/accessToken
userAuthorizationUri: http://localhost:8443/oauth2.0/authorize
tokenName: oauth_token
authenticationScheme: query
clientAuthenticationScheme: form
logoutUri: http://localhost:8443/logout
clientSuccessUri: http://localhost:4200/#/login-success
resource:
userInfoUri: http://localhost:8443/oauth2.0/profile
<%_ } _%>
thymeleaf:
mode: HTML
templates/src/test/java/resources/config/application.yml.ejs
All this done, I've followed the next steps:
Run npm link inside the blueprint directory.
Created a new directory for a app example: mkdir appmygenerator && cd appmygenerator
Started a new example app with my blueprint: jhipster --blueprint mygenerator --skip-git --skip-install --skip-user-management --skip-client answering all question.
Here I've got some surprises:
After answering What is the base name of your application? I've got this warning: [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./lib/util/" in the "exports" field module resolution of the package at /...<my-generator-path>/node_modules/yeoman-environment/package.json. Update this package.json to use a subpath pattern like "./lib/util/*"
My prompting function somehow made some questions be repeated, from question Do you want to make it reactive with Spring WebFlux? until Which other technologies would you like to use?.
When my prompt was finally shown, there was a message in front of the last option: CAS Protocol Run-async wrapped function (sync) returned a promise but async() callback must be executed to resolve
I've made some changes to my prompt function: removed the calling of super._prompting() with the hope to solve the item 2, and removed the async in the hope to solve the item 3.
Well ... apparently it was solved. But I get a new error when JHipster (or Yeoman) try process the template:
An error occured while running jhipster:server#writeFiles
ERROR! /home/fabianorodrigo/Downloads/my-blueprint/generators/server/templates/src/test/resources/config/application.yml.ejs:47
45| favicon:
46| enabled: false
>> 47| <%_ if (authenticationProtocol == 'oauth2') { _%>
48| security:
49| enable-csrf: true
50| oauth2:
authenticationProtocol is not defined
How come authenticationProtocol is not defined? I'm stuck here. What I could noticed is that, in all the Jhipster's generators I've cited above, the prompt function sets the properties like "this.[property] = [value]" and the "this.jhipsterConfig.[property] = [value]" and in the templates they are referenced (just the property's name) and it works.
What am I missing? Why even if I set the property "this.authenticationProtocol" in the function prompting it is not seem at the template?
Yeoman (yo/yeoman-generator/yeoman-environment) are not required and should no be a dependency to avoid duplication in the dependency tree, unless you know what you are doing. JHipster customizes them, yeoman-test is required by tests.
Unable to resolve path to module is a bug at eslint-plugin-import
I also noticed that the generator created for me has a small difference from the existing generators in the JHipster Github, such as jhipster-dotnetcore, generator-jhipster-quarkus, generator-jhipster-nodejs. Those blueprints are quite old (blueprint support is changing very fast for v8/esm) and are full server/backend replacements, seems you are trying to add cas support. The use case is quite different.
Does it make any difference in this Jhipster version or there is no problem if I return the same way as jhipster-dotnetcore? Yes, get [INITIALIZING_PRIORITY]() is the new notation, and INITIALIZING_PRIORITY may be >initializing instead of initializing. The explanation is here. JHipster v8 will not support the old notation.
...super._prompting(), is used to ask original prompts, since this is a side-by-side blueprint, prompts will be duplicated.
[DEP0148] DeprecationWarning: Use of deprecated folder mapping "./lib/util/" is a bug in yeoman-environment, and should be fixed in next version.
CAS Protocol Run-async wrapped function (sync) returned a promise but async() callback must be executed to resolve is shown because you are using async function with const done = this.async(); done(); together.
this.async() is a to support async through callbacks before Promises were a js default.
There are a few blueprints that uses new notation and can be used as inspiration: native, ionic, jooq and entity-audit.
I didn't see anything about the writing priority, so it looks like you are overriding an existing template and the original generator will write it. For this reason you should inject you configuration into the original generator.
The end result should be something like:
get [INITIALIZING_PRIORITY]() {
return {
async initializingTemplateTask() {
this.info('this blueprint adds support to cas authentication protocol');
},
};
}
get [PROMPTING_PRIORITY]() {
return {
async promptingTemplateTask() {
await this.prompt({
type: 'list',
name: 'authenticationProtocol',
message: 'Which authentication protocol do you want to use?',
choices: [
{
name: 'OAuth 2.0 Protocol',
value: 'oauth2',
},
{
name: 'CAS Protocol',
value: 'cas',
},
],
default: 'oauth2',
}, this.blueprintStorage); // <- `this.blueprintStorage` tells the prompt function to store the configuration inside `.yo-rc.json` at the blueprint namespace.
},
};
}
get [CONFIGURING_PRIORITY]() {
return {
configuringTemplateTask() {
// Store the default configuration
this.blueprintConfig.authenticationProtocol = this.blueprintConfig.authenticationProtocol || 'oauth2';
},
};
}
get [LOADING_PRIORITY]() {
return {
loadingTemplateTask() {
// Load the stored configuration, the prompt can be skipped so this needs to be in another priority.
this.authenticationProtocol = this.blueprintConfig.authenticationProtocol;
// Inject the configuration into the original generator. If you are writing the template by yourself, this may be not necessary.
this.options.jhipsterContext.authenticationProtocol = this.blueprintConfig.authenticationProtocol;
},
};
}

puppet migration: v3.8.5 -> v5.4.0 "Could not find template"

I'm migrating a from puppetmaster on Xenial (v3.8.5) to Bionic (v5.4.0) and have run into an issue. So far I've copied the node and modules files from the old server to the new and had a client connect. I keep getting the following error on the client and master:
Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Function Call, Could not find template 'ntp/client_ntp.conf.erb' (file: /etc/puppet/code/environments/production/manifests/modules/ntp/manifests/init.pp, line: 17, column: 20) on node owain18.dimerocker.com
The template file exists at: /etc/puppet/code/environments/production/manifests/modules/ntp/templates/client_ntp.conf.erb
The contents of ntp/manifests/init.pp:
class ntp {
package { "ntp": }
file { "/etc/ntp.conf":
mode => "644",
content => template("ntp/client_ntp.conf.erb"),
notify => Service["ntp"],
require => Package["ntp"],
} # file
service { "ntp":
ensure => running,
enable => true,
require => Package["ntp"],
} # service
} # class ntp
(I removed some comments from the top of the file so the line number in the error doesn't match, but there's no code missing.)
Any pointers on how to fix this issue? Thanks for your help.

Cannot delete files from firebase collection

I am following the example listed here, except with modifications due to the API of the new firebase-tools.
exports.clearMessages = functions.runWith({ timeoutSeconds: 540, memory: '2GB' }).https.onCall(messagesController.clearMessages)
export const clearMessages = async (data, context) => {
const uid = context.auth.uid
const path = `users/${uid}/messages`
return firebase_tools.firestore.delete('flightApp3', path, {
recursive: true,
shallow: true,
allCollections: true
}).then(result => {
console.log('delete result', result)
return result
})
}
However, when I run this , I see the following displayed in Cloud Functions log:
Unhandled error { Error
at Error.FirebaseError (/user_code/node_modules/firebase-tools/lib/error.js:9:18)
at module.exports (/user_code/node_modules/firebase-tools/lib/getProjectId.js:10:19)
at Command.module.exports (/user_code/node_modules/firebase-tools/lib/requirePermissions.js:11:21)
at /user_code/node_modules/firebase-tools/lib/command.js:154:38
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
name: 'FirebaseError',
message: 'No project active. Run with \u001b[1m--project <projectId>\u001b[22m or define an alias by\nrunning \u001b[1mfirebase use --add\u001b[22m',
children: [],
status: 500,
exit: 1,
stack: 'Error\n at Error.FirebaseError (/user_code/node_modules/firebase-tools/lib/error.js:9:18)\n at module.exports (/user_code/node_modules/firebase-tools/lib/getProjectId.js:10:19)\n at Command.module.exports (/user_code/node_modules/firebase-tools/lib/requirePermissions.js:11:21)\n at /user_code/node_modules/firebase-tools/lib/command.js:154:38\n at process._tickDomainCallback (internal/process/next_tick.js:135:7)',
original: undefined,
context: undefined }
However, I'm pretty sure I have an active project in my firebase CLI.
$ firebase use
Active Project: production (flightApp3)
Project aliases for /Users/myUser/Developer/flightApp3/cloud:
* default (flightApp3)
* production (flightApp3)
Run firebase use --add to define a new project alias.
some options cannot be mixed ...
return firebase_tools.firestore.delete('flightApp3', path, {
// allCollections: true,
recursive: true,
yes: true
}).then(() => {
return {
path: path
};
});
that's how the path is being built up (path and allCollections also do not seem to make sense together): projects/${project}/databases/(default)/documents/users/${uid}/messages
getProjectId.js checks for rc.projects (where options.project is option --project):
module.exports = function(options, allowNull) {
if (!options.project && !allowNull) {
var aliases = _.get(options, "rc.projects", {});
...
these rc.projects are the projects from the .firebaserc file:
{
"projects": {
"default": "flightApp3"
}
}
or run firebase use default to switch from alias production to default (or remove alias production once for a test). FirestoreDelete(project, path, options) also does not care about options.token nor options.project anymore (as the documentation suggests).
$ firebase firestore:delete --help explains the command-line options:
Usage: firestore:delete [options] [path]
Delete data from Cloud Firestore.
Options:
-r, --recursive Recursive. Delete all documents and sub-collections.
Any action which would result in the deletion of child
documents will fail if this argument is not passed.
May not be passed along with --shallow.
--shallow Shallow. Delete only parent documents and ignore documents
in sub-collections. Any action which would orphan documents
will fail if this argument is not passed.
May not be passed along with --recursive.
--all-collections Delete all. Deletes the entire Firestore database,
including all collections and documents.
Any other flags or arguments will be ignored.
-y, --yes No confirmation. Otherwise, a confirmation prompt will appear.
the npm package (the output above) is at version 6.0.1.
just found a relevant comment (but possibly obsolete):
The token must be set in the functions config, and can be generated at the command line by running firebase login:ci.
this hints for environment configuration, so that functions.config().fb.token has the token:
firebase functions:config:set fb.token="THE TOKEN"
one can also obtain the projectId from process.env.FIREBASE_CONFIG.projectId.
Docs https://firebase.google.com/docs/firestore/solutions/delete-collections
In /functions directory install firebase-tools
"firebase-tools": "^7.16.2"
In cloud function import firebase-tools and call delete
const firebaseTools = require("firebase-tools");
...
firebaseTools.firestore.delete(workspaceRef.path, {
project: process.env.GCLOUD_PROJECT, // required
recursive: true, // required
yes: true // required
})
There is no need for a token when calling firebase-tools from a cloud function.
Also the link to the API https://github.com/firebase/firebase-tools/blob/v7.16.2/src/firestore/delete.js with code implementation for FirestoreDelete seems wrong.
I'm successfully calling .delete(path, options) but the code says .delete(project, path, options)?

Puppet invalid parameter encoding

Trying to use puppets file_line to update /etc/environment
class system_variables {
include stdlib
file { '/etc/environment':
ensure => present
} ->
file_line { 'Add ENVIRONMENT_TYPE':
path => '/etc/environment',
line => 'ENVIRONMENT_TYPE="production"',
match => '^ENVIRONMENT_TYPE'
}
}
But keep getting error:
Error: /Stage[main]/System_variables/File_line[Add ENVIRONMENT_TYPE]: Could not evaluate: Invalid parameter encoding(:encoding)
I have tried googling but to no avail.
Edit:
Ive also tested it on the master server where it runs without errors.
The file encoding is the same on both servers, and checked locales on each server aswell.

Puppet notify service error

I try to write a puppet configuration in order to install lamp env.
But i have an issue with notify option.
I have an apache conf:
class apache inherits apache::params {
package { 'apache':
name => "${apache::params::package}",
ensure => present
}
service { 'apache':
ensure => running,
name => $apache::params::service,
enable => true,
subscribe => Package['apache'],
}
}
and and php module conf:
define php::module(
$notify = $php::params::notify,
$package_prefix = $php::params::module_package_prefix
) {
package { "php-module-${name}":
ensure => present,
name => "${package_prefix}${name}",
notify => Service['apache'],
require => [Class['apache'], Package['php', 'php-dev']]
}
}
but when I launch puppet I have this error:
Error: Parameter notify failed on Php::Module[mcrypt]: No title provided and "apache" is not a valid resource reference
I don't understand why it said that apache service is not a valid resources ?
I think there might be 2 issues here:
1) Puppet doesn't like this line in php::module:
$notify = $php::params::notify,
Can you try to remove that or check what is in $php::params::notify? (I don't see you using it)
2) Did you have something like
include apache
in your site.pp? The class still needs to be declared before you can reference the contained resources.

Resources