文章目录 一、安装nginx 二、安装mysql 三、安装php 测试:
一、安装nginx
- name: the nginx playhosts: webserversremote_user: roottasks:- name: stop firewalld #关闭防火墙service: name=firewalld state=stopped enabled=no- name: selinux stopcommand: '/usr/sbin/setenforce 0'- name: mount dev #挂载光盘mount: src=/dev/sr0 path=/mnt state=mounted fstype=iso9660ignore_errors: true- name: copy nginx.repo #nginx源copy: src=/etc/yum.repos.d/nginx.repo dest=/etc/yum.repos.d- name: install nginxyum: name=nginx state=latestignore_errors: true- name: restart nginxservice: name=nginx state=started enabled=yesignore_errors: true
vim /etc/yum.repos.d
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
二、安装mysql
- name: the mysql play#hosts: webserversremote_user: roottasks:- name: copy mysql filecopy: src=/etc/yum.repos.d/mysql57-community-release-el7-11.noarch.rpm dest=/etc/yum.repos.d/- name: yum mysqlshell: 'cd /etc/yum.repos.d&&rpm -ivh mysql57-community-release-el7-11.noarch.rpm'ignore_errors: true- name: replacereplace: path=/etc/yum.repos.d/mysql-community.repo regexp="gpgcheck=1" replace="gpgcheck=0"- name: yum mysql-serveryum: name=mysql-server state=installedignore_errors: true- name: start mysqlservice: name=mysqld.service state=restarted enabled=yes- name: mysql.shscript: /opt/mysql.shignore_errors: true
vim /opt/mysql.sh
passd=$(grep "A temporary password is generated for root@localhost:" /var/log/mysqld.log | awk '{print $NF}')
mysql -uroot -p"$passd" --connect-expired-password -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'Admin@123';"
mysql -uroot -pAdmin@123 -e "grant all privileges on *.* to root@'%' identified by 'Admin@123' with grant option;"
三、安装php
- name: the php playgather_facts: falsehosts: webserversremote_user: roottasks:- name: copy phpcopy: src=/etc/yum.repos.d/epel.repo dest=/etc/yum.repos.d/- name: copy php1copy: src=/etc/yum.repos.d/epel-testing.repo dest=/etc/yum.repos.d/- name: copy php2copy: src=/etc/yum.repos.d/webtatic-archive.repo dest=/etc/yum.repos.d/- name: copy php3copy: src=/etc/yum.repos.d/webtatic.repo dest=/etc/yum.repos.d/- name: copy php4copy: src=/etc/yum.repos.d/webtatic-testing.repo dest=/etc/yum.repos.d/- name: yum phpshell: yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-pdo php72w-xml php72w-fpm php72w-mysqlnd php72w-opcacheignore_errors: true- name: start phpservice: name=php-fpm state=started- name: copy nginx.confcopy: src=/etc/nginx/conf.d/default.conf dest=/etc/nginx/conf.d/- name: start nginxservice: name=nginx state=restarted- name: copy index.phpcopy: src=/usr/share/nginx/html/index.php dest=/usr/share/nginx/html/
测试: