@@ -0,0 +1,2573 @@
+import argparse%0D%0Afrom fabric.api import *%0D%0Afrom fabric.contrib import files%0D%0A%0D%0Aparser = argparse.ArgumentParser()%0D%0Agroup = parser.add_mutually_exclusive_group()%0D%0A%0D%0Aparser.add_argument('--user', help='the target user', %0D%0A                    action='store', default='ubuntu', dest='user')%0D%0Aparser.add_argument('--hosts', help='the target address', %0D%0A                    action='store', dest='hosts')%0D%0Agroup.add_argument('--install', help='install RabbitMQ HA', %0D%0A                   action='store_true', default=False, dest='install')%0D%0Aparser.add_argument('--erlang-cookie', help='setup elang cookie',%0D%0A                    action='store', default=False, dest='erlang_cookie')%0D%0Aparser.add_argument('--rabbit-user', help='set rabbit user name',%0D%0A                    action='store', default=False, dest='rabbit_user')%0D%0Aparser.add_argument('--rabbit-pass', help='set rabbit password',%0D%0A                    action='store', default=False, dest='rabbit_pass')%0D%0Agroup.add_argument('--join-cluster', help='join the rabbit cluster',%0D%0A                   action='store', default=False, dest='join_cluster')%0D%0A%0D%0Aargs = parser.parse_args()%0D%0A%0D%0A%0D%0Aclass RabbitMq(object):%0D%0A    %22%22%22RabbitMQ HA Installation%22%22%22%0D%0A    def __init__(self, user, hosts, parallel=True):%0D%0A        self.user = user%0D%0A        self.hosts = hosts%0D%0A        self.parallel = parallel%0D%0A        env.user = self.user%0D%0A        env.hosts = self.hosts%0D%0A        env.parallel = self.parallel%0D%0A%0D%0A    def _install(self, erlang_cookie, rabbit_user, rabbit_pass):%0D%0A        sudo('apt-get update')%0D%0A        sudo('apt-get install -y rabbitmq-server')%0D%0A        sudo('service rabbitmq-server stop')%0D%0A        sudo('echo %22%25s%22 %3E /var/lib/rabbitmq/.erlang.cookie' %25 erlang_cookie)%0D%0A        sudo('service rabbitmq-server start')%0D%0A        sudo('rabbitmqctl change_password %25s %25s' %25 (rabbit_user, rabbit_pass))%0D%0A        sudo('echo %22%5B%7Brabbit, %5B%7Bloopback_users, %5B%5D%7D%5D%7D%5D.%22 %3E /etc/rabbitmq/rabbitmq.config')%0D%0A        sudo('service rabbitmq-server restart')%0D%0A%0D%0A    def _join_cluster(self, join_cluster):%0D%0A        sudo('rabbitmqctl stop_app')%0D%0A        sudo('rabbitmqctl join_cluster %25s' %25 join_cluster)%0D%0A        sudo('rabbitmqctl start_app')%0D%0A        sudo('rabbitmqctl set_policy ha-all %5C'%5E(?!amq%5C.).*%5C' %5C'%7B%22ha-mode%22: %22all%22%7D%5C'')%0D%0A%0D%0A%0D%0Adef main():%0D%0A    target = RabbitMq(user=args.user, hosts=args.hosts.split(','))%0D%0A%0D%0A    if args.install:%0D%0A        execute(target._install, args.erlang_cookie, args.rabbit_user, args.rabbit_pass)%0D%0A    %0D%0A    if args.join_cluster:%0D%0A        execute(target._join_cluster, args.join_cluster)%0D%0A%0D%0Aif __name__ == '__main__':%0D%0A    main()

Add RabbitMQ HA