ansible 使用playbook編譯安裝nginx
思路:
安裝nginx的編譯環境
下載檔案、解壓
編譯安裝
playbook:
使用yum、user、get_url、file、unarchive、chmmand這些模塊
yum模塊(官方):安裝多個軟體包
- name: ensure a list of packages installed
yum:
name: “{{ packages }}”
vars:
packages:
- httpd
- httpd-tools
user模塊(官方):創建johnd、指定johnd的uid、并指定組為admin
- name: Add the user ‘johnd’ with a specific uid and a primary group of ‘admin’
user:
name: johnd
uid: 1040
group: admin
get_url模塊(官方):下載并指定目錄
- name: Download foo.conf
get_url:
url: http://example.com/path/file.conf
dest: /etc/foo.conf
mode: ‘0440’
file模塊(官方):創建目錄可指定權限
- name: Create a directory if it does not exist
file:
path: /etc/some_directory
state: directory
mode: ‘0755’
unarchive模塊(官方):解壓檔案并指定目錄
- name: Extract foo.tgz into /var/lib/foo
unarchive:
src: foo.tgz
dest: /var/lib/foo
chmmand模塊:先執行chdir(切換目錄)、再執行/usr/bin…………
- name:
command: /usr/bin/make_database.sh db_user db_name
args:
chdir: somedir/
---
#安裝編譯依賴環境
- name: Install and compile dependent environment
hosts: all
tasks:
- name: install yum
yum:
name: "{{ packages }}"
vars:
packages:
- gcc
- gcc-c++
- autoconf
- automake
- zlib
- zlib-devel
- openssl
- openssl-devel
- pcre
#創建編譯安裝的用戶
- name: Create user
user:
name: nginx
#下載nginx原始碼包
- name: Download the nginx source package
get_url:
url: https://nginx.org/download/nginx-1.18.0.tar.gz
dest: /mnt
#創建目錄
- name: Create a directory
file:
path: /usr/local/nginx
state: directory
#解壓下載的nginx原始碼包
- name: Unzip the nginx source package
unarchive:
src: /mnt/nginx-1.18.0.tar.gz
dest: /mnt/
#編譯安裝、先切換目錄再執行 ./configure
- name: ./configure
command: ./configure --prefix=/usr/local/nginx/ --user=nginx --group=nginx
args:
chdir: /mnt/nginx-1.18.0
- name: make
command: make
args:
chdir: /mnt/nginx-1.18.0
- name: make install
command: make install
args:
chdir: /mnt/nginx-1.18.0
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/189564.html
標籤:其他
