使用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环境的更多相关文章

  1. yum安装LAMP环境与管理(七)

    [教程主题]:yum安装LAMP环境与管理 [1] 什么是LAMP 目前世界最流行的企业建站方式是LAMP(Linux+Apache+MySQL+PHP),即使用Linux作为操作系统,Apache作 ...

  2. centos 安装卸载软件命令 & yum安装LAMP环境

    安装一个软件时 yum -y install httpd 安装多个相类似的软件时 yum -y install httpd* 安装多个非类似软件时 yum -y install httpd php p ...

  3. yum安装LAMP环境与管理

    yum安装LAMP环境与管理 参考:http://www.zixue.it/ yum添加163源 地址: http://mirrors.163.com/.help/centos.html 下载方式: ...

  4. 将php网站移到CentOS 6.7上[一]:yum安装lamp环境

    最近应老师要求,将一个网站从51php上转移到学校提供的服务器上,之前对Linux没有了解,一切都在百度百度百度.于是发现很多步骤自己做过后就忘了,现将有效步骤记录下来,以供下次参考. 原51php上 ...

  5. centos7.2 yum安装lamp环境

    一.准备工作 1.   下载并安装centos7.2,配置好网络环境,确保centos能上网,可以获取到yum源. centos7.2的下载地址:http://pan.baidu.com/s/1eRT ...

  6. CentOS 7.4 yum安装LAMP环境

    配置防火墙,开启80.3306端口.CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. #停止firewall服务 systemctl stop firewa ...

  7. linux centos yum安装LAMP环境

    centos 6.5 1.yum安装和源代码编译在使用的时候没啥区别,但是安装的过程就大相径庭了,yum只需要3个命令就可以完成,源代码需要13个包,还得加压编译,步骤很麻烦,而且当做有时候会出错,源 ...

  8. yum安装lamp环境

    装了好些次lamp环境了,都没好好总结下,现在总结下 ^ ^ 1.替换163的yum源 1.检查系统版本 cat /etc/redhat-releas   (我的版本是CentOS release 6 ...

  9. Linux之yum安装LAMP环境与管理

    [1] 什么是LAMP 目前世界最流行的企业建站方式是LAMP(Linux+Apache+MySQL+PHP),即使用Linux作为操作系统,Apache作为Web服务器,MySQL作为数据库,PHP ...

随机推荐

  1. js测试

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. List、Set、Map集合大杂烩

    java集合主要分三种:list.set.map:当中list和set都继承自Collection接口,两者最大差别是set不能包括反复元素 list的经常使用实现类有: ArrayList:大小可变 ...

  3. TCP/IP各层协议数据格式

    ISO规范里定义了7层网络模型,实际常用的仍为TCPIP四层网络模型. 注:本文章插图均来自<图解TCP/IP>. 数据链路层帧格式 经常说的帧格式为以太网帧格式,由于类型和帧长度字段不重 ...

  4. hdu6038 Function 函数映射

    /** 题目:hdu6038 Function 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6038 题意:给定一个a排列[0,n-1],一个b排列[0, ...

  5. 用阿里云搭建Http代理服务器

    先说下我的运行环境: Ubuntu16.04+python3.5,用的是阿里云ECS乞丐版. 搭建步骤: [python] view plain copy 0. 直接用xshell或putty远程到云 ...

  6. Could not load type ‘System.ServiceModel.Activation.HttpModule’ from&

    1. 部署网站到IIS7.5,Window 2008的时候出现这个错误   2. 错误信息 Server Error in ‘/’ Application. Could not load type ‘ ...

  7. 网易研发project师(移动端游戏)—暑期实习生电面题目 2014年5月14日

    2014年5月14日 暑期实习生电话面试: 首先自我介绍. 一.C++ 1.extern的使用方法 2.虚函数 3.强制转换 4.malloc和new的差别 二.计算机网络 1.TCP和UDP有什么差 ...

  8. 【PyQt】分析承载界面

    承载界面: # coding=utf-8 import sys from PyQt4.QtCore import * from PyQt4.QtGui import * import class_da ...

  9. (转)使用.NET Reflector 查看Unity引擎里面的DLL文件

    当你查看unity里面API的时候,是不是有时候追踪了一两步就碰到DLL文件走不下去了呢?很是不爽吧. 这种问题我也是经常碰到.这是人家商业引擎不想让你看到底层代码啦,所以着急不得. 不过,今天我终于 ...

  10. VC++ Debug产生异常时中断程序执行Break on Exception

    It is possible to instruct the debugger to break when an exception occurs, before a handler is invok ...