使用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. 关于EasyUI的Layout总结

    版权声明:本文为博主原创文章,未经博主允许不得转载. 1.layout以html标签方式建立的 <div id="content" region="center&q ...

  2. springBoot文档地址

    文档: https://www.gitbook.com/book/qbgbook/spring-boot-reference-guide-zh/details 配置: http://docs.spri ...

  3. ubuntu1204-gedit中文乱码

    1 在界面上使用ALT-F2打开"执行应用程序"界面. 2 输入dconf-editor.然后点击"执行"打开"Configuration Edito ...

  4. 可以输入也可以下拉选择的select

    网址:http://www.helloweba.com/view-blog-348.html 示例:http://www.helloweba.com/demo/2016/editable-select ...

  5. shell学习三十八天----运行顺序和eval

    运行顺序和eval shell从标准输入或脚本中读取的每一行称为管道,它包括了一个或多个命令,这些命令被一个或多个管道字符(|)隔开. 其实嗨哟非常多特殊符号可用来切割单个的命令:分号(;),管道(| ...

  6. CSS样式设置

    转载来自:http://www.imooc.com/article/2067水平居中设置-行内元素 水平居中 如果被设置元素为文本.图片等行内元素时,水平居中是通过给父元素设置 text-align: ...

  7. MathType编辑书名号的方法有哪些

    MathType作为一款数学公式编辑器,其功能是非常全面的,大家都知道它可以非常方便的编辑各种数据公式和符号.比如书名号.对于这个符号大家的印象是在文科方面用得比较多,其实在数学领域也是常常会用到的, ...

  8. 利用Fiddler或Charles进行mock数据

    使用场景:服务器数据不符合测试条件时,我们可以通过在本地创建虚拟数据来打到测试用例所描述的条件. fiddler使用方法 1.首先在本地创建txt数据:将抓到的response中的json数据拷贝到记 ...

  9. 【BZOJ2055】80人环游世界 有上下界费用流

    [BZOJ2055]80人环游世界 Description     想必大家都看过成龙大哥的<80天环游世界>,里面的紧张刺激的打斗场面一定给你留下了深刻的印象.现在就有这么     一个 ...

  10. org.apache.zookeeper.ClientCnxn - Got ping response for sessionid: 0x160fd6f04410017 after 0ms

    dubbo报错: org.apache.zookeeper.ClientCnxn - Got ping response for sessionid: 0x160fd6f04410017 after ...