此文章接Ansible-角色部署LAMP
配置主机
[root@ansible ~]# cd /etc/ansible/
[root@ansible ansible]# ls
ansible.cfg hosts httpd.yml mysqld.yml php.yml roles
[root@ansible ansible]# vim hosts
[dev]
node1
node2
[harproxy]
node3
创建角色
[root@ansible ansible]# cd roles/
[root@ansible roles]# ls
apache mysql php
[root@ansible roles]# ansible-galaxy init httpd
- Role httpd was created successfully
[root@ansible roles]# ansible-galaxy init haproxy
- Role haproxy was created successfully
[root@ansible roles]# ls
apache haproxy httpd mysql php
通过httpd角色部署web站点
tasks任务
[root@ansible roles]# vim httpd/tasks/main.yml
---
# tasks file for httpd
- name: set firewalld
service:
name: firewalld
state: stopped
enabled: no
- name: stop selinux
lineinfile:
path: /etc/sysconfig/selinux
regexp: '^SELINUX='
line: 'SELINUX=disabled'
- name: setenforce 0
shell: setenforce 0
- name: install httpd
yum:
name: httpd
state: present
- name: index.html.j2
template:
src: index.html.j2
dest: /var/www/html/index.html
- name: restart httpd
service:
name: httpd
state: restarted