Skip to content

Instantly share code, notes, and snippets.

@ares
ares / gist:d995960966fde3f3f71c
Last active September 7, 2015 10:46
Puppet template example to use Foreman ENC
Available subnets:
===================
<% @foreman_subnets.each do |subnet| %>
<%= subnet['name'] %>:
<%= subnet.to_yaml %>
---------------------
<% end %>
Configured interfaces:
======================
@ares
ares / Preseed networking setup snippet
Last active January 11, 2020 22:54
Preseed networking setup snippet
<% subnet = @host.subnet -%>
<% dhcp = subnet.dhcp_boot_mode? -%>
real=`ip -o link | grep <%= @host.mac -%> | awk '{print $2;}' | sed s/://`
<% if @host.respond_to?(:has_primary_interface) && @host.has_primary_interface? %>
cat << EOF > /etc/network/interfaces
auto lo
iface lo inet loopback
auto $real
@ares
ares / Resume all paused tasks in error states that are resumable
Last active September 7, 2015 10:45
Resume all paused tasks in error states that are resumable
ForemanTasks::Task.where(:state => :paused, :result => :error).all.select(&:resumable?).each {|t| ForemanTasks.dynflow.world.execute(t.execution_plan.id)}
Simple script to convert puppet text output to yaml so it can be easily uploaded to Foreman using node script.
usage:
convert_text_facts_to_yaml.rb /tmp/user.yaml > /var/lib/puppet/yaml/facts/user.yaml
/etc/puppet/node.rb user
def set_interfaces(parser)
# if host has no information in primary interface we try to match it and update it
# instead of creating new interface, suggested primary interface mac and identifier
# is saved to primary interface so we match it in updating code below
if !self.managed? && self.primary_interface.mac.blank? && self.primary_interface.identifier.blank?
identifier, values = parser.suggested_primary_interface(self)
self.primary_interface.mac = Net::Validations.normalize_mac(values[:macaddress])
self.primary_interface.identifier = identifier
self.primary_interface.save!
end
@ares
ares / .rubocop.yml
Created September 21, 2015 13:00
Default .rubocop.yml
AllCops:
Include:
- "**/*.gemspec"
- "**/Rakefile"
- "**/Gemfile"
- "**/Vagrantfile"
- "**/config.ru"
Exclude:
- "vendor/**/*"
- "db/schema.rb"
@ares
ares / gist:4bf685dd6f29c0f5709b
Created November 30, 2015 11:53
openstack patch
diff --git a/app/models/compute_resources/foreman/model/openstack.rb b/app/models/compute_resources/foreman/model/openstack.rb
index d273cfb..fa998b9 100644
--- a/app/models/compute_resources/foreman/model/openstack.rb
+++ b/app/models/compute_resources/foreman/model/openstack.rb
@@ -77,6 +77,7 @@ module Foreman::Model
boot_from_volume(args) if Foreman::Cast.to_bool(args[:boot_from_volume])
network = args.delete(:network)
# fix internal network format for fog.
+ args[:nics] ||= []
args[:nics].delete_if(&:blank?)
$ rubocop lib/dynflow
...
121 files inspected, 1346 offenses detected
# this includes stuff like `=->`, `on Work::Step.(step: ~any)`, `define =-> _ do`
$ rubocop lib/dynflow | grep lamda | wc -l
22
# see yourself by
$ rubocop lib/dynflow | grep -i lambda -C 3
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
gem "rails", github: "rails/rails"
// original and I'd say very clear for reader
if (a) {
return 1
} else {
return 2
}
// vs accepted by linter but duplicates condition keeping it clear when 2 is returned