Refactor plugin to support new yaml files
Change-Id: Ic58445906a4470d40c887a3c0524133e20565ec9
This commit is contained in:
parent
deda8672d7
commit
2c64c9a98c
|
@ -1,3 +1,4 @@
|
||||||
.tox
|
.tox
|
||||||
.build
|
.build
|
||||||
*.pyc
|
*.pyc
|
||||||
|
.idea
|
||||||
|
|
|
@ -1,21 +1,26 @@
|
||||||
notice('MODULAR: detach-rabbitmq/rabbitmq_hiera_override.pp')
|
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_name = 'detach-rabbitmq'
|
||||||
$plugin_yaml = "${plugin_name}.yaml"
|
$detach_rabbitmq_plugin = hiera($plugin_name, undef)
|
||||||
|
|
||||||
if ($detach_rabbitmq_plugin) {
|
if ($detach_rabbitmq_plugin) {
|
||||||
|
$hiera_plugins_dir = '/etc/hiera/plugins'
|
||||||
|
$plugin_yaml = "${hiera_plugins_dir}/${plugin_name}.yaml"
|
||||||
$network_metadata = hiera_hash('network_metadata')
|
$network_metadata = hiera_hash('network_metadata')
|
||||||
$rabbitmq_roles = [ 'standalone-rabbitmq' ]
|
$rabbitmq_roles = [ 'standalone-rabbitmq' ]
|
||||||
$rabbit_nodes = get_nodes_hash_by_roles($network_metadata, $rabbitmq_roles)
|
$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')
|
$rabbit_address_map = get_node_to_ipaddr_map_by_network_role(
|
||||||
#lint:endignore
|
$rabbit_nodes,
|
||||||
$amqp_port = hiera('amqp_port', '5673')
|
'mgmt/messaging',
|
||||||
|
)
|
||||||
|
|
||||||
$rabbit_nodes_ips = values($rabbit_address_map)
|
$rabbit_nodes_ips = values($rabbit_address_map)
|
||||||
$rabbit_nodes_names = keys($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') {
|
case hiera_array('roles', 'none') {
|
||||||
/rabbitmq/: {
|
/rabbitmq/: {
|
||||||
$rabbit_enabled = true
|
$rabbit_enabled = true
|
||||||
|
@ -29,55 +34,30 @@ if ($detach_rabbitmq_plugin) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$amqp_nodes = $rabbit_nodes_ips
|
$calculated_content = inline_template('<%
|
||||||
$amqp_hosts = inline_template("<%= @amqp_nodes.map {|x| x + ':' + @amqp_port}.join ',' %>")
|
require "yaml"
|
||||||
|
amqp_hosts = @amqp_hosts.map {|x| x + ":" + @amqp_port}.join(",")
|
||||||
$calculated_content = inline_template('
|
data = {
|
||||||
amqp_hosts: <%= @amqp_hosts %>
|
"amqp_hosts" => amqp_hosts,
|
||||||
rabbit:
|
"rabbit" => {
|
||||||
enabled: <%= @rabbit_enabled %>
|
"enabled" => @rabbit_enabled,
|
||||||
<% if @corosync_nodes -%>
|
},
|
||||||
<% require "yaml" -%>
|
"deploy_vrouter" => @deploy_vrouter,
|
||||||
corosync_nodes:
|
}
|
||||||
<%= YAML.dump(@corosync_nodes).sub(/--- *$/,"") %>
|
data["corosync_nodes"] = @corosync_nodes if @corosync_nodes
|
||||||
<% end -%>
|
data["corosync_roles"] = @corosync_roles if @corosync_roles
|
||||||
<% if @corosync_roles -%>
|
-%>
|
||||||
corosync_roles:
|
<%= YAML.dump(data) %>')
|
||||||
<%
|
|
||||||
@corosync_roles.each do |crole|
|
file { 'hiera_plugins' :
|
||||||
%> - <%= crole %>
|
ensure => 'directory',
|
||||||
<% end -%>
|
path => $hiera_plugins_dir,
|
||||||
<% end -%>
|
}
|
||||||
deploy_vrouter: <%= @deploy_vrouter %>
|
|
||||||
')
|
file { 'plugin_yaml' :
|
||||||
|
ensure => 'present',
|
||||||
###################
|
path => $plugin_yaml,
|
||||||
file {'/etc/hiera/override':
|
content => $calculated_content,
|
||||||
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'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue