角色部署haproxy实现轮询
一,部署apache
添加主机清单
[root@ansible ~]# cd /etc/ansible/
[root@ansible ansible]# vim hosts
[webservers]
node1
node2
[haproxy]
node3
定义角色
[root@ansible roles]# ansible-galaxy init httpd
- Role httpd was created successfully
部署tasks任务
[root@ansible roles]# cd httpd/
[root@ansible httpd]# ls
defaults files handlers meta README.md tasks templates tests vars
[root@ansible httpd]# vim tasks/main.yml
[root@ansible httpd]# cat tasks/main.yml
---
# tasks file for httpd
- name: stop firewalld
state: stopped
enabled: no
- name: selinux
lineinfile:
path: /etc/selinux/config
regexp: '^SELINUX='
line: SELINUX=disabled
- name: selinux1
shell:
cmd: setenforce 0
- name: mount
mount:
src: /dev/cdrom
path: /mnt
fstype: iso9660
state: mounted
- name: repo1
yum_repository:
name: baseos
description: baseos1
file: server
baseurl: file:///mnt/BaseOS
enabled: yes
gpgcheck: no
- name: repo2
yum_repository:
name: appsteram
description: appstream
file: server
baseurl: file:///mnt/AppStream
enabled: yes
gpgcheck: no
- name: install httpd
yum:
name: httpd
state: present
- name: index.html
template:
src: index.html.j2
dest: /var/www/html/index.html
- name: start httpd
service:
name: httpd
state: restarted
enabled: yes
编写index.html.j2模板
[root@ansible httpd]# vim templates/index.html.j2
[root@ansible httpd]# cat templates/index.html.j2
welcome to {