From ec02702d27f04313ea25c0b133b0a61cf2cc78e4 Mon Sep 17 00:00:00 2001 From: noelmcloughlin Date: Wed, 9 Jun 2021 01:15:55 +0100 Subject: [PATCH] feat(queues): create/delete queues using cli --- pillar.example | 19 ++++++++++--------- rabbitmq/config/clean.sls | 1 + rabbitmq/config/init.sls | 1 + rabbitmq/config/queue/clean.sls | 19 +++++++++++++++++++ rabbitmq/config/queue/init.sls | 5 +++++ rabbitmq/config/queue/install.sls | 21 +++++++++++++++++++++ 6 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 rabbitmq/config/queue/clean.sls create mode 100644 rabbitmq/config/queue/init.sls create mode 100644 rabbitmq/config/queue/install.sls diff --git a/pillar.example b/pillar.example index 6a80ace8..aa6243ca 100644 --- a/pillar.example +++ b/pillar.example @@ -45,15 +45,16 @@ rabbitmq: queue: my-new-queue: - - user: saltstack - - passwd: 'password' - - durable: true - - auto_delete: false - - vhost: test_vhost - - arguments: - - 'x-message-ttl': 8640000 - - 'x-expires': 8640000 - - 'x-dead-letter-exchange': 'my-new-exchange' + ## note : dict format + user: saltstack + passwd: 'password' + durable: true + auto_delete: false + vhost: test_vhost + arguments: + - 'x-message-ttl': 8640000 + - 'x-expires': 8640000 + - 'x-dead-letter-exchange': 'my-new-exchange' exchange: my-new-exchange: diff --git a/rabbitmq/config/clean.sls b/rabbitmq/config/clean.sls index 69d9a9f2..326b47b3 100644 --- a/rabbitmq/config/clean.sls +++ b/rabbitmq/config/clean.sls @@ -12,6 +12,7 @@ include: - .policy.clean - .plugin.clean - .upstream.clean + - .queue.clean - .vhost.clean - .user.clean - .file.clean diff --git a/rabbitmq/config/init.sls b/rabbitmq/config/init.sls index ab1e7d9c..93320b7e 100644 --- a/rabbitmq/config/init.sls +++ b/rabbitmq/config/init.sls @@ -5,6 +5,7 @@ include: - .file - .user - .vhost + - .queue - .policy - .plugin - .upstream diff --git a/rabbitmq/config/queue/clean.sls b/rabbitmq/config/queue/clean.sls new file mode 100644 index 00000000..faba5158 --- /dev/null +++ b/rabbitmq/config/queue/clean.sls @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import mapdata as rabbitmq with context %} +{%- set sls_service_running = tplroot ~ '.service.running' %} + +include: + - {{ sls_service_running }} + + {% for name, q in salt["pillar.get"]("rabbitmq:queue", {}).items() %} + +rabbitmq-config-queue-absent-{{ name }}: + cmd.run: + - name: /usr/local/sbin/rabbitmqadmin delete queue --vhost={{ q.vhost }} --username={{ q.user }} --password={{ q.passwd }} name={{ name }} + - require: + - service: {{ rabbitmq.service.name }} + + {% endfor %} diff --git a/rabbitmq/config/queue/init.sls b/rabbitmq/config/queue/init.sls new file mode 100644 index 00000000..d3e55181 --- /dev/null +++ b/rabbitmq/config/queue/init.sls @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +include: + - .install diff --git a/rabbitmq/config/queue/install.sls b/rabbitmq/config/queue/install.sls new file mode 100644 index 00000000..4d85bc8e --- /dev/null +++ b/rabbitmq/config/queue/install.sls @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import mapdata as rabbitmq with context %} +{%- set sls_service_running = tplroot ~ '.service.running' %} + +include: + - {{ sls_service_running }} + + {% for name, q in salt["pillar.get"]("rabbitmq:queue", {}).items() %} + +rabbitmq-config-queue-present-{{ name }}: + cmd.run: + - name: /usr/local/sbin/rabbitmqadmin declare queue --vhost={{ q.vhost }} --username={{ q.user }} --password={{ q.passwd }} name={{ name }} durable={{ q.durable|to_bool|lower }} auto_delete={{ q.auto_delete|to_bool|lower }} + + ### note: arguments='{# q.arguments|json #}' causes "mapping values are not allowed in this context" + - require: + - service: {{ rabbitmq.service.name }} + + {% endfor %}