一、目录环境
[root@wd-code deploy_nginx]# tree . ├── hosts ├── roles │ ├── common │ │ └── tasks │ │ └── main.yml │ └── nginx │ ├── files │ │ └── nginx-1.14.0.tar.gz │ ├── tasks │ │ └── main.yml │ ├── templates │ └── vars │ └── main.yml └── site.yml 8 directories, 6 files
二、common目录为公共目录
main.yml文件
--- - name: Install deps yum: name={{ item }} state=present #become: true #become_user: root #become_method: su with_items: - gcc - make - zlib-devel - openssl-devel - pcre-devel - pcre - zlib - openssl
三、nginx目录下
tasks目录下main.yml文件
--- - name: Copy Nginx copy: src=nginx-1.14.0.tar.gz dest=/tmp - name: tar nginx unarchive: src: /tmp/nginx-1.14.0.tar.gz dest: "{{ install_bashdir }}" copy: no - name: Install Nginx shell: "cd {{ install_bashdir }}/nginx-1.14.0 && ./configure --prefix={{ install_bashdir }}/nginx --user={{ nginx_user }} --group={{ nginx_group }} --with-http_stub_status_module --with-http_ssl_module && make && make install" - name: chown work Permission file: dest={{ install_bashdir }}/nginx owner={{ nginx_user }} group={{ nginx_user }} recurse=yes - name: remove nginx package file: dest={{ install_bashdir }}/nginx-1.14.0 state=absent #- name: start nginx # shell: cd "{{ install_bashdir }}" && nginx/sbin/nginx
四、vars变量目录
main.yml文件
install_bashdir: /home/work
nginx_user: root
nginx_group: root
五、入口文件site.yml
site.yml
--- - hosts: nginx gather_facts: no remote_user: root roles: - role: common - role: nginx