Quantcast
Channel: Ask Puppet: Puppet DevOps Q&A Community - RSS feed
Viewing all articles
Browse latest Browse all 6104

Having difficulties with my defined type and making it robust

$
0
0
***GOAL : I want to avoid duplicating my code/lines in this hieradata. How can I rethink my approach to this?*** The component module freshserver::html creates an HTML file with links to launch an application. The link names are based on the company id (e.g. HEH, or BEAT). One company may have many subcompanies, and so multiple links. Each subcompany needs its own html file too, so if HEH has subcompanies WEB, BEAT, HEHB, UDAS we need 5 html files which are all alike, each html file having 5 sets of links. Hiera is useful for this, because every host/node has DIFFERENT company names on it **profiles::html** class profiles::html ( $clients = hiera('profiles::html::clients'), ){ Freshserver::Html { directory => '/u2/prod1/conf/GUI/web', } create_resources(freshserver::html, $clients) } **hieradata** profiles::html::clients: kelloggs: ensure: file hide_links: false notice: 'this is an example of a so-called normal 1:1 company:html file' web: hide_links: true notice: 'this is an example of a many-to-many, with 1 html file per company, and each html files having all company links' companies: - heh - hehb - web - udas - beat udas: hide_links: true warn: 'Not Yet Live' notice: 'notice' companies: - heh - hehb - web - udas - beat hehb: hide_links: true warn: 'Not Yet Live' notice: 'notice' companies: - heh - hehb - web - udas - beat heh: hide_links: true warn: 'Not Yet Live' notice: 'notice' companies: - heh - hehb - web - udas - beat beat: hide_links: true warn: 'Not Yet Live' notice: 'notice' companies: - heh - hehb - web - udas - beat **define freshserver::html** # configures .html files in $GW on fresh server define freshserver::html ( $directory, $companies = $title, $ensure = file, $hide_links = false, $notice = undef, $symlink_path = undef, $warn = undef, ){ validate_absolute_path($directory) $companies_real = any2array($companies) $full_path = "${directory}/${title}.html" file { $title: ensure => $ensure, owner => 'root', group => 'root', mode => '0644', path => $full_path, content => template( 'freshserver/html/client.html.erb'), } if $symlink_path != undef { exec { "${title}-symlink": user => 'root', path => '/usr/bin:/bin', command => "echo test", require => File[$title], } } } **client.html.erb** <% if @hide_links != true -%><% @companies_real.each do |company| -%><% end -%><% @companies_real.each do |company| -%><% end -%>
In Office (Internal)
<%= company.upcase %>Fresh
<%= company.upcase %>Large
<%= company.upcase %>XLarge
 
At Home (External)
<%= company.upcase %>Fresh
<%= company.upcase %>Large
<%= company.upcase %>XLarge
<% end -%>

Viewing all articles
Browse latest Browse all 6104

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>