Skip to content

Commit

Permalink
Merge pull request #58 from daks/env-mgmt
Browse files Browse the repository at this point in the history
Management of env file
  • Loading branch information
myii authored Dec 23, 2019
2 parents 3eaab51 + f7e5d39 commit 8c2001a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 0 deletions.
14 changes: 14 additions & 0 deletions kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ suites:
state_top:
base:
'*':
- states.files
- rabbitmq
- rabbitmq.config_files
pillars:
Expand All @@ -190,17 +191,25 @@ suites:
- rabbitmq
pillars_from_files:
rabbitmq.sls: pillar.example
# dependencies needed for tests
dependencies:
# extra files provided to the formula
- name: files
path: ./test/salt
# states used to prepare the system before tests
- name: states
path: ./test/salt

verifier:
inspec_tests:
- path: test/integration/default

- name: latest
provisioner:
state_top:
base:
'*':
- states.files
- rabbitmq.latest
- rabbitmq.config_files
pillars:
Expand All @@ -210,9 +219,14 @@ suites:
- rabbitmq
pillars_from_files:
rabbitmq.sls: pillar.example
# dependencies needed for tests
dependencies:
# extra files provided to the formula
- name: files
path: ./test/salt
# states used to prepare the system before tests
- name: states
path: ./test/salt
verifier:
inspec_tests:
- path: test/integration/default
2 changes: 2 additions & 0 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ rabbitmq:
# version: "3.5.3-1"
enabled: true
running: true
env:
rabbitmq_mnesia_base: /opt/rabbitmq
plugin:
rabbitmq_management:
- enabled
Expand Down
12 changes: 12 additions & 0 deletions rabbitmq/config.sls
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,15 @@ rabbitmq_user_guest:
rabbitmq_user.absent:
- name: guest
{% endif %}

{%- if salt['pillar.get']('rabbitmq:env', None) %}
rabbitmq_env-file:
file.managed:
- name: /etc/rabbitmq/rabbitmq-env.conf
- source: salt://{{ slspath }}/files/rabbitmq-env.conf
- template: jinja
- context:
env: {{ salt['pillar.get']('rabbitmq:env', {}) }}
- watch_in:
- service: rabbitmq-server
{%- endif %}
8 changes: 8 additions & 0 deletions rabbitmq/files/rabbitmq-env.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
########################################################################
# File managed by Salt at <{{ source }}>.
# Your changes will be overwritten.
########################################################################

{% for key, value in env.items() %}
{{ key | upper }}={{ value }}
{%- endfor %}
6 changes: 6 additions & 0 deletions test/integration/default/controls/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@
it { should be_file }
its('content') { should include '# Config file for rabbitmq' }
end

describe file('/etc/rabbitmq/rabbitmq-env.conf') do
it { should exist }
it { should be_file }
its('content') { should include 'RABBITMQ_MNESIA_BASE=/opt/rabbitmq' }
end
end
14 changes: 14 additions & 0 deletions test/salt/states/files/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

rabbitmq_user:
user.present:
- name: rabbitmq
- home: /opt/rabbitmq

rabbitmq_dir:
file.directory:
- name: /opt/rabbitmq
- user: rabbitmq
- group: rabbitmq
- makedirs: true
- require:
- user: rabbitmq

0 comments on commit 8c2001a

Please sign in to comment.