cat redis-install.yml
---
- name: install redis
gather_facts: False
hosts: "{{ ip }}"
user: root
vars:
- redis_port: "{{ port|default(6379) }}"
tasks:
# - name: remove the old file
# file: path={{ redis_home }} state=absent
- name: remove the tmp file
file: path=/tmp/redis* state=absent
- name: Create the dir
file: path={{ item }} state=directory
with_items:
- /etc/redis/
- /tmp/redis/
- "{{ redis_home }}"
- "{{ redis_home }}/data"
- "{{ redis_home }}/data/{{ redis_port }}"
- name: prepare the environment
yum: name={{ item }} state=present
with_items:
- gcc
- gcc-*
- automake
- autoconf
- libtool
- make
- zlib
- zlib-devel
- glibc-*
- tcl
ignore_errors: yes
- name: get libunwind-1.1_tar.gz
get_url: url=http://nongnu.askapache.com/libunwind/libunwind-1.1.tar.gz dest=/tmp/libunwind-1.1.tar.gz
- name: unarchive the libunwind-1.1_tar.gz
unarchive: src=/tmp/libunwind-1.1.tar.gz dest=/tmp/ copy=no
- name: install the libunwind-1.1_tar.gz
shell: cd /tmp/libunwind-1.1/ && ./configure && make && make install
- name: get gperftools-2.5_tar.gz
get_url: url=https://github.com/gperftools/gperftools/releases/download/gperftools-2.5/gperftools-2.5.tar.gz dest=/tmp/gperftools-2.5.tar.gz
- name: unarchive the gperftools-2.5_tar.gz
unarchive: src=/tmp/gperftools-2.5.tar.gz dest=/tmp/ copy=no
- name: install the gperftools-2.5_tar.gz
shell: cd /tmp/gperftools-2.5/ && ./configure && make && make install
- name: ldconfig the /usr/local/lib
shell: echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf && ldconfig
- name: get redis_tar_gz
get_url: url={{ url }} dest=/tmp/redis.tar.gz
- name: unarchive the redis.tar.gz
unarchive: src=/tmp/redis.tar.gz dest=/tmp/redis/ copy=no
- name: install redis to {{ redis_home }}
shell: cd /tmp/redis/ && make PREFIX={{ redis_home }} USE_TCMALLOC=yes install
- name: init the redis_conf
template: src=/ansible/roles/redis/templates/redis.conf.j2 dest=/etc/redis/redis-{{ redis_port }}.conf
- name: init the redis maintain script
template: src=/ansible/roles/redis/templates/redis.sh.j2 dest=/etc/init.d/redis-{{ redis_port }} mode=0755
- name: Start the redis server
shell: /etc/init.d/redis-{{ redis_port }} start
ignore_errors: yes
- name: add redis to chkconfig
shell: chkconfig --level 345 redis-{{ redis_port }} on
ignore_errors: yes使用方法:

ansible-playbook redis-install.yml --extra-vars "{'ip':'redis-server','url':'http://download.redis.io/releases/redis-3.2.0.tar.gz','redis_home':'/usr/local/redis','redis_port':'6380'}"參數(shù)說(shuō)明:
ip:目標(biāo)主機(jī)
url:redis軟件包下載地址
redis_home:redis安裝目錄
redis_port:redis監(jiān)聽(tīng)端口
更多示例參考我的github:https://github.com/miaocbin/ansible-playbooks
歡迎留言交流!
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
網(wǎng)頁(yè)標(biāo)題:ansible-playplaybooks批量安裝redis腳本-創(chuàng)新互聯(lián)
分享鏈接:http://chinadenli.net/article40/dhodeo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、微信小程序、用戶體驗(yàn)、自適應(yīng)網(wǎng)站、服務(wù)器托管、云服務(wù)器
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容