diff --git a/.gitignore b/.gitignore index daedd39..617baa4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .tox .build *.pyc +.idea diff --git a/deployment_scripts/rabbitmq_hiera_override.pp b/deployment_scripts/rabbitmq_hiera_override.pp index a353d27..9cf8b19 100644 --- a/deployment_scripts/rabbitmq_hiera_override.pp +++ b/deployment_scripts/rabbitmq_hiera_override.pp @@ -1,21 +1,26 @@ notice('MODULAR: detach-rabbitmq/rabbitmq_hiera_override.pp') -$detach_rabbitmq_plugin = hiera('detach-rabbitmq', undef) -$hiera_dir = '/etc/hiera/override' $plugin_name = 'detach-rabbitmq' -$plugin_yaml = "${plugin_name}.yaml" +$detach_rabbitmq_plugin = hiera($plugin_name, undef) if ($detach_rabbitmq_plugin) { + $hiera_plugins_dir = '/etc/hiera/plugins' + $plugin_yaml = "${hiera_plugins_dir}/${plugin_name}.yaml" $network_metadata = hiera_hash('network_metadata') $rabbitmq_roles = [ 'standalone-rabbitmq' ] $rabbit_nodes = get_nodes_hash_by_roles($network_metadata, $rabbitmq_roles) -#lint:ignore:80chars - $rabbit_address_map = get_node_to_ipaddr_map_by_network_role($rabbit_nodes, 'mgmt/messaging') -#lint:endignore - $amqp_port = hiera('amqp_port', '5673') + + $rabbit_address_map = get_node_to_ipaddr_map_by_network_role( + $rabbit_nodes, + 'mgmt/messaging' + ) + $rabbit_nodes_ips = values($rabbit_address_map) $rabbit_nodes_names = keys($rabbit_address_map) + $amqp_hosts = $rabbit_nodes_ips + $amqp_port = hiera('amqp_port', '5673') + case hiera_array('roles', 'none') { /rabbitmq/: { $rabbit_enabled = true @@ -29,55 +34,30 @@ if ($detach_rabbitmq_plugin) { } } - $amqp_nodes = $rabbit_nodes_ips - $amqp_hosts = inline_template("<%= @amqp_nodes.map {|x| x + ':' + @amqp_port}.join ',' %>") - - $calculated_content = inline_template(' -amqp_hosts: <%= @amqp_hosts %> -rabbit: - enabled: <%= @rabbit_enabled %> -<% if @corosync_nodes -%> -<% require "yaml" -%> -corosync_nodes: -<%= YAML.dump(@corosync_nodes).sub(/--- *$/,"") %> -<% end -%> -<% if @corosync_roles -%> -corosync_roles: -<% -@corosync_roles.each do |crole| -%> - <%= crole %> -<% end -%> -<% end -%> -deploy_vrouter: <%= @deploy_vrouter %> - ') - -################### - file {'/etc/hiera/override': - ensure => directory, - } -> - file { "${hiera_dir}/${plugin_yaml}": - ensure => file, - content => "${calculated_content}\n", - } - - package {'ruby-deep-merge': - ensure => 'installed', - } - - # hiera file changes between 7.0 and 8.0 so we need to handle the override the - # different yaml formats via these exec hacks. It should be noted that the - # fuel hiera task will wipe out these this update to the hiera.yaml - exec { "${plugin_name}_hiera_override_7.0": - command => "sed -i '/ - override\\/plugins/a\\ - override\\/${plugin_name}' /etc/hiera.yaml", - path => '/bin:/usr/bin', - unless => "grep -q '^ - override/${plugin_name}' /etc/hiera.yaml", - onlyif => 'grep -q "^ - override/plugins" /etc/hiera.yaml' - } - - exec { "${plugin_name}_hiera_override_8.0": - command => "sed -i '/ - override\\/plugins/a\\ - override\\/${plugin_name}' /etc/hiera.yaml", - path => '/bin:/usr/bin', - unless => "grep -q '^ - override/${plugin_name}' /etc/hiera.yaml", - onlyif => 'grep -q "^ - override/plugins" /etc/hiera.yaml' - } + $calculated_content = inline_template('<% +require "yaml" +amqp_hosts = @amqp_hosts.map {|x| x + ":" + @amqp_port}.join(",") +data = { + "amqp_hosts" => amqp_hosts, + "rabbit" => { + "enabled" => @rabbit_enabled, + }, + "deploy_vrouter" => @deploy_vrouter, +} +data["corosync_nodes"] = @corosync_nodes if @corosync_nodes +data["corosync_roles"] = @corosync_roles if @corosync_roles +-%> +<%= YAML.dump(data) %>') + + file { 'hiera_plugins' : + ensure => 'directory', + path => $hiera_plugins_dir, + } + + file { 'plugin_yaml' : + ensure => 'present', + path => $plugin_yaml, + content => $calculated_content, + } + } diff --git a/tests/template.pp b/tests/template.pp new file mode 100644 index 0000000..65a6de3 --- /dev/null +++ b/tests/template.pp @@ -0,0 +1,23 @@ +$amqp_hosts = [ '192.168.0.1', '192.168.0.2' ] +$amqp_port = '5673' +$rabbit_enabled = true +$deploy_vrouter = false +$corosync_roles = ['standalone-rabbitmq'] +$corosync_nodes = ['node1', 'node2'] + + $calculated_content = inline_template('<% +require "yaml" +amqp_hosts = @amqp_hosts.map {|x| x + ":" + @amqp_port}.join(",") +data = { + "amqp_hosts" => amqp_hosts, + "rabbit" => { + "enabled" => @rabbit_enabled, + }, + "deploy_vrouter" => @deploy_vrouter, +} +data["corosync_nodes"] = @corosync_nodes if @corosync_nodes +data["corosync_roles"] = @corosync_roles if @corosync_roles +-%> +<%= YAML.dump(data) %>') + +notice($calculated_content)