Foreman - replacing repo with local mirrors - ruby

We use foreman (v1.14.1) for provisioning and we have a working CentOS 7 installation media for the base OS.
When installing it does install the default repos in /etc/yum.repos.d with online mirrors but I want to replace this with our local mirrors.
I ran accross this workflow (from 2012)
It uses the following snippet to iterate over all the media of the current host os and set write out a repo definition.
<% #host.os.media.each do |media| -%>
[<%= media.name.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '') %>]
name=<%= media.name %>
baseurl=<%= #host.os.medium_uri #host, media.path %>
enabled=1
gpgcheck=0
<% end -%>
I have set several Installation media for this OS, each one of them having a specific repo URI (Base, Updates, Plus, Extras...).
The snippet is called in the %post install section of the kickstart but when I want to build the host I get the following error:
Failure parsing Kickstart default: The snippet 'FF_repos' threw an error:
undefined method 'media' for Operatingsystem::Jail (Redhat).
I understand that "#host.os.media.each" is not correct for iterating over the different medias, but how could I do it ?
Any help appreciated :)

Couldn't get this to work so I have simply changed my snippet "FF_repos" to directly bake the repos definition into corresponding repo files on disk.
I added the following in the %post section then to remove default repos and leave our.
rm -f /etc/yum.repos.d/*
<%= snippet("FF_repos") %>

Related

Check if a file exists with puppet template

I try to check if a file exists on client who run puppet agent.
On my puppet master, I have a template.erb like this :
<% if File.exists?('/usr/bin/lwp-request') %>SCRIPTWHITELIST="/usr/bin/lwp-request"<% end %>
This little code in my template is needed to my rkhunter module.
The result is always false, however the file exists.
If I add the file on the puppet master, the result is true. So the ruby code seems to be executed on the master.
How can I check on my template if a file exists on client ?
Tested on puppet 2.7.5 and 2.8.1.
Thanks
The only information you have about the node when compiling manifests and templates are Facts that are sent by the node when requesting a catalog.
If you need additional information from the node, then you need to add a Custom Fact that retrieves the information you need (like whether or not a file exists). You can then use the custom fact inside of templates.
Within a Puppet module create a custom fact lib/facter/lwp.rb:
Facter.add(:lwp_request_exists) do
setcode do
File.exists?('/usr/bin/lwp-request')
end
end
then within erb template use something like:
<% if $::lwp_request_exists -%>
some code...
<% end -%>

File traverse and read failure in Vagrant / Puppet setup

I have a Vagrant / Puppet set up in which I am attempting to generate a bunch of configuration files and then concatenate them into a master file.
The individual files are generated and written to a conf directory and the last action is to create the master file which uses an erb template to read the files in the conf directory.
<% files = Dir["/etc/sysconfig/iptables/conf/*.conf"] -%>
<% files.each do |name| -%>
<% file = File.open(name) -%>
<% contents = file.read -%>
<%= contents %>
<% end -%>
When I run "vagrant up", everything appears to run correctly but the master configuration file is empty. I have checked the timestamps on the conf directory and the master configuration file and they are correct to (The master config file is created after all the individual config files).
If I ssh into vagrant and run "puppet apply" manually, the master config file is created as expected. I have tried using a bash script instead of the erb method but encountered the same problems.
Does anyone have any ideas what might cause this?
Puppet expands templates at manifest compile time. The content you are trying to catenate is only available at catalog application time.
Have you looked at the concat module? It will likely make short work of your task.

Vagrant Puppet Class Not Found Error

I am getting the message:
Puppet::Parser::AST::Resource failed with error ArgumentError: Could not find declared class git at /tmp/vagrant-puppet-1/manifests/site.pp:15 on node vagrant-ubuntu-precise-64.wp.comcast.net
Probably the best idea is to see this in action. I have created a GitHub repo of the exact manifest I am using. It is here:
https://github.com/jamorat/puppet-example
The manifests and git module are there. If you have Vagrant, this can be vagrant up and you will see the error for yourself. Would be cool to either receive an answer here and/or also as a commit (for which credit would still be given here for answer.)
Thank you so much!
You need to configure vagrant with the puppet module path. On a side note, you would also usually keep the manifest and module folder in the same folder, instead of modules inside manifests.
This:
class{ git:
svn => 'installed',
gui => 'installed',
}
is telling puppet to create a resource based on the class named git that has 2 parameters: svn and gui. Such a class declaration doesn't exist anywhere in what you've posted. If it were, it would look something like:
class git ($svn, $gui) {
package {'svn':
ensure => $svn,
}
# Whatever 'gui' is, making package b/c use of "installed"
package {'gui':
ensure => $gui,
}
}
Alternative is to declare a class and include it using the "include" directive.
Recommend a good reading of Language: Classes

Unable to use application_ruby cookbook with Chef 11.8.0, Cannot find a resource for bundle_options

I have been attempting to setup a chef recipe which installs ruby using RVM and then uses the application_ruby cookbook to configure the application, however I keep running into the error
NameError: Cannot find a resource for bundle_options on ubuntu version 12.04
I am using the following code
application "application setup" do
owner "ubuntu"
group "ubuntu"
repository "https://github.com/me/myapplication.git" // Real address removed
path rails_app_path
revision "master"
rails do
bundler true
precompile_assets true
bundler_deployment true
end
end
I noticed that the bundle_options was recently added, https://github.com/opscode-cookbooks/application_ruby/commit/e7719170a661a957796e8e5d58ba8f4ecd937487 however I am unable to track down if this is causing the issue. I have included
depends "application"
depends "application_ruby"
in my metadata.rb and made sure all my dependencies are installed so I am unsure what I am doing wrong at this point.
According to documentation bundle_options is an attribute of the rails resource, not a resource itself.
The only correct way of using it is INSIDE the "rails" block, so you got the message because you either used it as :
an attribute of the application resource (but outside of the "rails" block)
standalone resource (outside of any resource).
Message you mentioned is being displayed when nonexistent resource is being referenced. e.g. if you had tried to execute following code on your system:
nonexistent_resource "failure gonna happen" do
some_attribute "whatever_value"
end
you would've got a message
NameError: Cannot find a resource for nonexistent_resource on Ubuntu version 12.04
I ran into this problem today as well. It appears the problem is that commit e771917 forgot to add the necessary getter for the bundle_option. Someone filed a PR to fix it (https://github.com/poise/application_ruby/pull/44), but it has not yet been merged. I can confirm that when I made that change locally, this error went away. The forked branch in the PR is located at https://github.com/mauriciosilva/application_ruby/tree/bundle_options_fix.

How to stop TDDium from running script/cucumber features automatically

I am using TDDium to run my tests continuously.
Every time I push something it runs using my tddium.yml configuration file:
:tddium:
:timeout: 90
:postgresql: false
:test_pattern:
- spec/**_spec.rb
:mysql:
:adapter: mysql2
:config:
:adapter: mysql2
:database: <%= ENV['TDDIUM_DB_NAME'] %>
:username: <%= ENV['TDDIUM_DB_USER'] %>
:password: <%= ENV['TDDIUM_DB_PASSWORD'] %>
:database: <%= ENV['TDDIUM_DB_NAME'] %>
As you can see, I'm specifying :test_pattern:.
Even though I have a set of .feature files in my features directory, I don't want it to run them automatically.
How do I stop TDDium from doing this?
I thought that by specifying :test_pattern: and not including the .feature pattern it'd skip them.
I've tried running tddium suite --edit and this is what happened:
bonsai-2 project$ tddium suite --edit
... Detected ruby ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin11.4.2]
... Detected bundle Bundler version 1.3.5
... Detected gem 1.8.24
... Configured test pattern from tddium.yml:
- spec/**_spec.rb
>>> To change the pattern:
1. Edit tddium.yml
2. Run `tddium suite --edit` again.
>>> To set up Hosted CI, enter a git URL to pull from.
You can also set a git URL to push to after tests pass.
>>> Set both pull and push URLs to 'disable' to disable hosted CI completely.
Enter git URL to pull from (default 'ssh://git#github.com/etagwerker/project.git') or enter 'disable':
Enter git URL to push to (default '') or enter 'disable': disable
Custom Campfire room for this suite (current: '') or enter 'disable': disable
Custom HipChat room for this suite (current: '') or enter 'disable': At Work
Updated suite successfully.
Any other ideas would be helpful.
Thanks!
I'd suggest disabling Tddium’s automatic test mapping (i.e. set :test_pattern to none)
:tddium:
:test_pattern: 'none'
Then you can manually invoke the tests through the :tests configuration.
If you have never run the test suite for your current branch, Tddium will simply pick up the test pattern and use it. If you have already configured the suite for the current branch, the simplest solution is to run tddium suite --edit.

Resources