Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed generating single quote erlang config file #5

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/

6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# RabbitMQ Ansible Role

## Dependcies

It depends from:

- [`config_encoder_filters v1.3`](https://galaxy.ansible.com/jtyr/config_encoder_filters)

## Version

See:
Expand Down
11 changes: 3 additions & 8 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
---
rabbitmq_cluster: False

rabbitmq_cluster: False
rabbitmq_cluster_master: "rabbit@{{ hostvars[ansible_play_hosts.0].ansible_hostname }}"

rabbitmq_cluster_name: "rabbitmq-cluster"
rabbitmq_erlang_cookie_file: /var/lib/rabbitmq/.erlang.cookie

rabbitmq_plugin_dir: "/usr/lib/rabbitmq/lib/rabbitmq_server-{{ rabbitmq_version.split('-').0 }}/plugins"

rabbitmq_plugins:
- rabbitmq_management

rabbitmq_plugins_disabled: []

rabbitmq_users:
- user: admin
password: admin
Expand All @@ -20,8 +17,6 @@ rabbitmq_users:
rabbitmq_users_absent:
- guest

rabbitmq_version: 3.6.6-1

rabbitmq_version: 3.6.10-1
rabbitmq_vhosts: []

rabbitmq_vhosts_absent: []
4 changes: 4 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---

- name: rabbitmq restart
service: name=rabbitmq-server state=restarted
7 changes: 6 additions & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---

galaxy_info:
author: jasonroyle
description: RabbitMQ
Expand All @@ -13,10 +14,14 @@ galaxy_info:
- name: Ubuntu
versions:
- trusty
- xenial
galaxy_tags:
- rabbitmq
- amqp
- plugin
- cluster

dependencies: []
dependencies:
- src: jtyr.config_encoder_filters
version: v1.3

5 changes: 3 additions & 2 deletions tasks/Debian/install.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
- name: import erlang rpm key

- name: import erlang apt key
apt_key:
url: "https://packages.erlang-solutions.com/debian/erlang_solutions.asc"

Expand All @@ -11,7 +12,7 @@
apt:
name: erlang

- name: import rabbitmq rpm key
- name: import rabbitmq apt key
apt_key:
url: https://www.rabbitmq.com/rabbitmq-release-signing-key.asc

Expand Down
1 change: 1 addition & 0 deletions tasks/RedHat/install.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---

- name: import erlang rpm key
rpm_key:
key: https://packages.erlang-solutions.com/rpm/erlang_solutions.asc
Expand Down
7 changes: 4 additions & 3 deletions tasks/cluster.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
---

- name: stop rabbitmq app
shell: rabbitmqctl stop_app

- name: reset rabbitmq
shell: rabbitmqctl reset

- name: join rabbitmq cluster
shell: "rabbitmqctl join_cluster {{ rabbitmq_cluster_master }}"
register: rabbitmq_output
Expand All @@ -10,6 +14,3 @@
- name: ensure rabbitmq cluster member
fail: msg="Unable to join the cluster."
when: ("'already_member' not in rabbitmq_output.stderr") and rabbitmq_output.rc != 0

- name: start rabbitmq app
shell: rabbitmqctl start_app
16 changes: 9 additions & 7 deletions tasks/configure-cluster.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
---

- name: add rabbitmq cluster hosts
lineinfile:
dest: /etc/hosts
line: "{{ hostvars[item].rabbitmq_cluster_ip_address | default(hostvars[item].ansible_default_ipv4.address) }} {{ hostvars[item].ansible_hostname }}"
with_items: "{{ ansible_play_hosts }}"

- name: set erlang cookie
template:
src: erlang.cookie.j2
dest: "{{ rabbitmq_erlang_cookie_file }}"
owner: rabbitmq
group: rabbitmq
mode: 0400
- name: set cluster name
shell: "rabbitmqctl set_cluster_name {{ rabbitmq_cluster_name }}"

- include: cluster.yml
when: rabbitmq_cluster and rabbitmq_nodename != rabbitmq_cluster_master

- name: start rabbitmq app
shell: rabbitmqctl start_app
22 changes: 22 additions & 0 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
---

- name: configure rabbitmq
template:
src: rabbitmq.config.j2
dest: /etc/rabbitmq/rabbitmq.config
when: rabbitmq_config is defined

- name: rabbitmq full stop
include: node_fullstop.yml
when: rabbitmq_erlang_cookie is defined

- name: set erlang cookie
template:
src: erlang.cookie.j2
dest: "{{ rabbitmq_erlang_cookie_file }}"
owner: rabbitmq
group: rabbitmq
mode: 0400
when: rabbitmq_erlang_cookie is defined
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this. It will make it easy to make the erlang_cookie setting optional. You only really want to set it once, during the initial setup and when doing maintenance updates it might be a good idea to leave it out.

This of course may introduce a problem when adding new nodes to the cluster. But I guess that this is a good enough trade-off in this case.

Copy link
Collaborator Author

@Raffaello Raffaello Oct 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it could be a problem adding new nodes. It should be more parametrized, but still for a new node you still can define that cookie from ansible CLI, so it should be possible.


- include: node_fullstart.yml

- include: vhosts.yml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may fail when creating new hosts. Similar to #6, however, I have opened a separate issue for this: #7.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now with ansible 2.4 there should be improvements on these rabbitmq functions. Also it should support TLS that was a requirements for me with this role, so until ansible 2.3 there were issues with TLS and certificates. Now those should be fixed. Not sure. I suspended working on this one.


- include: users.yml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I noted in #6, this will fail when creating new users (at least it did for me). It would be good to only run this on the master node.


- include: plugins.yml
12 changes: 9 additions & 3 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
---
- include: rabbitmq.yml
tags:
- rabbitmq

- name: include rabbitmq installation tasks
include: "{{ ansible_os_family }}/install.yml"

- include: configure.yml

- include: configure-cluster.yml
when: rabbitmq_cluster

4 changes: 4 additions & 0 deletions tasks/node_fullrestart.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---

- include: node_fullstop.yml
- include: node_fullstart.yml
10 changes: 10 additions & 0 deletions tasks/node_fullstart.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---

- name: start rabbitmq server
service:
name: rabbitmq-server
enabled: true
state: started

- name: start rabbitmq app
shell: rabbitmqctl start_app
17 changes: 17 additions & 0 deletions tasks/node_fullstop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---

- name: start rabbitmq server
service:
name: rabbitmq-server
state: started

- name: stop rabbitmq app
shell: rabbitmqctl stop_app

- name: rabbitmq app reset
shell: rabbitmqctl reset

- name: stop rabbitmq server
service:
name: rabbitmq-server
state: stopped
10 changes: 10 additions & 0 deletions tasks/node_start.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---

- name: start rabbitmq server
service:
name: rabbitmq-server
enabled: true
state: started

- name: start rabbitmq app
shell: rabbitmqctl start_app
1 change: 1 addition & 0 deletions tasks/plugins.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---

- name: install rabbitmq plugins
get_url:
url: "{{ item.url }}"
Expand Down
23 changes: 0 additions & 23 deletions tasks/rabbitmq.yml

This file was deleted.

1 change: 1 addition & 0 deletions tasks/users.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---

- name: remove rabbitmq users
rabbitmq_user:
user: "{{ item }}"
Expand Down
1 change: 1 addition & 0 deletions tasks/vhosts.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---

- name: remove rabbitmq virtual hosts
rabbitmq_vhost:
name: "{{ item }}"
Expand Down
Empty file.
20 changes: 0 additions & 20 deletions templates/config-encoder-macros/LICENSE.md

This file was deleted.

Loading