Using hash in node definition and passing to template - hash

I'm struggling to get this to work and don't understand where I'm going wrong, can someone please guide me on how to correct?
Basically I want to get an array in my nodes.pp, which is then used by my templates file by cycling through it and writing a line of each element:
nodes.pp:
node test{
net::addr { 'routing':
$routes = {
route1 => {
address => '172.29.54.70',
netmask => '255.255.255.0',
gateway => '172.29.54.65',
dev => 'eth0',
},
route2 => {
address => '192.168.1.3',
netmask => '255.255.255.0',
gateway => '192.168.1.1',
dev => 'eth3',
},
}
}
}
When I run the puppet client i keep getting the following:
err: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not parse for environment production: Syntax error at '='; expected '}' at /etc/puppet/manifests/nodes/
test.pp:3 on node test.myincorp.net
addr.pp
define net::addr (
$address='',
$netmask='',
$gateway='',
$dev='',
) {
file { "route-${name}":
ensure => 'present',
mode => '0644',
owner => 'root',
group => 'root',
path => "/etc/sysconfig/network-scripts/route-${name}",
content => template('network/addr.erb'),
}
}
Template: addr.erb:
<% routes.each do |route| -%>
<%= route['address'] %> <%= route['netmask'] %> <%= route['gateway'] %> <%= route['dev'] %>
<% end -%>
<% end -%>
<% end -%>
Can someone help me with fixing the above please?
Thanks
Dan

I believe the actual issue here is the use of a variable ($routes) in the definition of a resource: instead of using a $routes = { ... }, you must set key/value pairs in the definition of a resource, such as routes => { ... }.
But I actually would recommend a different route entirely: have you seen the puppet-network module? It handles creation of static route files for you automatically, so you wouldn't have to implement any of this functionality yourself. For example, puppet-network implements this using the following:
network::route { "eth0":
address => [ "192.168.2.0", "10.0.0.0", ],
netmask => [ "255.255.255.0", "255.0.0.0", ],
gateway => [ "192.168.1.1", "10.0.0.1", ],
}
See more details at GitHub or PuppetForge

Related

Errors accessing hash in mojolicious

I am having issues accessing my hash in mojolicious.
my %managers = (
'IT' => {
'name' => 'Mike',
'id' => 1,
'num_of_employees' => 15,
},
'Sales' => {
'name' => 'John',
'id' => 33,
'num_of_employees'=> 50,
},
);
In perl I can access the data like $managers{'IT'}{'name'} would print out Mike. How would I do the same in mojolicious?
Being passed to my template
$g->stash(manage => \%managers);
<%== $manage{'IT'}{'name'} %>
The above throws an error. printing <%== $manage %> gives a HASH(0x1335430) location.
In your template $manage is a hash ref not a hash, so you need to dereference it by using the -> operator like this
<%== $manager->{'IT'}{'name'} %>

Perl script with JIRA REST-API to create JIRA along with custom field

We are unable to create the new ticket in Jira using REST-API via Perl script.
Note: Without custom field script successfully executing. please provide the suggestion to add a custom field in my script.
Screenshot for the custom field.
Error Message:
JIRA::REST Error[400 - Bad Request]:
- [custom_field] Field 'custom_field' cannot be set. It is not on the appropriate screen, or unknown.at copy_of_new-jira.pl line 16.
Perl Script :
#Loading the modules from a specific location such that JIRA::REST.
use JIRA::Client::Automated;
use JIRA::REST;
use Data::Dumper;
#Login details about Jira server
my $jira = JIRA::REST->new({
url => 'https://xxxxxxxx.xxxxx.com',
username => 'xxxxxxx',
password => 'xxxxxxx',
});
# Create the ticket using post function
my $issue = $jira->POST('/issue', undef, {
fields => {
project => { key => 'TIME' },
issuetype => { name => 'Task' },
summary => '20-7-2018 checking field persent or not',
description => 'test',
custom_field => { Epic Link => 'Application Framework'},
},
});
It looks like you're missing some quote marks in your fields->custom_field data structure:
# Create the ticket using post function
my $issue = $jira->POST('/issue', undef, {
fields => {
project => { key => 'TIME' },
issuetype => { name => 'Task' },
summary => '20-7-2018 checking field persent or not',
description => 'test',
custom_field => { 'Epic Link' => 'Application Framework'},
},
});
There's also a typo in summary, but presumably that doesn't matter too much.

cakephp 3: change class input error

