huhahapz 发表于 2018-7-28 14:04:18

ansible-playbook安装keepalived-指定tags安装MASTER或BACKUP

---  
- name: "安装keepalived"
  
yum:
  
    name: keepalived
  
    state: present
  
- name: "复制检测、通知脚本"
  
copy:
  
    src={{ item }}
  
    dest=/etc/keepalived/
  
    mode=755
  
with_items:
  
    - check_nginx.sh
  
    - notify.sh
  
- name: "复制配置文件"
  
template:
  
    src=keepalived_master.conf.j2
  
    dest=/etc/keepalived/keepalived.conf
  
- name: "配置keepalived日志格式"
  
lineinfile:
  
    path: /etc/sysconfig/keepalived
  
    regexp: 'KEEPALIVED_OPTIONS="-D"'
  
    line: 'KEEPALIVED_OPTIONS="-D -S 3"'
  
    backrefs: no
  
- name: "创建日志目录"
  
file:
  
    path: /var/log/keepalived
  
    state: directory
  
- name: "配置rsyslog中关于keepalived的"
  
lineinfile:
  
    path: /etc/rsyslog.conf
  
    insertafter: 'local7.*                                                /var/log/boot.log'
  
    line: 'local3.*                                                /var/log/keepalived/keepalived.log'
  
- name: "配置日志的udp"
  
lineinfile:
  
    path: /etc/rsyslog.conf
  
    insertafter: 'UDPServerRun 514'
  
    line: '$ModLoad imudp'
  
- name: "配置日志的udp"
  
lineinfile:
  
    path: /etc/rsyslog.conf
  
    insertafter: 'UDPServerRun 514'
  
    line: '$UDPServerRun 514'
  
- name: "重启日志"
  
service:
  
    name=rsyslog
  
    state=restarted
  
- name: "启动keepalived,设置开机自动启动"
  
service:
  
    name=keepalived
  
    state=started
  
    enabled=yes
页: [1]
查看完整版本: ansible-playbook安装keepalived-指定tags安装MASTER或BACKUP