ansible-構建NGINX

playbook編寫編譯安裝NGINX劇本nginx

 

劇本以下:shell

[dwchensenwen@vms20 script]$ cat nginx.yaml 
---
- hosts: test
  become: yes
  become_method: sudo
  tasks:
  - name: 安裝依賴包
    yum: name={{ item }} state=latest
    with_items:
      - pcre-devel
      - openssl-devel

  - name: 建立一個管理nginx進程的虛擬用戶
    user: name=www shell=/sbin/nologin/ state=present

  - name: 建立目錄
    command: >
      mkdir -p /server/tools
      mkdir -p /application       

  - name: 下載nginx軟件包
    get_url: 
      url: http://nginx.org/download/nginx-1.12.2.tar.gz
      dest: /server/tools/nginx-1.12.2.tar.gz
      mode: 0755

  - name: 解壓NGINX軟件包
    command: >
      tar -C /server/tools -xvf /server/tools/nginx-1.12.2.tar.gz

  - name: 編譯安裝NGINX
    shell: cd /server/tools/nginx-1.12.2;./configure --prefix=/application/nginx-1.12.2 --user=www --group=www --with-http_ssl_module --with-http_stub_status_module;make && make install

  - name: nginx程序軟件建立連接目錄
    file: src=/application/nginx-1.12.2 dest=/application/nginx state=link

  - name: 啓動NGINX程序服務
    shell: /application/nginx/sbin/nginx

運行結果:瀏覽器

查看遠端NGINX服務app

 

本地瀏覽器訪問:url

相關文章
相關標籤/搜索