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.
Related
I need to import a file into my project when an environment variable is set, say dist/built.esm.js. It's implied that when the environment variable is set, the file will exist, otherwise it may or may not exist. It seems straightforward to just wrap a call to import in an if statement that checks for the environment variable, but Vue throws the below warning even if the if statement never passes:
And the code:
if (process.env.VUE_APP_USE_COMPILED == 'true') {
const compiledPackage = require('./dist/built.esm.js')
Vue.use(compiledPackage)
}
Setting the if statement to always be false in a nondeterminate way (setting a string var and then comparing it to a different value, instead of just if (false)) results in the same problem, which rules out any possibility of the environment variable being 'true' when it isn't supposed to be.
A temporary workaround I found is to wrap the import in a try/catch, which instead displays a warning instead of an error:
How can I get rid of the errors and warnings completely? I do want it to still error if the file doesn't exist but the environment variable has been set to true, but it shouldn't fail or warn on compilation if the statement hasn't even executed yet.
Does this work?
if (process.env.VUE_APP_USE_COMPILED == 'true') {
import('dist/built.esm.js')
.then(obj => Vue.use(obj))
.catch(err => console.log(err));
}
I managed to figure this out on my own. I used the resolve.alias property in the Webpack configuration to allow a 'soft fail' when the file doesn't exist. I changed my import to use an alias (my-compiled-package-alias), which would conditionally resolve to either the built file or an empty dummy file (dev/import-dummy.js). I had to use resolve.alias rather than resolve.fallback, since Vue2 uses Webpack v4 which doesn't include the latter property.
My updated code:
if (process.env.VUE_APP_USE_COMPILED == 'true') {
const compiledPackage = require('my-compiled-package-alias')
Vue.use(compiledPackage)
}
In my vue.config.js:
module.exports = {
...
configureWebpack: {
resolve: {
alias: {
"my-compiled-package-alias":
process.env.VUE_APP_USE_COMPILED ? "./dist/built.esm.js": "./import-dummy.js"
}
}
},
...
}
but it shouldn't fail or warn on compilation if the statement hasn't even executed yet
Compilation happens before execution. If you get a compile error, that means something went wrong before your code was executed, including any conditionals.
What I believe happens here is that you're using webpack, and it's trying to include dist/built.esm.js in your bundle. Behind the scenes, webpack actually replaces require with some magic. To get around this, use __non_webpack_require__ instead
You could try setting up a compile-time constant using DefinePlugin in your webpack config, maybe something like
plugins: [
new webpack.DefinePlugin({
// this is resolved compile-time
USE_COMPILED: process.env.VUE_APP_USE_COMPILED == 'true'
})
]
Then, in your code
if (USE_COMPILED) require('./dist/built.esm.js')
Here the value of USE_COMPILED should be replaced by webpack compile-time with true if your environment var is set to 'true', and false otherwise.
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.
I was trying to create a new file in my module, but every time I am getting an error for my file resource, saying:
File paths must be fully qualified, not '/the/path/that/I/have/given'.
What are the possible reasons for that error?
class fresh_start {
file { 'source_file.rb':
ensure => 'file',
source => 'puppet:///modules/fresh_start/source_file.rb',
path => '/etc/puppetlabs/code/environments/production/modules/fresh_start/destination_file.rb',
owner => 'root',
group => 'root',
mode => '0755', # Use 0700 if it is sensitive
notify => Exec['run_my_ruby']
}
exec { 'run_my_ruby':
command => 'ruby etc/puppetlabs/code/environments/production/modules/fresh_start/source_file.rb > /etc/puppetlabs/code/environments/production/modules/fresh_start/output.txt',
refreshonly => true,
}
}
I have also tried to put the file path in a variable and use that variable as the path attribute's value, but I got the same error.
This happens when you attempt to run code with Unix paths on Windows. Check out the Puppet source code here and here.
Using a debugger, we can see that Unix-style paths are rejected on a Windows platform:
[1] pry(main)> slash = '[\\\\/]'
=> "[\\\\/]"
[2] pry(main)> label = '[^\\\\/]+'
=> "[^\\\\/]+"
[3] pry(main)> AbsolutePathWindows = %r!^(?:(?:[A-Z]:#{slash})|(?:#{slash}#{slash}#{label}#{slash}#{label})|(?:#{slash}#{slash}\?#{slash}#{label}))!io
=> /^(?:(?:[A-Z]:[\\\/])|(?:[\\\/][\\\/][^\\\/]+[\\\/][^\\\/]+)|(?:[\\\/][\\\/]\?[\\\/][^\\\/]+))/i
[4] pry(main)> path = '/foo/bar'
=> "/foo/bar"
[5] pry(main)> path =~ AbsolutePathWindows
=> nil
I am getting this error when applying my Puppet manifest:
Error: Could not apply complete catalog: Found 1 dependency cycle:
(Exec[pip install requirements] => File[change venv permissions] => File[enforce MinGW compiler] => Exec[pip install requirements])
Try the '--graph' option and opening the resulting '.dot' file in OmniGraffle or GraphViz
Here is my Puppet manifest (the relevant part) and I don't see any dependency cycle there. Any ideas?
exec {'create virtualenv':
command => "$install_dir/Scripts/virtualenv.exe venv",
cwd => $project_dir,
require => Exec['install virtualenv'],
}
file { "fix Mingw32CCompiler":
path => "C:/Python27/Lib/distutils/cygwinccompiler.py",
content => template($cygwinc_template),
ensure => present,
require => Exec['create virtualenv'],
}
file { "enforce MinGW compiler":
path => "$project_dir/venv/Lib/distutils/distutils.cfg",
owner => $user,
content => $mingw,
ensure => present,
require => File['fix Mingw32CCompiler'],
}
exec {'pip install requirements':
timeout => 1200,
command => "$project_dir/venv/Scripts/pip.exe install -r $project_dir/requirements.txt",
require => File['enforce MinGW compiler'],
}
file {'change venv permissions':
path => "$project_dir/venv",
recurse => true,
owner => $user,
mode => 0770,
require => Exec['pip install requirements'],
}
In puppet files have an implicit require for any parent directories that are declared.
Effectively:
File['change venv permissions'] -> File['enforce MinGW compiler']
So the parent requires the exec, the exec requires the child, and the child requires the parent, creating a loop.
What was your last change (that's probably the moment you added the cycle).
Try the suggestion to generate the graph. Post the generated dot file as gist so that we can investigate further.
Take a look at Debugging cycle or missing dependency.
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.