使用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. (译)Getting Started——1.3.3 Working with Foundation(使用Foundation框架)

    在你使用Objective-C语言开发应用时,你会发现在开发中,你会用到很多框架.尤其是Foundation框架,该框架为应用提供了最基础的服务.Foundation框架包括了代表着基本数据类型的va ...

  2. CentOS 7 ifconfig: command not found

    # ifcon-bash: ifconfig: command not found谷歌了一下,整理了一下解决思路 查看ifconfig命令是否存在 查看 /sbin/ifconfig是否存在 如果if ...

  3. Oracle的REGEXP_INSTR函数简单使用方法

    REGEXP_INSTR函数让你搜索一个正則表達式模式字符串. 函数使用输入字符集定义的字符进行字符串的计算. 它返回一个整数,指示開始或结束匹配的子位置.这取决于return_option參数的值. ...

  4. Django - 安装filebrowser发生Error finding Upload-Folder错误

    Error finding Upload-Folder (site.storage.location + site.directory). Maybe it does not exist? 解决: F ...

  5. 检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046} 的组件时失败解决方案

    第一种方法测试过可用:地址:http://download.csdn.net/detail/itjjfamily/8853509 下面是第二种: .NET导出Excel遇到的80070005错误的解决 ...

  6. (转)memcache缓存

    转自:http://369369.blog.51cto.com/319630/833234/ memcache分布式缓存 Memcache知识点梳理 Memcached概念:    Memcached ...

  7. (转)ReentrantLock与Synchronized同步区别

    转自:http://blog.csdn.net/fw0124/article/details/6672522 原文:http://www.ibm.com/developerworks/cn/java/ ...

  8. poj 1659(havel算法)

    题目链接:http://poj.org/problem?id=1659 思路:  havel算法的应用: (1)对序列从大到小进行排序. (2)设最大的度数为 t ,把最大的度数置0,然后把最大度数后 ...

  9. CentOS中Apache虚拟主机(virtualHost)设置在/home目录下的若干问题

    在Ubuntu中安装LAMP是非常简单的意见事情.但是在CentOS中却遇到了很多问题. 首先是CentOS中必须手动配置iptables,把80端口开放出来,不然,是访问不到的,开放80端口在/et ...

  10. web前端入坑第五篇:秒懂Vuejs、Angular、React原理和前端发展历史

    秒懂Vuejs.Angular.React原理和前端发展历史 2017-04-07 小北哥哥 前端你别闹 今天来说说 "前端发展历史和框架" 「前端程序发展的历史」 「 不学自知, ...