I am using the backuppc module that has the following code for the client:
##file { "${backuppc::params::config_directory}/pc/${::fqdn}.pl":
ensure => $ensure,
content => template("${module_name}/host.pl.erb"),
owner => 'backuppc',
group => $backuppc::params::group_apache,
mode => '0640',
tag => "backuppc_config_${backuppc_hostname}"
}
While the backuppc server uses this code to create the files:
File <<| tag == "backuppc_config_${::fqdn}" |>> {
group => $backuppc::params::group_apache,
notify => Service[$backuppc::params::service],
require => File["${backuppc::params::config_directory}/pc"],
}
Twenty seven other hosts have their files written out,for some darn reason the puppet master is not pushing the config. The class on the client, puppetmaster, ran because the other components worked. I can see the class running with a do a puppet agent --debug --test, but I am looking for recommendations on how to debug this further. Other servers are running fine. It is the puppet master that is not pushing the config to backuppc_config tag.
There are two things that are missing:
1. a config file that is created
2. an entry in a host file for backuppc
As I mentioned multiple other servers are working, but not the darn puppetmaster, which is just kinda important to backup.
Adding notify debugging is showing that the command is running, but when I poll the /v3/resources url, the resource is not showing up. The other resources that are not exported are showing up, but for some reason the puppet on the puppet master is not exporting that resource.
To add more fun to this I am seeing puppetdb insert the resource into the database.
2014-05-16 17:31:53,688 DEBUG [command-proc-69] [bonecp.PreparedStatementHandle] INSERT INTO catalog_resources (catalog_id,resource,type,title,tags,exported,file,line) VALUES (6,'14be980772ccedd05d2c7e8d31563f20159b71a1','File','/etc/backuppc/pc/myserver_redacted.com.pl',(array of type7),true,'/etc/puppet/modules/backuppc/manifests/client.pp',418)
2014-05-16 17:31:53,689 DEBUG [command-proc-69] [bonecp.PreparedStatementHandle] INSERT INTO catalog_resources (catalog_id,resource,type,title,tags,exported,file,line) VALUES (6,'65c88548872aba1ae75da554e75192279da41e8a','File_line','backuppc_host_/myserver_redacted.igivefirst.com',(array of type7),true,'/etc/puppet/modules/backuppc/manifests/client.pp',407)
I actually filed a bug on puppetdb on this item: https://tickets.puppetlabs.com/browse/PDB-672
Related
service{'cron':
ensure => 'running',
enable => 'true',
}
Error:
change from 'running' to 'stopped' failed: systems stop for cron failed.
Drop this
service { 'crond':
ensure => 'running',
enable => 'true',
}
Into a file on a server, let's call the file crontest.pp then as root run puppet apply crontest.pp you should see cron start.
Also, if you're trying to debug this sort of thing a good starting place is to use puppet resource in this case puppet resource service, you should be able to see a list of all your services. Look through that to find the one relating to cron, it gives you the Puppet code for it's current state so you can copy that directly into a class file, just ignore the provider => line as the Puppet resource abstraction layer will take care of that.
We're using Puppet + Foreman to monitor changes in environment by checking custom facts. For example, whenever a custom fact equals 'true' puppet calls the Notify resource with a message sent to the agent log. Puppet includes this message in the agent report and Foreman shows this in UI.
Problem is that whenever a message is thrown, Foreman considers this action as "Applied" and the node status changes to "Active" (blue icon).
We want to keep the node at "No Changes" (Green) plus show the Notify message.
Is that possible in some way? Maybe define a new custom resource type?
Here is the puppet code:
class mymodule::myclass::mysubclass {
if $::fact023 == 'fail' {
notify {'mynotify1':
message => "WARNING: Node ${::fqdn} failed fact023",
loglevel => hiera('warnings_loglevel'),
} } }
See screenshot of Foreman here
Update:
I'll refine the question: Is there a way to use the Notify resource without causing puppet to report that the node has changed? Meaning just print the message to client log (and therefore the message will be visible in report) but without puppet classify the event as an applied configuration?
The reason is that when puppet triggers the Notify resource, Foreman flags the node as being active (changed)
UPDATE #2
I'm thinking about changing Foreman report file so that the UI will ignore Notify events so that the node's status will remain unchanged but still show the message in the report. Can someone point me to the right direction? Thanks!
UPDATE #3
Problem fixed after switching from the "Notify" resource type to custom type "echo" created by some dude in Puppet Forge. Thanks!
It's not completely clear what you are trying to accomplish. One option would be to use the notice function instead of a resource. Functions execute on the puppet master, so you the log will end up in the puppet master's logs instead of the agent report. That also means that it will not count as an applied resource, and the node should appear to be stable.
I'm looking for a way to display a notify { ... } message during puppet client run only when using
puppet apply <--verbose | --debug>
puppet agent <--verbose | --debug>
I'd like to display debug messages when interactively/manually running puppet on clients.
Yet, I couldn't find a way to evaluate these switches in my puppet manifests. How could I achieve this for puppet 4.x?
All Puppet resources support the loglevel metaparameter, including notify. Set it to debug to make a resource report on that level.
notify { "this is a debug message": loglevel => "debug" }
Output from such resources is hidden by default.
The verbose option does not imply a specific log level.
Presently I have my logs and logstash running on the same machine, so I read my logs placed on my local machine with this config(using pull model)
input {
file {
path => "/home/Desktop/Logstash-Input/**/*_log"
start_position => "beginning"
}
}
Now, we have logstash running on a different machine and want to read the logs remote mechine.
Is there a way to set the ip in file input of config file?
EDIT:
I manage to do this with logstash-forwarder which is a push model(log shipper/logstash-forwarder will ship log to logstash index server) but still i am looking for a pull model without shipper, where logstash index server will go and contact directly to remote host.
Take a look to FileBeat: https://www.elastic.co/products/beats/filebeat
It´s not a pull model but it seems a better choice than logstash-forwarder.
It monitors log files and forwards them to Logstash or Elasticsearh. It keeps also the state of log files and guarantees that events will be delivered at least one time (depends on log rotation speed). It's really easy to configure:
Input configuration:
input_type: log
paths:
- /opt/app/logs
Output configuration
output.logstash:
hosts: ["remote_host:5044"]
index: filebeat_logs
In the logstash side you must install and configure the Beats input plugin:
input {
beats {
port => 5044
}
}
Logstash doesn't contain any magic to read files from other computer's file systems (and that's probably a good thing). You'll either have to mount the remote file system that contains the logs you're interested in or you have to install a log shipper (like e.g. Logstash) on the remote machine and configure it to send the data to your current Logstash instance (or an intermediate broker like Redis, RabbitMQ, or Kafka).
You could also use the syslog daemon (that's probably already installed on the machine) to ship logs via the syslog protocol, but keep in mind that there's no guarantee of the maximum allowed length of each message.
You can add the remote system IP in the path and access the logs from Remote machine.
input {
file {
path => "\\IP address/home/Desktop/Logstash-Input/**/*_log"
start_position => "beginning"
}}
How can we write a puppet manifest code that identifies whether a service(httpd) is running or not on puppet clients/agents. And if not, it should start that service and send out an email ?
class apache {
package { mysql-server: ensure => installed }
if hasstatus == "false" {
service { "mysql":
ensure => running,
require => Package["mysql-server"],
}
}
}
node default {
include apache
}
I know this is not a correct code. But I want to check hasstatus first and if the service status is false then I want to start service and send out an email.
Thanks
Sanket Dangi
I have configured tagmail.conf in puppet master and have also enabled puppet reports but not able to receive mails to my gmail account. I can see puppet agent reports on puppet master but not receiving mails. Do I need to configure mail server for this ?
My Tagmail Conf :
all: xxxxxxx#gmail.com
Puppet isn't an imperative shell script where you need to check the value of X before performing action Y that gets you to state Z. Instead, you specify that you want state Z and Puppet checks the current state and handles the transition.
What this means is that you don't need to check the status of a service before deciding whether to start it or not and instead you declare that the mysql service should be running and Puppet ensures this is the case.
Simply have this in your manifest alongside the package line:
service { "mysql":
ensure => running,
enable => true,
require => Package["mysql-server"],
}
The require line ensures the package is installed before evaluating or starting the service.
To send out notifications you can use the tagmail reporting feature in Puppet. First set up a tagmail file (reference docs) like this at /etc/puppet/tagmail.conf on the master:
mysql, apache: wwwadmins#example.com
And in the master's puppet.conf, set:
[master]
reports = tagmail
Ensure clients have report enabled in puppet.conf:
[agent]
report = true
This should then trigger e-mails relating to any resources with the "mysql" or "apache" tags (class names, module names etc).