I have a node server that uses environments variables.
I manually add those to my .bashrc file and when the node server runs, it uses them as process.env.something.
Now we have to deploy this service from a Jenkins job.
What is the proper way of setting this up?
If you are talking about setting the environment variable during the run of the Pipeline then you can use Declarative for it.
environment {
PROJECT_NAME = 'Jenkins-Job'
DISABLE_AUTH = 'true'
}
Environment variables can be set globally, like the example below, or per stage.
pipeline {
agent {
label 'linux'
}
environment {
DISABLE_AUTH = 'true'
}
stages {
stage('Build') {
environment {
DB_ENGINE = 'sqlite'
}
steps {
echo "Database engine is ${DB_ENGINE}"
echo "DISABLE_AUTH is ${DISABLE_AUTH}"
sh 'printenv'
}
}
}
}
For more info, please read this
Is there a way to use local-exec to generate an output for a variable inside of Terraform .tf file?
data-external feature of Terraform has helped me
cat owner.sh
jq -n --arg username $(git config user.name) '{"username": $username}'
The config part which must be added on instance_create.tf files;
data "external" "owner_tag_generator" {
program = ["bash", "/full/path/of/owner.sh"]
}
output "owner" {
value = "${data.external.owner_tag_generator.result}"
}
tags {
...
CreatorName = "${data.external.owner_tag_generator.result.username}"
...
}
Puppet beginner here so maybe I'm doing something wrong...
I have a manifest that contains the following define
define amqconf (
$activemq_home = '/opt/apache-activemq',
$group = 'activemq',
$mode = 0644,
$owner = 'activemq',
$broker_name = $title,
$broker_port = 61616,
) {
file { $title:
ensure => present,
path => "${activemq_home}/${broker_name}/conf/activemq.xml",
content => template('profiles/activemq.xml.erb'),
}
}
and then tries to use that define
$broker_conf = hiera('profiles::activemq::broker::conf')
create_resources( amqconf, $broker_conf )
but when I try and use this class I get the following error
Info: Using configured environment 'testing'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Function Call, Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type amqconf at /etc/puppetlabs/code/environments/testing/modules/profiles/manifests/activemq.pp:73:5 on node cust-stage.internal
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
What do I need to do in order to be able to use this define?
EDIT: added complete manifest
class profiles::activemq {
include archive
include profiles::java_7_oracle
$activemq_version = '5.13.3'
define amqconf (
$activemq_home = '/opt/apache-activemq',
$group = 'activemq',
$mode = 0644,
$owner = 'activemq',
$broker_name = $title,
$broker_port = 61616,
) {
file { $title:
ensure => present,
path => "${activemq_home}/${broker_name}/conf/activemq.xml",
content => template('profiles/activemq.xml.erb'),
}
}
group { 'activemq':
ensure => present,
}
user { 'activemq':
groups => 'activemq',
comment => 'Service user for running the ActiveMQ service',
home => "/opt/apache-activemq-$activemq_version",
ensure => present,
shell => '/bin/bash',
}
file { "/opt/apache-activemq-$activemq_version" :
ensure => directory,
owner => 'activemq',
group => 'activemq',
mode => '0755',
}
archive { "/tmp/apache-activemq-$activemq_version-bin.tar.gz" :
ensure => present,
source => 'http://archive.apache.org/dist/activemq/5.13.3/apache-activemq-5.13.3-bin.tar.gz',
checksum => 'c19e2717f5c844a2f271fcd39eb024d04ebcfa5d',
checksum_type => 'sha1',
extract => true,
extract_path => '/opt',
creates => "/opt/apache-activemq-$activemq_version/bin",
cleanup => true,
user => 'activemq',
group => 'activemq',
}
# Create the brokers defined in hiera.
$brokers = hiera('profiles::activemq::brokers')
$broker_defaults = {
cwd => "/opt/apache-activemq-${activemq_version}",
group => 'activemq',
user => 'activemq',
}
create_resources( exec , $brokers, $broker_defaults )
$broker_conf = hiera('profiles::activemq::broker::conf')
create_resources( amqconf, $broker_conf )
}
I was never able to get the define to work in the class, but by placing it in its own file, I was able to get the define to work.
amqconf.pp
define profiles::amqconf (
$activemq_home = '/opt/apache-activemq',
$group = 'activemq',
$mode = 0644,
$owner = 'activemq',
$broker_name = $title,
$broker_port = 61616,
$broker_network_uri = 'NONE',
) {
file { $title:
ensure => present,
path => "${activemq_home}/${broker_name}/conf/activemq.xml",
content => template('profiles/activemq.xml.erb'),
}
}
and then declaring it in activemq.pp
profiles::amqconf { 'amq-1-conf' :
broker_name => 'amq-1',
activemq_home => "/opt/apache-activemq-${activemq_version}",
}
The define works as expected.
I want to change the variable "enabled" in jail.conf of Fail2ban according to the status of Proftpd on the agent machine.
Ex: If on the agent machine, Proftpd is running, "enable = true" (Fail2ban will monitor Proftpd)
If Proftpd is stopped, "enable = false" (Fail2ban won't monitor Proftpd)
My init.pp file :
class fail2ban {
package { "fail2ban":
ensure => "installed",
}
service { "fail2ban":
ensure => "running",
enable => "true",
require => Package["fail2ban"],
}
$path = "/var/run/proftpd.pid"
$status = inline_template("<% if File.exist?(#path) -%>true<% else -%>false<%end -%>")
file { "jail.conf":
path => '/etc/fail2ban/jail.conf',
ensure => file,
require => Package['fail2ban'],
content => template("fail2ban/jail.conf.erb"),
notify => Service['fail2ban'],
}
My template jail.conf.erb file:
[proftpd]
enabled = <%= $status %>
port = ftp,ftp-data,ftps,ftps-data
filter = proftpd
logpath = /var/log/proftpd/proftpd.log
maxretry = 5
The problem is that my "enabled" result is according to the check on Puppet Master, not the agent machine, while I need to do the check on the agent machine.
Can anyone help me ?
I am using the following Puppet definition to disable IPV6 in windows:
#IPv6 Management
define winconfig::ipv6 (
$ensure,
$state = UNDEF,
) {
include winconfig::params
case $ensure {
'present','enabled': {
case $state {
UNDEF,'all': { $ipv6_data = '0' }
'preferred': { $ipv6_data = '0x20' }
'nontunnel': { $ipv6_data = '0x10' }
'tunnel': { $ipv6_data = '0x01' }
default: { $ipv6_data = '0' }
}
}
'absent','disabled': { $ipv6_data = '0xffffffff' }
default: { fail('You must specify ensure status...') }
}
registry::value{'ipv6':
key => 'hklm\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters',
value => 'DisabledComponents',
type => 'dword',
data => $ipv6_data,
}
reboot {'ipv6':
subscribe => Registry::Value['ipv6'],
}
}
In Site.pp on the master I am using the follwing to call it from a node:
node 'BMSGITSS1' {
# Disable IPV6
winconfig::ipv6 {
ensure => 'disabled',
}
}
I get the following error when running puppet agent -t
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Could
not parse for environment production: All resource specifications require names
; expected '%s' at /etc/puppetlabs/puppet/manifests/site.pp:55 on node bmsgitss1
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
The hint is in the error:
All resource specifications require names; expected '%s'
You need to give it a name:
winconfig::ipv6{"Disable IPv6":
ensure => 'disabled',
}