From a67dde50f26e0f76d91f0744e8e8341dac95dae2 Mon Sep 17 00:00:00 2001 From: Larry Smith Jr Date: Sat, 20 May 2017 21:19:34 -0400 Subject: Cleaned up code as part of issue #10 Signed-off-by: Larry Smith Jr --- tasks/debian.yml | 6 ++++++ tasks/fedora.yml | 7 +++++++ tasks/main.yml | 17 ++++++++++++++--- tasks/rabbitmq_ha_config.yml | 27 +++++++++++++++++---------- tasks/rabbitmq_users.yml | 39 +++++++++++++++++++++++---------------- tasks/redhat.yml | 7 +++++++ 6 files changed, 74 insertions(+), 29 deletions(-) (limited to 'tasks') diff --git a/tasks/debian.yml b/tasks/debian.yml index a031ead..b25d39b 100644 --- a/tasks/debian.yml +++ b/tasks/debian.yml @@ -3,22 +3,26 @@ apt_key: url: "{{ rabbitmq_debian_repo_key }}" state: present + become: true - name: debian | adding RabbitMQ repo apt_repository: repo: "{{ rabbitmq_debian_repo }}" state: present register: "rabbitmq_repo_added" + become: true - name: debian | updating apt cache apt: update_cache: yes + become: true when: rabbitmq_repo_added.changed - name: debian | installing RabbitMQ server apt: name: "{{ item }}" state: present + become: true with_items: - rabbitmq-server @@ -26,6 +30,7 @@ rabbitmq_plugin: names: rabbitmq_management state: enabled + become: true notify: restart rabbitmq-server - name: debian | ensuring that the RabbitMQ service is running @@ -33,3 +38,4 @@ name: rabbitmq-server state: started enabled: yes + become: true diff --git a/tasks/fedora.yml b/tasks/fedora.yml index 3d92963..6ac9c03 100644 --- a/tasks/fedora.yml +++ b/tasks/fedora.yml @@ -3,6 +3,7 @@ dnf: name: "{{ item }}" state: present + become: true with_items: - wget @@ -10,30 +11,36 @@ dnf: name: "erlang" state: present + become: true - name: fedora | adding RabbitMQ public GPG key rpm_key: key: "{{ rabbitmq_redhat_repo_key }}" state: present + become: true - name: fedora | downloading RabbitMQ get_url: url: "{{ rabbitmq_redhat_url }}/{{ rabbitmq_redhat_package }}" dest: "/opt/{{ rabbitmq_redhat_package }}" + become: true - name: fedora | installing RabbitMQ dnf: name: "/opt/{{ rabbitmq_redhat_package }}" state: present + become: true - name: fedora | starting and enabling RabbitMQ service service: name: "rabbitmq-server" state: started enabled: yes + become: true - name: fedora | enabling the RabbitMQ Management Console rabbitmq_plugin: names: rabbitmq_management state: enabled notify: restart rabbitmq-server + become: true diff --git a/tasks/main.yml b/tasks/main.yml index bd82f93..1da06c4 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -3,19 +3,30 @@ when: ansible_os_family == "Debian" - include: redhat.yml - when: ansible_distribution == "CentOS" or ansible_distribution == "Red Hat Enterprise Linux" + when: > + ansible_distribution == "CentOS" or + ansible_distribution == "Red Hat Enterprise Linux" - include: fedora.yml when: ansible_distribution == "Fedora" +- include: config.yml + when: rabbitmq_config_service + - name: checking to see if already clustered stat: path=/etc/rabbitmq/clustered register: clustered - include: rabbitmq_clustering.yml - when: rabbitmq_enable_clustering and (clustered.stat.exists != True) + when: > + rabbitmq_enable_clustering and + not clustered['stat']['exists'] - include: rabbitmq_ha_config.yml - when: rabbitmq_config_ha and rabbitmq_enable_clustering + when: > + rabbitmq_config_ha and + rabbitmq_enable_clustering and + rabbitmq_config is defined - include: rabbitmq_users.yml + when: rabbitmq_users is defined diff --git a/tasks/rabbitmq_ha_config.yml b/tasks/rabbitmq_ha_config.yml index 8811b6d..bf74957 100644 --- a/tasks/rabbitmq_ha_config.yml +++ b/tasks/rabbitmq_ha_config.yml @@ -6,39 +6,46 @@ - name: rabbitmq_ha_config | install rabbitMQ admin shell: wget http://guest:guest@localhost:15672/cli/rabbitmqadmin - when: not rabbitmqadmin_check.stat.exists + become: true + when: not rabbitmqadmin_check['stat']['exists'] - name: rabbitmq_ha_config | moving the rabbitMQ Admin shell: mv rabbitmqadmin /usr/sbin - when: not rabbitmqadmin_check.stat.exists + become: true + when: not rabbitmqadmin_check['stat']['exists'] - name: rabbitmq_ha_config | making executable rabbitMQ Admin shell: chmod +x /usr/sbin/rabbitmqadmin notify: restart rabbitmq-server - when: not rabbitmqadmin_check.stat.exists + become: true + when: not rabbitmqadmin_check['stat']['exists'] - name: rabbitmq_ha_config | creating queue(s) - command: rabbitmqadmin declare queue name={{ item.queue_name }} durable={{ item.durable|lower }} + command: rabbitmqadmin declare queue name={{ item['queue_name'] }} durable={{ item['durable']|lower }} run_once: true + become: true with_items: "{{ rabbitmq_config }}" - name: rabbitmq_ha_config | setting up ha on queue(s) rabbitmq_policy: name: "ha-all" - pattern: "{{ item.queue_name }}" - tags: "{{ item.tags }}" + pattern: "{{ item['queue_name'] }}" + tags: "{{ item['tags'] }}" state: present run_once: true + become: true with_items: "{{ rabbitmq_config }}" - name: rabbitmq_ha_config | creating exchange(s) - command: rabbitmqadmin declare exchange name={{ item.exchange_name }} type={{ item.type }} + command: rabbitmqadmin declare exchange name={{ item['exchange_name'] }} type={{ item['type'] }} run_once: true + become: true with_items: "{{ rabbitmq_config }}" - when: item.exchange_name is defined + when: item['exchange_name'] is defined - name: rabbitmq_ha_config | creating binding(s) - command: rabbitmqadmin declare binding source={{ item.exchange_name }} destination_type="queue" destination={{ item.queue_name }} routing_key={{ item.routing_key }} + command: rabbitmqadmin declare binding source={{ item['exchange_name'] }} destination_type="queue" destination={{ item['queue_name'] }} routing_key={{ item['routing_key'] }} run_once: true + become: true with_items: "{{ rabbitmq_config }}" - when: item.exchange_name is defined + when: item['exchange_name'] is defined diff --git a/tasks/rabbitmq_users.yml b/tasks/rabbitmq_users.yml index 8bce8b2..98e45e2 100644 --- a/tasks/rabbitmq_users.yml +++ b/tasks/rabbitmq_users.yml @@ -1,27 +1,34 @@ --- - name: rabbitmq_users | creating rabbitmq users rabbitmq_user: - name: "{{ item.name }}" - password: "{{ item.password }}" - vhost: "{{ item.vhost }}" - configure_priv: "{{ item.configure_priv }}" - read_priv: "{{ item.read_priv }}" - write_priv: "{{ item.write_priv }}" - tags: "{{ item.tags }}" + name: "{{ item['name'] }}" + password: "{{ item['password'] }}" + vhost: "{{ item['vhost'] }}" + configure_priv: "{{ item['configure_priv'] }}" + read_priv: "{{ item['read_priv'] }}" + write_priv: "{{ item['write_priv'] }}" + tags: "{{ item['tags'] }}" state: present + become: true with_items: "{{ rabbitmq_users }}" - when: (rabbitmq_enable_clustering is defined and not rabbitmq_enable_clustering) or rabbitmq_enable_clustering is not defined + when: > + (rabbitmq_enable_clustering is defined and + not rabbitmq_enable_clustering) or + rabbitmq_enable_clustering is not defined - name: rabbitmq_users | creating rabbitmq users rabbitmq_user: - name: "{{ item.name }}" - password: "{{ item.password }}" - vhost: "{{ item.vhost }}" - configure_priv: "{{ item.configure_priv }}" - read_priv: "{{ item.read_priv }}" - write_priv: "{{ item.write_priv }}" - tags: "{{ item.tags }}" + name: "{{ item['name'] }}" + password: "{{ item['password'] }}" + vhost: "{{ item['vhost'] }}" + configure_priv: "{{ item['configure_priv'] }}" + read_priv: "{{ item['read_priv'] }}" + write_priv: "{{ item['write_priv'] }}" + tags: "{{ item['tags'] }}" state: present run_once: yes + become: true with_items: "{{ rabbitmq_users }}" - when: (rabbitmq_enable_clustering is defined and rabbitmq_enable_clustering) + when: > + rabbitmq_enable_clustering is defined and + rabbitmq_enable_clustering diff --git a/tasks/redhat.yml b/tasks/redhat.yml index 484597d..afa714c 100644 --- a/tasks/redhat.yml +++ b/tasks/redhat.yml @@ -3,6 +3,7 @@ yum: name: "{{ item }}" state: present + become: true with_items: - epel-release - wget @@ -11,30 +12,36 @@ yum: name: "erlang" state: present + become: true - name: redhat | adding RabbitMQ public GPG key rpm_key: key: "{{ rabbitmq_redhat_repo_key }}" state: present + become: true - name: redhat | downloading RabbitMQ get_url: url: "{{ rabbitmq_redhat_url }}/{{ rabbitmq_redhat_package }}" dest: "/opt/{{ rabbitmq_redhat_package }}" + become: true - name: redhat | installing RabbitMQ yum: name: "/opt/{{ rabbitmq_redhat_package }}" state: present + become: true - name: redhat | starting and enabling RabbitMQ service service: name: "rabbitmq-server" state: started enabled: yes + become: true - name: redhat | enabling the RabbitMQ Management Console rabbitmq_plugin: names: rabbitmq_management state: enabled notify: restart rabbitmq-server + become: true -- cgit v1.2.3