From b9205e831368baaee70f5b99f7e349db07ab7192 Mon Sep 17 00:00:00 2001 From: Jesse Pretorius Date: Fri, 24 Nov 2017 13:26:14 +0000 Subject: [PATCH] Check and set cookie without using a failed task Currently the checking of the cookie content uses a try/rescue block and for a new install always results in a failed task. This causes a lot of confusion due to the failed task report. This patch improves the process by executing the stop/start if the cookie file is changed in any way by the copy task. This is far simpler and results in no task fails. As all the tasks related to this were marked rabbitmq-config the tag implementation is set in the main tasks file and removed from all the individual tasks. Change-Id: Iba959f730f2453bf9a295158749b96ed3a966ef4 --- tasks/main.yml | 1 + tasks/rabbitmq_set_cookie.yml | 43 +++++++++++++---------------------- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 3808ee36..8d8728ad 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -58,6 +58,7 @@ - include: rabbitmq_set_cookie.yml tags: - rabbitmq_server-config + - rabbitmq-config - include: rabbitmq_post_install.yml tags: diff --git a/tasks/rabbitmq_set_cookie.yml b/tasks/rabbitmq_set_cookie.yml index 6349a82a..4145fc71 100644 --- a/tasks/rabbitmq_set_cookie.yml +++ b/tasks/rabbitmq_set_cookie.yml @@ -13,33 +13,22 @@ # See the License for the specific language governing permissions and # limitations under the License. -- block: - - name: Read rabbit cookie - slurp: - src: /var/lib/rabbitmq/.erlang.cookie - register: tmp_rabbit_cookie - failed_when: (tmp_rabbit_cookie.content | b64decode).find(rabbitmq_cookie_token) == -1 - tags: - - rabbitmq-config +- name: Set rabbit cookie + copy: + content: "{{ rabbitmq_cookie_token }}" + dest: /var/lib/rabbitmq/.erlang.cookie + mode: "0400" + owner: rabbitmq + group: rabbitmq + register: cookie_set - rescue: - - include: rabbitmq_stopped.yml - static: no - tags: - - rabbitmq-config +- include: rabbitmq_stopped.yml + static: no + when: + - cookie_set | changed - - name: Set rabbit cookie - copy: - content: "{{ rabbitmq_cookie_token }}" - dest: /var/lib/rabbitmq/.erlang.cookie - mode: "0400" - owner: rabbitmq - group: rabbitmq - register: cookie_set - tags: - - rabbitmq-config +- include: rabbitmq_started.yml + static: no + when: + - cookie_set | changed - - include: rabbitmq_started.yml - static: no - tags: - - rabbitmq-config