Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample Playbook to install Nginx from source. Details -> http://tech.furyu.jp/blog/?p=2684
# 以下のコマンドで本番環境用のサーバ構築が実行されます
ansible-playbook -i hosts nginx.yml --extra-vars="server_name=product worker_processes=2" -k
# 開発環境サーバ構築はこちら
ansible-playbook -i hosts nginx.yml --extra-vars="server_name=product worker_processes=2" -k
[test-servers]
192.168.xxx.xxx
#user nobody;
worker_processes {{ worker_processes }};
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main 'remote:$remote_addr\t'
'time:$time_local\t'
'request:$request\t'
'status:$status\t'
'referer:$http_referer\t'
'ua:$http_user_agent';
access_log logs/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name {{ server_name }};
location / {
root html;
index index.html index.htm;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
- hosts: test-servers
user: vagrant
sudo: yes
vars:
nginx_version: '1.2.8'
nginx_dir: "nginx-{{nginx_version}}"
nginx_url: "http://nginx.org/download/{{nginx_dir}}.tar.gz"
install_dir: "/usr/local/nginx"
tasks:
- name: "install-gcc"
action: yum pkg=gcc state=installed
- name: "get-nginx"
command: wget -O /tmp/$nginx_dir.tar.gz $nginx_url creates=/tmp/$nginx_dir.tar.gz
- name: "expand-nginx"
command: tar xzvf $nginx_dir.tar.gz chdir=/tmp creates=/tmp/$nginx_dir
- name: "configure"
command: ./configure --prefix=$install_dir chdir=/tmp/$nginx_dir
- name: "make"
command: make chdir=/tmp/$nginx_dir
- name: "make-install"
command: make install chdir=/tmp/$nginx_dir
- name: "deploy-nginx.conf"
action: template src=./nginx.conf.j2 dest=$install_dir/conf/nginx.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.