From 53f12d2f8053c0a4afe3f8fc3ef5006e453cc435 Mon Sep 17 00:00:00 2001 From: Eric Veiras Galisson Date: Wed, 18 Dec 2019 16:59:19 +0100 Subject: [PATCH 1/3] feat: config state now also managed rabbitmq env file --- pillar.example | 2 ++ rabbitmq/config.sls | 12 ++++++++++++ rabbitmq/files/rabbitmq-env.conf | 8 ++++++++ 3 files changed, 22 insertions(+) create mode 100644 rabbitmq/files/rabbitmq-env.conf diff --git a/pillar.example b/pillar.example index 319d11a2..79b8109a 100644 --- a/pillar.example +++ b/pillar.example @@ -3,6 +3,8 @@ rabbitmq: # version: "3.5.3-1" enabled: true running: true + env: + rabbitmq_mnesia_base: /opt/rabbitmq plugin: rabbitmq_management: - enabled diff --git a/rabbitmq/config.sls b/rabbitmq/config.sls index c63b7022..f7ee0216 100644 --- a/rabbitmq/config.sls +++ b/rabbitmq/config.sls @@ -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 %} diff --git a/rabbitmq/files/rabbitmq-env.conf b/rabbitmq/files/rabbitmq-env.conf new file mode 100644 index 00000000..a941962b --- /dev/null +++ b/rabbitmq/files/rabbitmq-env.conf @@ -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 %} From 85e2e321c6c179f6eefdea226e64b2a1d4888028 Mon Sep 17 00:00:00 2001 From: Eric Veiras Galisson Date: Wed, 18 Dec 2019 17:05:18 +0100 Subject: [PATCH 2/3] ci(kitchen): add salt state to kitchen exec --- kitchen.yml | 18 ++++++++++++------ test/salt/states/files/init.sls | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 test/salt/states/files/init.sls diff --git a/kitchen.yml b/kitchen.yml index 0fa2ce91..4ebfae93 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -166,6 +166,15 @@ provisioner: salt_copy_filter: - .kitchen - .git + # dependencies needed for tests + dependencies: + # extraneous files provided to the formula + - name: files + path: ./test/salt + # states used to prepare the system before tests + - name: states + path: ./test/salt + verifier: # https://www.inspec.io/ @@ -181,6 +190,7 @@ suites: state_top: base: '*': + - states.files - rabbitmq - rabbitmq.config_files pillars: @@ -190,17 +200,16 @@ suites: - rabbitmq pillars_from_files: rabbitmq.sls: pillar.example - dependencies: - - name: files - path: ./test/salt verifier: inspec_tests: - path: test/integration/default + - name: latest provisioner: state_top: base: '*': + - states.files - rabbitmq.latest - rabbitmq.config_files pillars: @@ -210,9 +219,6 @@ 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/salt/states/files/init.sls b/test/salt/states/files/init.sls new file mode 100644 index 00000000..410a8592 --- /dev/null +++ b/test/salt/states/files/init.sls @@ -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 From f7e5d391d7537fe91a0b425043b7d83bfb247511 Mon Sep 17 00:00:00 2001 From: Eric Veiras Galisson Date: Mon, 23 Dec 2019 12:14:51 +0100 Subject: [PATCH 3/3] test(inspec): test new rabbitmq-env file --- kitchen.yml | 26 ++++++++++++++------- test/integration/default/controls/config.rb | 6 +++++ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/kitchen.yml b/kitchen.yml index 4ebfae93..0a82a9d1 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -166,15 +166,6 @@ provisioner: salt_copy_filter: - .kitchen - .git - # dependencies needed for tests - dependencies: - # extraneous files provided to the formula - - name: files - path: ./test/salt - # states used to prepare the system before tests - - name: states - path: ./test/salt - verifier: # https://www.inspec.io/ @@ -200,6 +191,15 @@ 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 @@ -219,6 +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 diff --git a/test/integration/default/controls/config.rb b/test/integration/default/controls/config.rb index 5b7a5197..1a120321 100644 --- a/test/integration/default/controls/config.rb +++ b/test/integration/default/controls/config.rb @@ -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