Skip to content

Commit

Permalink
Merge pull request #57 from daks/source-files
Browse files Browse the repository at this point in the history
Option to specify an absolute salt:// path for config_files
  • Loading branch information
myii authored Dec 19, 2019
2 parents e97c976 + 2854d1b commit 7f5f6c3
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
9 changes: 9 additions & 0 deletions kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,18 @@ suites:
base:
'*':
- rabbitmq
- rabbitmq.config_files
pillars:
top.sls:
base:
'*':
- rabbitmq
pillars_from_files:
rabbitmq.sls: pillar.example
dependencies:
- name: files
path: ./test/salt

verifier:
inspec_tests:
- path: test/integration/default
Expand All @@ -198,13 +203,17 @@ suites:
base:
'*':
- rabbitmq.latest
- rabbitmq.config_files
pillars:
top.sls:
base:
'*':
- rabbitmq
pillars_from_files:
rabbitmq.sls: pillar.example
dependencies:
- name: files
path: ./test/salt
verifier:
inspec_tests:
- path: test/integration/default
16 changes: 9 additions & 7 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ rabbitmq:
config_files:
# config_files, if you need some stuffs set directly in configuration
# files, rather than via the light modules available.
rabbitmq.config:
# Need to add some template in rabbitmq/templates/rabbitmq.config
# templates not provided, as is probably too specific...
source: templates/relay-rabbitmq.config
rabbitmq.conf:
# source is relative to `rabbitmq` formula
# source: templates/rabbitmq.conf
# or absolute in salt fileserver
source: salt://files/rabbitmq/rabbitmq.conf
# an optional map can be passed to the jinja template
context:
src_broker_uri: "amqp://user:[email protected]"
rabbitmqcfg.json:
source: templates/relay-rabbitmqcfg.config
# context: is optional map passed to the jinja template...
# rabbitmqcfg.json:
# source: templates/relay-rabbitmqcfg.config
# # context: is optional map passed to the jinja template...
9 changes: 7 additions & 2 deletions rabbitmq/config_files.sls
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
include:
- .install

{% for filename, info in salt["pillar.get"]("rabbitmq:config_files", {}).items() %}
{%- for filename, info in salt["pillar.get"]("rabbitmq:config_files", {}).items() %}
{%- set source = info['source'] %}
/etc/rabbitmq/{{ filename }}:
file.managed:
- source: salt://{{ slspath }}/{{ info['source'] }}
{%- if source.startswith('salt://') %}
- source: {{ source }}
{%- else %}
- source: salt://{{ slspath }}/{{ source }}
{% endif %}
- template: jinja
- context: {{ info.get('context', {})|json }}
- watch_in:
Expand Down
11 changes: 11 additions & 0 deletions test/integration/default/controls/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

control 'rabbitmq configuration' do
title 'should match desired lines'

describe file('/etc/rabbitmq/rabbitmq.conf') do
it { should exist }
it { should be_file }
its('content') { should include '# Config file for rabbitmq' }
end
end
1 change: 1 addition & 0 deletions test/salt/files/rabbitmq/rabbitmq.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Config file for rabbitmq

0 comments on commit 7f5f6c3

Please sign in to comment.