文章目录  
 一、安装nginx 二、安装mysql 三、安装php 测试:   
  
 
 一、安装nginx  
- name: the nginx play
  hosts: webservers
  remote_user: root
  tasks:
  - name: stop firewalld                 #关闭防火墙
    service: name=firewalld state=stopped enabled=no
  - name: selinux stop
    command: '/usr/sbin/setenforce 0'
  - name: mount dev                      #挂载光盘
    mount: src=/dev/sr0 path=/mnt state=mounted fstype=iso9660
    ignore_errors: true
  - name: copy nginx.repo                #nginx源
    copy: src=/etc/yum.repos.d/nginx.repo dest=/etc/yum.repos.d
  - name: install nginx
    yum: name=nginx state=latest
    ignore_errors: true
  - name: restart nginx
    service: name=nginx state=started enabled=yes
    ignore_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: webservers
  remote_user: root
  tasks:
  - name: copy mysql file
    copy: src=/etc/yum.repos.d/mysql57-community-release-el7-11.noarch.rpm dest=/etc/yum.repos.d/
  - name: yum mysql
    shell: 'cd /etc/yum.repos.d&&rpm -ivh mysql57-community-release-el7-11.noarch.rpm'
    ignore_errors: true
  - name: replace
    replace: path=/etc/yum.repos.d/mysql-community.repo regexp="gpgcheck=1" replace="gpgcheck=0"
  - name: yum mysql-server
    yum: name=mysql-server state=installed
    ignore_errors: true
  - name: start mysql
    service: name=mysqld.service state=restarted enabled=yes
  - name: mysql.sh
    script: /opt/mysql.sh
    ignore_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 play
  gather_facts: false
  hosts: webservers
  remote_user: root
  tasks:
  - name: copy php
    copy: src=/etc/yum.repos.d/epel.repo dest=/etc/yum.repos.d/
  - name: copy php1
    copy: src=/etc/yum.repos.d/epel-testing.repo dest=/etc/yum.repos.d/
  - name: copy php2
    copy: src=/etc/yum.repos.d/webtatic-archive.repo dest=/etc/yum.repos.d/
  - name: copy php3
    copy: src=/etc/yum.repos.d/webtatic.repo dest=/etc/yum.repos.d/
  - name: copy php4
    copy: src=/etc/yum.repos.d/webtatic-testing.repo dest=/etc/yum.repos.d/
  - name: yum php
    shell: 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-opcache
    ignore_errors: true
  - name: start php
    service: name=php-fpm state=started
  - name: copy nginx.conf
    copy: src=/etc/nginx/conf.d/default.conf dest=/etc/nginx/conf.d/
  - name: start nginx
    service: name=nginx state=restarted
  - name: copy index.php
    copy: src=/usr/share/nginx/html/index.php dest=/usr/share/nginx/html/
  
 
 测试: