Last active
January 26, 2016 13:06
-
-
Save logankimmel/d6f02aa80b1b47b57f70 to your computer and use it in GitHub Desktop.
Invalid Relationship when using require param in class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/puppetlabs/puppet/node_data/agent-haproxy.yaml | |
--- | |
agent-haproxy: | |
classes: | |
linux_postinstall: | |
install_packages: tree | |
upload_recursive: 'false' | |
haproxy: | |
require: Class[linux_postinstall] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
These run fine without the without the require param. Also, I am able to run this in a manifest with: | |
#/etc/puppetlabs/puppet/manifests/site.pp | |
node default { | |
class { "linux_postinstall": | |
install_packages => "httpd", | |
upload_recursive => "false" | |
} | |
class { "haproxy" : | |
require => Class["linux_postinstall"] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@haproxy ~]# puppet agent -t | |
Info: Retrieving plugin | |
Info: Loading facts in /var/lib/puppet/lib/facter/staging_http_get.rb | |
Info: Loading facts in /var/lib/puppet/lib/facter/ip6tables_version.rb | |
Info: Loading facts in /var/lib/puppet/lib/facter/default_provider.rb | |
Info: Loading facts in /var/lib/puppet/lib/facter/os_maj_version.rb | |
Info: Loading facts in /var/lib/puppet/lib/facter/facter_dot_d.rb | |
Info: Loading facts in /var/lib/puppet/lib/facter/hyperv_install_status.rb | |
Info: Loading facts in /var/lib/puppet/lib/facter/rabbitmq_erlang_cookie.rb | |
Info: Loading facts in /var/lib/puppet/lib/facter/root_home.rb | |
Info: Loading facts in /var/lib/puppet/lib/facter/puppet_install_dir.rb | |
Info: Loading facts in /var/lib/puppet/lib/facter/puppet_vardir.rb | |
Info: Loading facts in /var/lib/puppet/lib/facter/pe_version.rb | |
Info: Loading facts in /var/lib/puppet/lib/facter/initiator_ports.rb | |
Info: Loading facts in /var/lib/puppet/lib/facter/iptables_persistent_version.rb | |
Info: Loading facts in /var/lib/puppet/lib/facter/haproxy_version.rb | |
Info: Loading facts in /var/lib/puppet/lib/facter/iptables_version.rb | |
Info: Loading facts in /var/lib/puppet/lib/facter/jboss_home.rb | |
Info: Loading facts in /var/lib/puppet/lib/facter/concat_basedir.rb | |
Info: Loading facts in /var/lib/puppet/lib/facter/win_common_desktop_directory.rb | |
Info: Loading facts in /var/lib/puppet/lib/facter/gemhome.rb | |
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Invalid relationship: Class[Haproxy] { require => Class[linux_postinstall] }, because Class[linux_postinstall] doesn't seem to be in the catalog | |
Warning: Not using cache on failed catalog | |
Error: Could not retrieve catalog; skipping run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is our node_terminus that we are using | |
require 'puppet/indirector/yaml' | |
require 'puppet/node' | |
require 'yaml' | |
class Puppet::Node::YamlDevice < Puppet::Indirector::Yaml | |
desc <<-EOT | |
This ENC can be used to specify what resources should be | |
configured for a specific node. It can also specify parameters | |
and classes like a typical ENC. | |
It pulls this classification information from the file: | |
$confdir/node_data/<certname>.yaml | |
The default location of $confdir is /etc/puppet/ for root | |
or ~/.puppet for a system user. | |
The data for this file is of the form: | |
certname1: | |
resources: | |
user: | |
dan: | |
ensure: present | |
certname2: | |
resources: | |
user: | |
bob: | |
ensure: present | |
EOT | |
def find(request) | |
node_name = request.key | |
node = Puppet::Node.new(request.key) | |
yaml_file = self.class.device_file(node.name) | |
if File.exists?(yaml_file) | |
device_hash = YAML.load_file(yaml_file) | |
unless device_hash | |
raise(Puppet::Error, "Yaml file #{yaml_file} was empty") | |
end | |
if device_info = device_hash[node_name] | |
# TODO for now, I will not allow params or classes to be set here | |
# but ,we will probably need it later | |
node.parameters = (device_info['parameters'] || {}) | |
node.classes = (device_info['classes'] || {}) | |
if resources = device_info['resources'] | |
if node.classes | |
unless node.classes.class == Hash | |
# | |
# we have to pass in classes as a Hash b/c we have to set the resource | |
# parameter in our class. I will fail if classes were specified as an array | |
# b/c otherwise, I have to convert it into a hash which potentially effects | |
# things if the user was expecting an array | |
# | |
raise(Puppet::Error, 'Cannot add resources if an array of classes was passed') | |
end | |
end | |
node.classes.merge!( | |
'asm::resource_wrapper' => {'resources' => resources} | |
) | |
end | |
else | |
Puppet.warning("Did not find node: #{node_name} in #{yaml_file}") | |
end | |
else | |
Puppet.warning("Yaml file #{yaml_file} does not exist") | |
end | |
node.fact_merge | |
node | |
end | |
def self.device_file(certname) | |
File.expand_path(File.join(Puppet[:confdir], 'node_data', "#{certname}.yaml")) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try changing your yaml this way:
Yeah this works for me, it appears when using the standard yaml ENC setting classes doesnt really work too hot, but as we have the
asm::resource_wrapper
thing i use that here via theresources
key to inject this data into a normal manifest where it works fine