Chef template issues, stale variables - ruby

I am seeing a weird issue when running my chef cookbook, it almost looks like there is some stale variable names being used in between runs even after modifying the json env file. Please see below for more details. I have pasted excerpts from my template, and environment files. Also showed the desired output and the current weird output that I am seeing. It may be something with my ruby loops (excuse my ruby, noob here) but I have checked it multiple times and don't see any issue with the construct.
Any help appreciated... have been messing with this for almost 24 hours now, in the interest of being productive I am reaching out to others.
This is my first post here and I am not allowed to post more than 2 links in the content. I had to remove the 'http' and 'https' from my sample output and rename my domain names to bypass.
Template:
gatewaymappings: |
{
<% #gatewaymappings.each_with_index do |mapping, index| %>
"<%= mapping.incomingFQDN %>" : "<%= mapping.upstreamProtocol %>://<%= mapping.upstreamFQDN %>
<% if (mapping.upstreamPort.length > 0) %>
:<%= mapping.upstreamPort %>"
<% end %>
<% if (index+1 != #gatewaymappings.count) %>
,
<% end %>
<% end %>
}
Chef template variables:
:gatewaymappings => node[app_name]['gatewaymappings']
Sample JSON:
"gatewaymappings": [
{
"incomingFQDN": "host1",
"upstreamProtocol": "http",
"upstreamFQDN": "upstream1",
"upstreamPort": "8000"
},
{
"incomingFQDN": "host2",
"upstreamProtocol": "https",
"upstreamFQDN": "upstream2",
"upstreamPort": "8001"
}
]
Desired output: (inside yml file)
gatewaymappings: |
{
"host1" : "upstream1:8000",
"host2" : "upstream2:8001"
}
Current output:
(The first element is from a previous sample env run which doesnt even exist in my current sample json, I tried clearing cache etc, but it still keep showing up)
gatewaymappings: |
{
"localhost" : "upstream",
"host1" : "upstream1:8000",
"host2" : "upstream2:8001",
"host1" : "upstream1:8000",
"host2" : "upstream2:8001"
}

I think I was able to fix this. It was due to my node configs being corrupted. I should have mentioned I was using chef-zero. It turns out the node config is saved back to a json file inside nodes directory even for chef-zero and so no matter how many times I deleted my local-mode caches inside ~/.chef and my installation directories, the stale values kept coming back. Thanks to gitter chat room, someone gave me a gentle reminder to check the node's configs. That took care of the issue and I am seeing my expected output now. Thanks!

Related

How do you secure deployd server dashboard

How do you secure a deployed server dashboard? ideally with authentication.
From the deployd docs:
To set up the dashboard on your server, type dpd keygen on your
server's command line to create a remote access key. Type dpd showkey
to get the key; you should store this somewhere secure.
You can then go to the /dashboard route on the server and type in that
key to gain access.
See here: http://docs.deployd.com/docs/server/your-server.md#s-Dashboard%20Access-2728
The documentation at docs.deployed.com has more detail than the github documentation by the way.
Hope this helps.
Change directory (cd) to your Deployd project's root.
Run dpd keygen.
Run dpd showkey and save the key somewhere.
Restart dpd with --environment production option, otherwise it won't
require the key when accessing /dashboard.
Go to your API's /dashboard and paste the key in the dialog.
On top of auth, I'm also limiting it to data-entry users only.
It's not perfect (i also want to remove the delete-resource button), but here goes:
env.sh
# this makes deployd require key for /dashboard
export NODE_ENV=production
.production.patch (disables events- config-editors)
--- node_modules/deployd/lib/resources/dashboard/index.ejs 2016-11-21 16:10:05.406025488 +0100
+++ node_modules/deployd/lib/resources/dashboard/index.ejs.new 2016-11-21 16:09:51.009794524 +0100
## -65,7 +65,7 ##
<span class="caret"></span>
<% if (type && type.dashboardPages) { %>
<ul class="nav pages type-icons <%= isCurrent ? '' : 'hide' %>">
- <% type.dashboardPages.forEach(function(p) { %>
+ <% type.dashboardPages.forEach(function(p) { if( p.match(/Config|Events|Properties/) != null ) return %>
<li <%- isCurrent && (Context.page || '').toLowerCase() === p.toLowerCase() ? 'class=active' : ''%> ><i class="icon-white icon-custom <%= p.toLowerCase() %>"></i> <%= p %></li>
<% }); %>
</ul>
.git/hooks/post-merge (automatically call upon git pull)
#!/bin/bash
# disallow users from changing resource schema's, event-code and config.json
patch -Np0 < .production.patch
[[ ! -n $NO_NPM ]] && npm update

RubyMine RoR I18n config/locals/en.yml syntax error "file should have single root"

I don't know if this is just a goof syntax error, or if this is something I should legitimately be concerned about. I've searched online for this error and have found very little concerning it. So my guess is that this is either something so "no duh" that hardly anybody ends up with this error, or that it's so obscure that - again - hardly anybody ends up with it. Nonetheless, here we go:
This is what I'm using:
Ruby 2.1.1p76
Rails 4.0.5
SafeYAML 1.0.3
RubyMine 6.3
[should you need anymore information, please ask]
The error I'm getting exactly is: "Rails i18n locale file should have single root"
Here is a shortened version of my en.yml file (I'll include what I believe to be the problem areas)
<%
object_names = **{**
:administrator => 'Administrator',
:activity_log => 'Site Activity',
:answer => 'Answer',
:approval => 'Approval',
:user => 'Member',
:video => 'Video',
:vote => 'Like'
}
section_names = **{**
:approvals => 'Items Awaiting Review',
:advertisements => 'Advertisements',
:ad_placements => 'Ad Placements',
:awarded_badges => 'Badges',
:badges => 'Badges',
:videos => 'Videos'
}
anonymous = 'Anonymous**'
%>
en:
homepage:
mine: "My %{site_name}"
site_name: "%{site_name}"
site_condition_name: "%{site_condition_name}"
titles:
main: "%{site_name}"
delimiters:
minor:** ' **-** '
major: ' | '
scopes:
popular: Popular
newest: Newest
active: Active
my_feed: My Friends
my_activity: What I've Done
tracked_items: "Only <%= object_names[:tracked_item].pluralize %>"
everyone: Everyone
user: "By %{name}"
view: "By %{view}"
sent: "Sent <%= object_names[:message].pluralize %>"
page: "Page %{page}"
letter: "Starting With %{letter}"
query: "%{query}"
category: "%{category}"
**meta_description:**
main: "%{site_name} is a social network that connects people"
footer:
about: "About %{site_name}"
about_alliance_health: About Alliance Health
community_advocates: Community Advocates
terms_of_use: Terms of Use
oh - wow. Ok, it looks like bold isn't going to work inside the code markers. But I'm sure you guys can decipher what's going on. Basically anything that's bold (or delimited with a double asterisk '**') is where the IDE is marking the code with this particular error. So, as you can see, it seems rather chaotic and nonsensical. But I often find that when such things happen, it's usually one tiny little character somewhere that's throwing everything else off.
Now, I'm no YAML expert - in fact, I hardly even know the stuff (which is something I'm planning on changing here in the near future) so this may be something along the "no duh" lines. However, it is interesting to note that the bulk of the error-marked syntax starts with the last single-quote of the word: " 'anonymous' ", all the way down to: " minor: ", skipping the first following single quote, and picking up again on the hyphen, afterwhich there are no more errors for the rest of the nearly 5,500 lines of this file.
Thanks to anybody who helps out. I've been dorking around with this for far too long, and with very little online information on this particular issue. So any help is much appreciated :)
Thanks!
So - I'm not sure this will ever help anybody ... but in the case that it may, this is how I re-engineered the script to avoid the errors. I simply removed the usual delimiters that were causing the parsing confusion. And #mu is too short, you were correct. This is an erb.yml file, though I'm not sure why the original creator left the dual extension off. At any rate - thank you to everybody who offered any suggestions and ideas :)
<%
object_names = Hash.new
object_names[:administrator] = %q<Administrator>
object_names[:activity_log] = %q<Site Activity>
object_names[:answer] = %q<Answer>
object_names[:approval] = %q<Approval>
object_names[:user] = %q<Member>
object_names[:video] = %q<Video>
object_names[:vote] = %q<Like>
section_names = Hash.new
section_names[:approvals] = %q<Items Awaiting Review>
section_names[:advertisements] = %q<Advertisements>
section_names[:ad_placements] = %q<Ad Placements>
section_names[:awarded_badges] = %q<Badges>
section_names[:badges] = %q<Badges>
section_names[:videos] = %q<Videos>
%>
en:
homepage:
mine: "My %{site_name}"
site_name: "%{site_name}"
site_condition_name: "%{site_condition_name}"
titles:
main: "%{site_name}"
delimiters:
minor: ' - '
major: ' | '
scopes:
popular: Popular
newest: Newest
active: Active
my_feed: My Friends
my_activity: What I've Done
tracked_items: "Only <%= object_names[:tracked_item].pluralize %>"
everyone: Everyone
user: "By %{name}"
view: "By %{view}"
sent: "Sent <%= object_names[:message].pluralize %>"
page: "Page %{page}"
letter: "Starting With %{letter}"
query: "%{query}"
category: "%{category}"
meta_description:
main: "%{site_name} is a social network that connects people"
footer:
about: "About %{site_name}"
about_alliance_health: About Alliance Health
community_advocates: Community Advocates
terms_of_use: Terms of Use

Chef Attribute file

I'm trying to pass attributes to my recipe at run-time of chef client.
following is my default.rb attribute file:
if node['os'] == 'windows'
if node.attribute?('temp')
default['param']['name'] = node['temp']['tempname']
else node.attribute?('base')
default['param']['name'] = node['base']['nodename']
end
end
I first ran the chef-client with only the base attribute defined in the node.json file. My node.json looked like :
{
"base": {
"nodename": "John"
}
}
Chef-client run was successfull and the attribute was set accordingly. i.e.
default['param']['name'] = "John"
Than I ran chef-client with both base and temp attribute defined in the node.json.
And here is my node.json file :
{
"base": {
"nodename": "John"
},
"temp": {
"tempname": "Mike"
}
}
Chef-client again ran successfully and the attribute was set accordingly.
default['param']['name'] = "Mike"
The problem is when I run the chef-client again and pass only base attribute from the node.json file(see below for the file), the code doesn't seem to enter the else loop. It just runs the `if' loop with old value for temp attribute(Mike).
{
"base": {
"nodename": "John-2"
}
}
Any ideas to where I'm going wrong.
The second time you ran chef-client, it saved the node[:temp][:nodename] attribute to the node object on the Chef server.
When you ran chef-client again, it loaded the node's attributes back from the server before reaching the attributes/default.rb file, so node[:temp][:nodename] was set when it reached the conditions.
I'm not sure what you're trying to achieve, but it would probably be best to explicitly tell which attribute you want to use through another attribute (and maybe assume a default for it), such as:
default[:name_attribute] = 'temp'
then,
if node['os'] == 'windows'
if node['name_attribute'] == 'temp'
default['param']['name'] = node['temp']['tempname']
else
default['param']['name'] = node['base']['nodename']
end
end

Pass dynamic content to template in Middleman

I'm building a static site using Middleman that has a portfolio section of all the client's recent projects.
The portfolio section will display project thumbnail images in a 3 X 3 gallery fashion and, when clicked on, will open their co-responding html page inside a lightbox.
The layout for the pages inside the light box is the same so rather than markup each individual page, I thought there would be a way for Middleman handling the content served from a yaml data file (projects.yml) using [a link.
Here's what I've got in my config.rb file
###
# Page options, layouts, aliases and proxies
###
# A path which all have the same layout
with_layout :popup do
page "/projects/*"
end
# Proxy (fake) files
# page "/this-page-has-no-template.html", :proxy => "/template-file.html" do
# #which_fake_page = "Rendering a fake page with a variable"
# end
data.projects.details.each do |pd|
proxy "/projects/#{pd[:client_name]}.html", "/projects/template.html", locals: { project: pd }, ignore: true
end
Ok so after some digging I came across the two posts below which helped me under stand how dynamic pages work in middleman. (Unfortunately there's not a lot of doco and the Middleman example for Dynamic pages is really basic)
http://benfrain.com/understanding-middleman-the-static-site-generator-for-faster-prototyping/
http://forum.middlemanapp.com/discussion/134/best-way-to-use-yaml-same-html-but-parameter-driven-data-fixed/p1
My solution...
data/projects.yml (contains project details)
details:
- client: "Company X"
title: "Company X Event"
video_url: ""
logo:
- "logo_companyx.gif"
image_path: "/img/projects/companyx"
total_images: 10
content: "<p>Blah blah blah</p>"
responsibilities:
"<li>Something</li>
<li>Some task</li>"
config.rb:
data.projects.details.each do |pd|
proxy "/projects/#{pd[:client]}.html", "/projects/template.html", :layout => false, :locals => { :project => pd }, :ignore => true
end
The trick with the snippet above is passing the entire project data object to the template via a proxy using locals and setting the layout to false so it doesn't inherit the default site layout (as I - or the client rather - want to display these in a lightbox popup)
The last step in the process was to create /projects/template.html.erb (in the source folder), declaring the following at the top of the template
<% p = locals[:project] %>
This allowed me to output each property of the p object within template.html.erb.
eg:
<%= p[:title] %>
I hope this helps someone as it took me a few days of playing around and LOTS of searching online for example or hints.

rails routes using the do part for iteration

I have a very basic question, am looking at some rails code similar to following but not able to interpret it, what are the REST urls and corresponding actions inferred from this? Can someone please help understand as I did not find any examples of similar routes.
map.resources :myresources do |item|
item.resources :v, :controller => 'my_controller' do |v|
v.resource :abc
end
end
Thanks in advance!!
This is actually the old routing style.
Now you can just write the code this way:
resources :myresources do
resources :v, :controller => "my_controller" do
resource :abc
end
end
With this code you will get these routes:
myresource_v_abc POST /myresources/:myresource_id/v/:v_id/abc(.:format) abcs#create
new_myresource_v_abc GET /myresources/:myresource_id/v/:v_id/abc/new(.:format) abcs#new
edit_myresource_v_abc GET /myresources/:myresource_id/v/:v_id/abc/edit(.:format) abcs#edit
GET /myresources/:myresource_id/v/:v_id/abc(.:format) abcs#show
PUT /myresources/:myresource_id/v/:v_id/abc(.:format) abcs#update
DELETE /myresources/:myresource_id/v/:v_id/abc(.:format) abcs#destroy
myresource_v_index GET /myresources/:myresource_id/v(.:format) my_controller#index
POST /myresources/:myresource_id/v(.:format) my_controller#create
new_myresource_v GET /myresources/:myresource_id/v/new(.:format) my_controller#new
edit_myresource_v GET /myresources/:myresource_id/v/:id/edit(.:format) my_controller#edit
myresource_v GET /myresources/:myresource_id/v/:id(.:format) my_controller#show
PUT /myresources/:myresource_id/v/:id(.:format) my_controller#update
DELETE /myresources/:myresource_id/v/:id(.:format) my_controller#destroy
myresources GET /myresources(.:format) myresources#index
POST /myresources(.:format) myresources#create
new_myresource GET /myresources/new(.:format) myresources#new
edit_myresource GET /myresources/:id/edit(.:format) myresources#edit
myresource GET /myresources/:id(.:format) myresources#show
PUT /myresources/:id(.:format) myresources#update
DELETE /myresources/:id(.:format) myresources#destroy

Resources