使用ansible 完成yum安装lamp环境
使用ansible 完成yum安装lamp环境
[root@node2 ~]# cd /etc/ansible/playbook/
[root@node2 playbook]# ls
lamp
[root@node2 playbook]# tree lamp/
lamp/
├── group_vars
│ └── lamp-vars
├── hosts
├── roles
│ ├── init_sys
│ │ └── tasks
│ │ └── mail.yml
│ └── install
│ ├── handlers
│ │ └── main.yml
│ ├── tasks
│ │ ├── install_apache.yml
│ │ ├── install_mysql.yml
│ │ ├── install_php.yml
│ │ └── main.yml
│ └── templates
│ ├── httpd.conf
│ └── phpinfo.php
└── site.yml
8 directories, 11 files
变量文件
[root@node2 lamp]# cat group_vars/lamp-vars
pkg1: httpd
pkg2: mariadb
pkg3: mariadb-server
pkg4: php
pkg5: php-mysql
系统初始化(禁用SElinux,停止防火墙,配置yum源)
[root@node2 lamp]# cat roles/init_sys/tasks/mail.yml
---
- name: configure yum.repo
shell: yum instal yum install http://mirrors.163.com/centos/7.4.1708/extras/x86_64/Packages/epel-release-7-9.noarch.rpm -y
- name: stop firewalld
shell: systemctl stop firewalld
- name: disable firewalld
shell: systemctl disable firewalld
- name: stop selinux
shell: sed 's/=permissive/=disabled/' /etc/selinux/config | setenforce 0
安装apache
[root@node2 lamp]# cat roles/install/tasks/install_apache.yml
---
- name: install apache
yum: name=httpd state=installed
- name: start apache
command: systemctl start httpd
- name: deploy apache rules
template: src=/etc/ansible/playbook/lamp/roles/install/templates/httpd.conf dest=/etc/httpd/conf/httpd.conf
notify: restart apache
- name: wait for apache to start
wait_for: port=80
安装mysql
[root@node2 lamp]# cat roles/install/tasks/install_mysql.yml
---
- nmae: install mysql
yum: pkg={{ pkg2 }} state=latest
- name: install mysql-sever
yum: pkg={{ pkg3 }} state=latest
- name: start mysql
command: systemctl start mariadb
安装php
[root@node2 lamp]# cat roles/install/tasks/install_php.yml
---
- name: install php
yum: pkg={{ pkg4 }} state=latest
- name: install php-mysql
yum: pkg={{ pkg5 }} state=latest
- name: /var/www/html
template: src=/etc/ansible/playbook/lamp/roles/install/templates/phpinfo.php dest=/var/www/html/phpinfo.php
notify: restart mysql
- name: wait for mysql to start
wait_for: port=3306
调用notify,当notify中有触发动作时调用
[root@node2 lamp]# cat roles/install/handlers/main.yml
---
- name: restart apache
service: name=apache state=restarted
- name: restart mysql
service: name=mysql state=restarted
模板文件
1)cat roles/install/templates/httpd.conf
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName 192.168.138.13:80
.....................................................
.........................省略
2)[root@node2 lamp]# cat roles/install/templates/phpinfo.php
======================================================================
this is a test web
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
入口文件
[root@node2 lamp]# cat site.yml
---
- hosts: lamp-vars
remote_user: root
roles:
- init_sys
- install
使用ansible 完成yum安装lamp环境的更多相关文章
- yum安装LAMP环境与管理(七)
[教程主题]:yum安装LAMP环境与管理 [1] 什么是LAMP 目前世界最流行的企业建站方式是LAMP(Linux+Apache+MySQL+PHP),即使用Linux作为操作系统,Apache作 ...
- centos 安装卸载软件命令 & yum安装LAMP环境
安装一个软件时 yum -y install httpd 安装多个相类似的软件时 yum -y install httpd* 安装多个非类似软件时 yum -y install httpd php p ...
- yum安装LAMP环境与管理
yum安装LAMP环境与管理 参考:http://www.zixue.it/ yum添加163源 地址: http://mirrors.163.com/.help/centos.html 下载方式: ...
- 将php网站移到CentOS 6.7上[一]:yum安装lamp环境
最近应老师要求,将一个网站从51php上转移到学校提供的服务器上,之前对Linux没有了解,一切都在百度百度百度.于是发现很多步骤自己做过后就忘了,现将有效步骤记录下来,以供下次参考. 原51php上 ...
- centos7.2 yum安装lamp环境
一.准备工作 1. 下载并安装centos7.2,配置好网络环境,确保centos能上网,可以获取到yum源. centos7.2的下载地址:http://pan.baidu.com/s/1eRT ...
- CentOS 7.4 yum安装LAMP环境
配置防火墙,开启80.3306端口.CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. #停止firewall服务 systemctl stop firewa ...
- linux centos yum安装LAMP环境
centos 6.5 1.yum安装和源代码编译在使用的时候没啥区别,但是安装的过程就大相径庭了,yum只需要3个命令就可以完成,源代码需要13个包,还得加压编译,步骤很麻烦,而且当做有时候会出错,源 ...
- yum安装lamp环境
装了好些次lamp环境了,都没好好总结下,现在总结下 ^ ^ 1.替换163的yum源 1.检查系统版本 cat /etc/redhat-releas (我的版本是CentOS release 6 ...
- Linux之yum安装LAMP环境与管理
[1] 什么是LAMP 目前世界最流行的企业建站方式是LAMP(Linux+Apache+MySQL+PHP),即使用Linux作为操作系统,Apache作为Web服务器,MySQL作为数据库,PHP ...
随机推荐
- maven将依赖打入jar包并制定main方法
<build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId& ...
- ubuntu16.0.4 update git
Ubuntu 16.04 comes with Git 2.7.x, which is a little old now. As versions 2.8 & 2.9 are not part ...
- eclipse JavaEE版"javax.servlet.http.HttpServlet" was not found on the Java Build Path问题的解决办法
使用eclipse JavaEE 版,新建 Dynamic Web Project 项目.在项目里添加 JSP 文件,会在文件头部出现错误提示.提示语句为:The superclass "j ...
- smartJS 0.1 API 讲解 - Trigger
上篇介绍了PromiseEvent,本篇介绍Trigger - 基于Promise的aop的体现:(感觉自己的对这些命名一直都很挫,也懒得想了,所以就凑合的用) Trigger 在目标对象上加入触发器 ...
- android手机有多个摄像头,打开其中一个
方法: private Camera openFrontFacingCameraGingerbread() { int cameraCount = 0; Camera cam = null; Came ...
- 如何正确使用Google搜索
“” 双引号表示完全匹配,结果中必须出现与搜索文本完全相同的内容 A -B 搜索包含A但不包含B的结果(请注意A后面的空格不能省略) filetype 搜索对应类型的文件.例如:中国防火墙 filet ...
- 【BZOJ4384】[POI2015]Trzy wieże 树状数组
[BZOJ4384][POI2015]Trzy wieże Description 给定一个长度为n的仅包含'B'.'C'.'S'三种字符的字符串,请找到最长的一段连续子串,使得这一段要么只有一种字符 ...
- iOS UIModalPresentationFormSheet风格下的键盘隐藏
1. 在UIModalPresentationFormSheet(iPad device, without a UINavigationController)下的视图中,如果使用 [inputView ...
- python if x:
# !usr/bin/env python # -*- coding:utf-8 _*- """ @author:happy_code @email: happy_cod ...
- 表达式求值(java)
今天去面试,考了这个,短时间没想出来... 太笨了! 后来想用栈和递归做 但是看了网上才知道,可以将中缀表达式转为后缀表达式,就极其方便了. import java.util.Scanner; imp ...