| [root@m01 roles]# vim /etc/ansible/hosts |
| [lb_server] |
| lb01 ansible_ssh_pass='1' |
| lb02 ansible_ssh_pass='1' |
| |
| [web_group] |
| web01 ansible_ssh_pass='1' |
| web02 ansible_ssh_pass='1' |
| |
| [nfs_server] |
| nfs ansible_ssh_pass='1' |
| |
| [rsync_server] |
| backup ansible_ssh_pass='1' |
| |
| [db_server] |
| db01 ansible_ssh_pass='1' |
| |
| [nginx:children] |
| web_group |
| lb_server |
| [root@m01 roles] |
| 10.0.0.4 lb01 |
| 10.0.0.5 lb02 |
| 10.0.0.7 web01 |
| 10.0.0.8 web02 |
| 10.0.0.31 nfs |
| 10.0.0.41 backup |
| 10.0.0.51 db01 |
| [root@m01 roles] |
| - hosts: all |
| tasks: |
| - name: Stop Firewalld |
| systemd: |
| name: firewalld |
| state: stopped |
| enabled: no |
| |
| - name: Stop Selinux |
| selinux: |
| state: disabled |
| |
| - name: Create www Group |
| group: |
| name: www |
| gid: 666 |
| state: present |
| when: ansible_fqdn != "db01" |
| |
| - name: Create www User |
| user: |
| name: www |
| uid: 666 |
| group: www |
| shell: /sbin/nologin |
| create_home: false |
| state: present |
| when: ansible_fqdn != "db01" |
| [root@m01 roles]# cd nginx/files/ |
| [root@m01 files]# ll |
| total 772 |
| -rw-r--r-- 1 root root 784272 Dec 10 09:13 nginx-1.16.1-1.el7.ngx.x86_64.rpm |
| -rw-r--r-- 1 root root 641 Dec 24 17:16 nginx.conf |
| [root@m01 roles] |
| - hosts: nginx |
| tasks: |
| - name: Push nginx rpm |
| copy: src: nginx-1.16.1-1.el7.ngx.x86_64.rpm |
| dest: /tmp/ |
| |
| - name: Install Nginx Server |
| yum: |
| name: /tmp/nginx-1.16.1-1.el7.ngx.x86_64.rpm |
| state: present |
| |
| - name: Config Nginx Server |
| copy: |
| src: nginx.conf |
| dest: /etc/nginx/ |
| notify: restart_nginx |
| |
| - name: Start Nginx Server |
| systemd: |
| name: nginx |
| state: started |
| [root@m01 roles] |
| - name: restart_nginx |
| systemd: |
| name: nginx |
| state: restarted |
| [root@m01 roles] |
| [root@m01 files] |
| total 19508 |
| -rw-r--r-- 1 root root 62646 Dec 21 11:04 php.ini |
| -rw-r--r-- 1 root root 19889622 Nov 22 15:52 php.tar.gz |
| -rw-r--r-- 1 root root 17962 Dec 22 15:10 www.conf |
| [root@m01 roles] |
| - hosts: web_group |
| tasks: |
| - name: Tar php Package |
| unarchive: |
| src: php.tar.gz |
| dest: /tmp/ |
| |
| - name: Check php Install Status |
| shell: "rpm -qa | grep php | wc -l" |
| register: get_php_install_status |
| changed_when: false |
| |
| - name: Install php Server |
| shell: "yum localinstall -y /tmp/*.rpm" |
| when: get_php_install_status.stdout_lines == 0 |
| |
| - name: Config php Server |
| copy: |
| src: "{{ item.src }}" |
| dest: "{{ item.dest }}" |
| with_items: |
| - { src: "php.ini", dest: "/etc" } |
| - { src: "www.conf", dest: "/etc/php-fpm.d/" } |
| notify: restart_php |
| |
| - name: Start php Server |
| systemd: |
| name: php-fpm |
| state: started |
| [root@m01 roles] |
| - name: restart_php |
| systemd: |
| name: php-fpm |
| state: restarted |