ansible自动安装rabbitmq

ansible playbook 安装rabbitmq单机版,以下脚本在CentOS6.7服务器测试通过。

需要配置本机的yum源,用于安装socat软件。

rabbitmq版本和Erlang版本需要对应,相关文档见:http://www.rabbitmq.com/which-erlang.html

可以根据自己需要选择rabbitmq版本(但要到官网查询支持的Erlang,否则安装后无法启动)

 1 ---
 2 - name: install rabbitmq app
 3   gather_facts: False
 4   hosts: "{{ host }}"
 5   user: root
 6   tasks:
 7     - name: time sync
 8       command: /usr/sbin/ntpdate 10.86.1.76
 9       
10     - name: install require rpm packages
11       yum: name=socat state=installed
12 
13     - name: download erlang package
14       get_url: url={{ erlang_url }} dest=/tmp/erlang.rpm 
15 
16     - name: install erlang packages
17       yum: name=/tmp/erlang.rpm state=present
18 
19     - name: download rabbitmq package
20       get_url: url={{ rabbitmq_url }} dest=/tmp/rabbitmq-server.rpm
21 
22     - name: rpm install rabbitmq-server
23       yum: name=/tmp/rabbitmq-server.rpm state=present
24 
25     - name: start rabbitmq-server
26       service: name=rabbitmq-server enabled=yes state=restarted
27 
28     - name: Enable the plugins is installed
29       shell: rabbitmq-plugins enable rabbitmq_management && rabbitmq-plugins enable rabbitmq_mqtt && rabbitmq-plugins enable rabbitmq_web_mqtt
30       notify:
31         restart rabbitmq-server
32 
33     - name: create the rabbitmq user
34       shell: rabbitmqctl add_user {{ username }} {{ password }}
35       ignore_errors: yes
36 
37     - name: add rabbitmq_user to adminstrator
38       shell: rabbitmqctl set_user_tags {{ username }} administrator
39 
40     - name: configure the rabbitmq_user premission
41       shell: rabbitmqctl set_permissions -p "/" {{ username }} ".*" ".*" ".*"
42 
43     - name: del rabbitmq install pkg
44       file: path={{ item }} state=absent
45       with_items:
46         - /tmp/erlang.rpm
47         - /tmp/rabbitmq-server.rpm
48 
49   handlers: 
50     - name: restart rabbitmq-server 
51       service: name=rabbitmq-server state=restarted
View Code

 

使用方法:

ansible-playbook rabbitmq_install.yml --extra-vars "{'host':'192.168.233.233','erlang_url':'https://github.com/rabbitmq/erlang-rpm/releases/download/v19.3.6.4/erlang-19.3.6.4-1.el6.x86_64.rpm','rabbitmq_url':'http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.14/rabbitmq-server-3.6.14-1.el6.noarch.rpm','username':'mquser','password':'123456'}"

 

相关软件下载地址:

rabbitmq-server下载:http://www.rabbitmq.com/releases/rabbitmq-server/
Erlang版本支持列表:http://www.rabbitmq.com/which-erlang.html
Erlang下载:https://github.com/rabbitmq/erlang-rpm/releases

posted @ 2017-12-12 19:52  冷水泡茶  阅读(1609)  评论(0编辑  收藏  举报