From 69308a071089e75d26915c0cd7e9e7aef7a9976a Mon Sep 17 00:00:00 2001 From: Eric Veiras Galisson Date: Wed, 18 Dec 2019 14:08:03 +0100 Subject: [PATCH 1/2] feat: config_files source can be a salt:// path --- pillar.example | 16 +++++++++------- rabbitmq/config_files.sls | 9 +++++++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/pillar.example b/pillar.example index f533ab3d..319d11a2 100644 --- a/pillar.example +++ b/pillar.example @@ -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:pass@10.1.2.3" - 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... diff --git a/rabbitmq/config_files.sls b/rabbitmq/config_files.sls index c9fa8a26..b3b37154 100644 --- a/rabbitmq/config_files.sls +++ b/rabbitmq/config_files.sls @@ -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: From 2854d1bc112349f7344c153430c0c401e8654344 Mon Sep 17 00:00:00 2001 From: Eric Veiras Galisson Date: Wed, 18 Dec 2019 14:10:22 +0100 Subject: [PATCH 2/2] test: add test for config_files --- kitchen.yml | 9 +++++++++ test/integration/default/controls/config.rb | 11 +++++++++++ test/salt/files/rabbitmq/rabbitmq.conf | 1 + 3 files changed, 21 insertions(+) create mode 100644 test/integration/default/controls/config.rb create mode 100644 test/salt/files/rabbitmq/rabbitmq.conf diff --git a/kitchen.yml b/kitchen.yml index 8854d698..bfdf7c9b 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -182,6 +182,7 @@ suites: base: '*': - rabbitmq + - rabbitmq.config_files pillars: top.sls: base: @@ -189,6 +190,10 @@ suites: - rabbitmq pillars_from_files: rabbitmq.sls: pillar.example + dependencies: + - name: files + path: ./test/salt + verifier: inspec_tests: - path: test/integration/default @@ -198,6 +203,7 @@ suites: base: '*': - rabbitmq.latest + - rabbitmq.config_files pillars: top.sls: base: @@ -205,6 +211,9 @@ suites: - rabbitmq pillars_from_files: rabbitmq.sls: pillar.example + dependencies: + - name: files + path: ./test/salt verifier: inspec_tests: - path: test/integration/default diff --git a/test/integration/default/controls/config.rb b/test/integration/default/controls/config.rb new file mode 100644 index 00000000..5b7a5197 --- /dev/null +++ b/test/integration/default/controls/config.rb @@ -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 diff --git a/test/salt/files/rabbitmq/rabbitmq.conf b/test/salt/files/rabbitmq/rabbitmq.conf new file mode 100644 index 00000000..7843c775 --- /dev/null +++ b/test/salt/files/rabbitmq/rabbitmq.conf @@ -0,0 +1 @@ +# Config file for rabbitmq