I build my form template according the documentation. It seemed everything was fine until I get fields errors. Now I have two problems:
How can I change the class name of the forms fields when they get error?
Solution:
$this->loadHelper('Form', [
'templates' => 'your_template_file',
'errorClass' => 'your-class',
]);
How can I set escape => false in the error-message from cakephp, when the field get error? Because I have icon within that div, such as
<div class="error-message"><i class="fa fa-times"></i> My error</div>
Well, I got part of th solution. To escape HTML I could put $this->Form->error('field', null, ['escape' => false]); in all fields, but it´s a hard manually task. I´d like to keep escape with default of all fields errors. I could edit the FormHelper.php class. However, I think that is not good idea.
My form template is:
'formStart' => '<form {{attrs}} class="form-horizontal" novalidate>',
'inputContainer' => '{{content}}',
'input' => '<input type="{{type}}" name="{{name}}" {{attrs}} class="form-control"/>',
'checkbox' => '<input type="checkbox" value="{{value}}" name="{{name}}" {{attrs}}/>',
'textareaContainerError' => '{{content}}',
'textarea' => '<textarea name="{{name}}" {{attrs}} class="form-control"></textarea>',
'select' => '<select name="{{name}}" {{attrs}} class="form-control">{{content}}</select>',
'button' => '<button {{attrs}} class="btn btn-primary">{{text}}</button>',
'nestingLabel' => '{{input}}',
'formGroup' => '{{input}}',
to the second part of the question: you can extend FormHelper like in code below, so that escape will be set to false by default
// extended FormHelper, this goes in src/View/Helper
namespace App\View\Helper;
use Cake\View\Helper;
class MyFormHelper extends Helper\FormHelper
{
public function error($field, $text = null, array $options = [])
{
if (!isset($options['escape'])) {
$options['escape'] = false;
}
return parent::error($field, $text, $options);
}
}
next create alias for this helper in AppController.php
public $helpers = [
'Form' => ['className' => 'MyForm']
];
this also allows you to add more customization of your own and at any time, you can go back to default implementation of FormHelper, just remove that alias from AppController.php.
For those who wants an 'easy solution' to escape error message on some fields, you cant simply set escape options to false :
<?= $this->Form->input('email', [
"label" => "Email",
"error" => [
"escape" => false
]
]) ?>

How to use PayPal for checkout in rails4

I am trying to add PayPal e-paiement to my RoR application. so I proceed as follow:
My panier.rb:
class Panier < ActiveRecord::Base
belongs_to :user
def paypal_url(return_path)
values = {
:business => 'r.karoui-buyer#loganddrive.com',
:cmd => '_cart',
:upload => 1,
:return => return_path,
:invoice => id
}
line_items.each_with_index do |item, index|
values.merge!({
"amount_#{index+1}" => item.price,
"item_name_#{index+1}" => item.book.title,
"item_number_#{index+1}" => item.id,
"quantity_#{index+1}" => 1
})
end
"#{Rails.application.secrets.paypal_host}/cgi-bin/webscr?" + values.to_query
end
end
my details.html.erb: where i call the PayPal service
<%= #panier.book_id %> | <%= #panier.price %> | <%= link_to 'acheter' , #panier.paypal_url(paniers_path) %>
but I got this error:
undefined local variable or method `line_items' for #
i just follow this railsCast tutorial :
http://railscasts.com/episodes/141-paypal-basics
what should I put in place of line_items.each_with_index do |item, index| if it is here the errors if not please help me to find out where is the problem
Try
def paypal_url(return_path)
values = {
:business => 'r.karoui-buyer#loganddrive.com',
:cmd => '_cart',
:upload => 1,
:return => return_path,
:invoice => id
}
values.merge!({
"amount_#{index+1}" => item.price,
"item_name_#{index+1}" => item.book.title,
"item_number_#{index+1}" => item.id,
"quantity_#{index+1}" => 1
})
"#{Rails.application.secrets.paypal_host}/cgi-bin/webscr?" + values.to_query
end

Ruby on Rails Formtastic Multiple Options in Member_Label

I have a relational model where users have managers that are also users. The below code works great and does exactly what it's suppose to, but it's only displaying the first name of the manager. I'm trying to get this to show both the first name and the last name of the manager.
<%= sf.input :managers, :as => :check_boxes, :member_label => (:firstname) ,:input_html => { :size => 20, :multiple => true}%>
The other field i'm trying to add is the :lastname. I cannot figure out how to get :member_label to take both fields.
I figured it out. By using the Proc.new, I was able to add in both first name and last name.
<%= sf.input :managers, :as => :check_boxes, :member_label => Proc.new { |t| h(t.firstname + " " + t.lastname) } ,:input_html => { :size => 20, :multiple => true}%>