├── .gitignore ├── demo-full ├── hosts-gce ├── hosts-azure ├── hosts-ec2 ├── hosts ├── install-roles.sh ├── templates │ ├── app.upstart.conf.j2 │ ├── app.sysvinit.sh.j2 │ └── app.nginx.conf.j2 ├── requirements.yml ├── Vagrantfile └── playbook.yml ├── demo-0a-simple ├── setup.sh └── Vagrantfile ├── demo-4b-facts ├── handlers │ └── main.yml ├── files │ └── nginx.repo.centos ├── tasks │ ├── main.yml │ ├── use-yum.yml │ └── use-apt.yml ├── playbook.yml ├── templates │ └── nginx.conf.j2 └── Vagrantfile ├── demo-roadmap.jpg ├── demo-5-roles ├── roles │ └── nginx │ │ ├── handlers │ │ └── main.yml │ │ ├── files │ │ └── nginx.repo.centos │ │ ├── tasks │ │ ├── use-yum.yml │ │ ├── main.yml │ │ └── use-apt.yml │ │ └── templates │ │ └── nginx.conf.j2 ├── playbook.yml └── Vagrantfile ├── demo-6-galaxy ├── requirements.yml ├── playbook.yml ├── install-roles.sh └── Vagrantfile ├── demo-0b-simple ├── playbook.yml └── Vagrantfile ├── demo-1a-script ├── Vagrantfile └── setup.sh ├── demo-1b-playbook ├── Vagrantfile └── playbook.yml ├── demo-2a-sed ├── Vagrantfile └── setup.sh ├── demo-2b-variables ├── Vagrantfile └── playbook.yml ├── demo-2c-template ├── Vagrantfile ├── nginx.conf.j2 └── playbook.yml ├── demo-4a-ubuntu-and-debian ├── setup.sh └── Vagrantfile ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant 2 | -------------------------------------------------------------------------------- /demo-full/hosts-gce: -------------------------------------------------------------------------------- 1 | [gce-host] 2 | 111.222.333.444 3 | -------------------------------------------------------------------------------- /demo-full/hosts-azure: -------------------------------------------------------------------------------- 1 | [azure-host] 2 | 111.222.333.444 3 | 4 | -------------------------------------------------------------------------------- /demo-full/hosts-ec2: -------------------------------------------------------------------------------- 1 | [ec2-host] 2 | 111.222.333.444 ansible_ssh_user=ubuntu 3 | -------------------------------------------------------------------------------- /demo-0a-simple/setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | apt-get update 4 | apt-get install -y nginx 5 | -------------------------------------------------------------------------------- /demo-4b-facts/handlers/main.yml: -------------------------------------------------------------------------------- 1 | - name: restart nginx 2 | service: name=nginx state=restarted -------------------------------------------------------------------------------- /demo-roadmap.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/William-Yeh/ansible-tutorial/HEAD/demo-roadmap.jpg -------------------------------------------------------------------------------- /demo-5-roles/roles/nginx/handlers/main.yml: -------------------------------------------------------------------------------- 1 | - name: restart nginx 2 | service: name=nginx state=restarted -------------------------------------------------------------------------------- /demo-6-galaxy/requirements.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - src: williamyeh.nginx 4 | name: nginx 5 | path: roles/ 6 | -------------------------------------------------------------------------------- /demo-0b-simple/playbook.yml: -------------------------------------------------------------------------------- 1 | - hosts: all 2 | tasks: 3 | - name: install Nginx 4 | apt: name=nginx update_cache=yes state=present 5 | -------------------------------------------------------------------------------- /demo-4b-facts/files/nginx.repo.centos: -------------------------------------------------------------------------------- 1 | [nginx] 2 | name=nginx repo 3 | baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ 4 | gpgcheck=0 5 | enabled=1 6 | -------------------------------------------------------------------------------- /demo-full/hosts: -------------------------------------------------------------------------------- 1 | [ec2-host] 2 | 111.222.333.444 ansible_ssh_user=ubuntu 3 | 4 | [gce-host] 5 | 111.222.333.444 6 | 7 | [azure-host] 8 | 111.222.333.444 9 | 10 | -------------------------------------------------------------------------------- /demo-5-roles/roles/nginx/files/nginx.repo.centos: -------------------------------------------------------------------------------- 1 | [nginx] 2 | name=nginx repo 3 | baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ 4 | gpgcheck=0 5 | enabled=1 6 | -------------------------------------------------------------------------------- /demo-5-roles/playbook.yml: -------------------------------------------------------------------------------- 1 | - hosts: all 2 | sudo: True 3 | 4 | roles: 5 | - nginx 6 | 7 | vars: 8 | worker_processes: auto 9 | worker_connections: 10240 10 | -------------------------------------------------------------------------------- /demo-6-galaxy/playbook.yml: -------------------------------------------------------------------------------- 1 | - hosts: all 2 | sudo: True 3 | 4 | roles: 5 | - nginx 6 | 7 | vars: 8 | worker_processes: auto 9 | worker_connections: 10240 10 | -------------------------------------------------------------------------------- /demo-full/install-roles.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # @see http://docs.ansible.com/galaxy.html#advanced-control-over-role-requirements-files 4 | # 5 | 6 | ansible-galaxy install -f -p roles -r requirements.yml 7 | -------------------------------------------------------------------------------- /demo-6-galaxy/install-roles.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # @see http://docs.ansible.com/galaxy.html#advanced-control-over-role-requirements-files 4 | # 5 | 6 | ansible-galaxy install -f -p roles -r requirements.yml 7 | -------------------------------------------------------------------------------- /demo-0b-simple/Vagrantfile: -------------------------------------------------------------------------------- 1 | Vagrant.configure(2) do |config| 2 | config.vm.box = "ubuntu/trusty64" 3 | 4 | config.vm.provision "ansible" do |ansible| 5 | ansible.playbook = "playbook.yml" 6 | ansible.sudo = true 7 | end 8 | 9 | end 10 | -------------------------------------------------------------------------------- /demo-1a-script/Vagrantfile: -------------------------------------------------------------------------------- 1 | Vagrant.configure(2) do |config| 2 | config.vm.box = "ubuntu/trusty64" 3 | 4 | config.vm.provision "shell", path: "setup.sh" 5 | 6 | config.vm.provider "virtualbox" do |v| 7 | v.cpus = 2 8 | end 9 | 10 | end 11 | -------------------------------------------------------------------------------- /demo-1b-playbook/Vagrantfile: -------------------------------------------------------------------------------- 1 | Vagrant.configure(2) do |config| 2 | config.vm.box = "ubuntu/trusty64" 3 | 4 | config.vm.provision "ansible" do |ansible| 5 | ansible.playbook = "playbook.yml" 6 | ansible.sudo = true 7 | end 8 | 9 | end 10 | -------------------------------------------------------------------------------- /demo-2a-sed/Vagrantfile: -------------------------------------------------------------------------------- 1 | Vagrant.configure(2) do |config| 2 | config.vm.box = "ubuntu/trusty64" 3 | 4 | config.vm.provision "shell", path: "setup.sh" 5 | 6 | config.vm.provider "virtualbox" do |v| 7 | v.cpus = 2 8 | end 9 | 10 | end 11 | -------------------------------------------------------------------------------- /demo-4b-facts/tasks/main.yml: -------------------------------------------------------------------------------- 1 | - name: delegate to APT system for installation 2 | include: use-apt.yml 3 | when: ansible_pkg_mgr == "apt" 4 | 5 | - name: delegate to YUM system for installation 6 | include: use-yum.yml 7 | when: ansible_pkg_mgr == "yum" 8 | -------------------------------------------------------------------------------- /demo-full/templates/app.upstart.conf.j2: -------------------------------------------------------------------------------- 1 | description "react-trader" 2 | 3 | start on filesystem 4 | stop on runlevel [!2345] 5 | 6 | respawn 7 | 8 | chdir "{{ project_root }}/current" 9 | script 10 | exec node server.js 2>&1 > /dev/null 11 | end script 12 | -------------------------------------------------------------------------------- /demo-0a-simple/Vagrantfile: -------------------------------------------------------------------------------- 1 | Vagrant.configure(2) do |config| 2 | config.vm.box = "ubuntu/trusty64" 3 | 4 | config.vm.provision "shell", path: "setup.sh" 5 | 6 | #config.vm.provision "shell", inline: <<-SHELL 7 | # apt-get update 8 | # apt-get install -y nginx 9 | #SHELL 10 | 11 | end 12 | -------------------------------------------------------------------------------- /demo-2b-variables/Vagrantfile: -------------------------------------------------------------------------------- 1 | Vagrant.configure(2) do |config| 2 | config.vm.box = "ubuntu/trusty64" 3 | 4 | config.vm.provision "ansible" do |ansible| 5 | ansible.playbook = "playbook.yml" 6 | ansible.sudo = true 7 | end 8 | 9 | config.vm.provider "virtualbox" do |v| 10 | v.cpus = 2 11 | end 12 | 13 | end 14 | -------------------------------------------------------------------------------- /demo-2c-template/Vagrantfile: -------------------------------------------------------------------------------- 1 | Vagrant.configure(2) do |config| 2 | config.vm.box = "ubuntu/trusty64" 3 | 4 | config.vm.provision "ansible" do |ansible| 5 | ansible.playbook = "playbook.yml" 6 | ansible.sudo = true 7 | end 8 | 9 | config.vm.provider "virtualbox" do |v| 10 | v.cpus = 2 11 | end 12 | 13 | end 14 | -------------------------------------------------------------------------------- /demo-4b-facts/tasks/use-yum.yml: -------------------------------------------------------------------------------- 1 | - name: install libselinux-python binary for Ansible to work 2 | yum: name=libselinux-python state=present 3 | 4 | - name: add Nginx official repository for CentOS 5 | copy: src=files/nginx.repo.centos dest=/etc/yum.repos.d/nginx.repo 6 | 7 | - name: install Nginx 8 | yum: name=nginx update_cache=yes state=present 9 | -------------------------------------------------------------------------------- /demo-5-roles/roles/nginx/tasks/use-yum.yml: -------------------------------------------------------------------------------- 1 | - name: install libselinux-python binary for Ansible to work 2 | yum: name=libselinux-python state=present 3 | 4 | - name: add Nginx official repository for CentOS 5 | copy: src=../files/nginx.repo.centos dest=/etc/yum.repos.d/nginx.repo 6 | 7 | - name: install Nginx 8 | yum: name=nginx update_cache=yes state=present 9 | -------------------------------------------------------------------------------- /demo-full/requirements.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - src: williamyeh.nginx 4 | path: roles/ 5 | 6 | - src: williamyeh.nodejs 7 | path: roles/ 8 | 9 | - src: geerlingguy.git 10 | path: roles/ 11 | 12 | - src: https://github.com/William-Yeh/ansible-project_deploy 13 | name: project_deploy 14 | path: roles/ 15 | 16 | - src: williamyeh.init-installer 17 | path: roles/ -------------------------------------------------------------------------------- /demo-1a-script/setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "deb http://nginx.org/packages/ubuntu/ trusty nginx" \ 4 | | sudo tee /etc/apt/sources.list.d/nginx.list 5 | 6 | echo "deb-src http://nginx.org/packages/ubuntu/ trusty nginx" \ 7 | | sudo tee -a /etc/apt/sources.list.d/nginx.list 8 | 9 | curl -sSL http://nginx.org/keys/nginx_signing.key \ 10 | | sudo apt-key add - 11 | 12 | apt-get update 13 | apt-get install -y nginx 14 | -------------------------------------------------------------------------------- /demo-5-roles/roles/nginx/tasks/main.yml: -------------------------------------------------------------------------------- 1 | - name: delegate to APT system for installation 2 | include: use-apt.yml 3 | when: ansible_pkg_mgr == "apt" 4 | 5 | - name: delegate to YUM system for installation 6 | include: use-yum.yml 7 | when: ansible_pkg_mgr == "yum" 8 | 9 | 10 | - name: copy Nginx configuration 11 | template: src=../templates/nginx.conf.j2 dest=/etc/nginx/nginx.conf 12 | notify: 13 | - restart nginx 14 | -------------------------------------------------------------------------------- /demo-4b-facts/playbook.yml: -------------------------------------------------------------------------------- 1 | - hosts: all 2 | sudo: True 3 | 4 | vars: 5 | worker_processes: auto 6 | worker_connections: 10240 7 | 8 | tasks: 9 | 10 | - include: 'tasks/main.yml' 11 | 12 | - name: copy Nginx configuration 13 | template: src=templates/nginx.conf.j2 dest=/etc/nginx/nginx.conf 14 | notify: 15 | - restart nginx 16 | 17 | handlers: 18 | - include: 'handlers/main.yml' 19 | 20 | -------------------------------------------------------------------------------- /demo-full/Vagrantfile: -------------------------------------------------------------------------------- 1 | Vagrant.configure(2) do |config| 2 | 3 | config.vm.box = "ubuntu/trusty64" 4 | #config.vm.box = "ubuntu/precise64" 5 | #config.vm.box = "debian/wheezy64" 6 | #config.vm.box = "bento/centos-7.1" 7 | #config.vm.box = "bento/centos-6.6" 8 | 9 | 10 | config.vm.network "forwarded_port", guest: 80, host: 8080 11 | 12 | config.vm.provision "ansible" do |ansible| 13 | ansible.playbook = "playbook.yml" 14 | ansible.verbose = "vvv" 15 | end 16 | 17 | end 18 | -------------------------------------------------------------------------------- /demo-2a-sed/setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "deb http://nginx.org/packages/ubuntu/ trusty nginx" \ 4 | | sudo tee /etc/apt/sources.list.d/nginx.list 5 | 6 | echo "deb-src http://nginx.org/packages/ubuntu/ trusty nginx" \ 7 | | sudo tee -a /etc/apt/sources.list.d/nginx.list 8 | 9 | curl -sSL http://nginx.org/keys/nginx_signing.key \ 10 | | sudo apt-key add - 11 | 12 | apt-get update 13 | apt-get install -y nginx 14 | 15 | 16 | 17 | sed -i 's/^\(worker_processes\s*\)1;/\1auto;/' \ 18 | /etc/nginx/nginx.conf 19 | 20 | service nginx restart 21 | -------------------------------------------------------------------------------- /demo-1b-playbook/playbook.yml: -------------------------------------------------------------------------------- 1 | - hosts: all 2 | tasks: 3 | 4 | - name: install add-apt-repository binary for Ansible to work 5 | apt: name=python-software-properties state=present update_cache=yes 6 | 7 | - name: add Nginx stable repository (deb) 8 | apt_repository: > 9 | repo='deb http://nginx.org/packages/ubuntu/ trusty nginx' 10 | state=present 11 | 12 | - name: add Nginx stable repository (deb-src) 13 | apt_repository: > 14 | repo='deb-src http://nginx.org/packages/ubuntu/ trusty nginx' 15 | state=present 16 | 17 | - name: add Nginx.org key 18 | apt_key: > 19 | url=http://nginx.org/keys/nginx_signing.key 20 | state=present 21 | 22 | 23 | - name: install Nginx 24 | apt: name=nginx update_cache=yes state=present 25 | -------------------------------------------------------------------------------- /demo-4b-facts/tasks/use-apt.yml: -------------------------------------------------------------------------------- 1 | - name: install add-apt-repository binary for Ansible to work 2 | apt: name=python-software-properties state=present update_cache=yes 3 | 4 | - name: add Nginx stable repository (deb) 5 | apt_repository: > 6 | repo='deb http://nginx.org/packages/{{ ansible_distribution|lower }}/ {{ ansible_distribution_release|lower }} nginx' 7 | state=present 8 | 9 | - name: add Nginx stable repository (deb-src) 10 | apt_repository: > 11 | repo='deb-src http://nginx.org/packages/{{ ansible_distribution|lower }}/ {{ ansible_distribution_release|lower }} nginx' 12 | state=present 13 | 14 | - name: add Nginx.org key 15 | apt_key: > 16 | url=http://nginx.org/keys/nginx_signing.key 17 | state=present 18 | 19 | - name: install Nginx 20 | apt: name=nginx update_cache=yes state=present 21 | -------------------------------------------------------------------------------- /demo-5-roles/roles/nginx/tasks/use-apt.yml: -------------------------------------------------------------------------------- 1 | - name: install add-apt-repository binary for Ansible to work 2 | apt: name=python-software-properties state=present update_cache=yes 3 | 4 | - name: add Nginx stable repository (deb) 5 | apt_repository: > 6 | repo='deb http://nginx.org/packages/{{ ansible_distribution|lower }}/ {{ ansible_distribution_release|lower }} nginx' 7 | state=present 8 | 9 | - name: add Nginx stable repository (deb-src) 10 | apt_repository: > 11 | repo='deb-src http://nginx.org/packages/{{ ansible_distribution|lower }}/ {{ ansible_distribution_release|lower }} nginx' 12 | state=present 13 | 14 | - name: add Nginx.org key 15 | apt_key: > 16 | url=http://nginx.org/keys/nginx_signing.key 17 | state=present 18 | 19 | - name: install Nginx 20 | apt: name=nginx update_cache=yes state=present 21 | -------------------------------------------------------------------------------- /demo-2c-template/nginx.conf.j2: -------------------------------------------------------------------------------- 1 | 2 | user nginx; 3 | worker_processes {{ worker_processes }}; 4 | 5 | error_log /var/log/nginx/error.log warn; 6 | pid /var/run/nginx.pid; 7 | 8 | 9 | events { 10 | worker_connections {{ worker_connections }}; 11 | } 12 | 13 | 14 | http { 15 | include /etc/nginx/mime.types; 16 | default_type application/octet-stream; 17 | 18 | log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 19 | '$status $body_bytes_sent "$http_referer" ' 20 | '"$http_user_agent" "$http_x_forwarded_for"'; 21 | 22 | access_log /var/log/nginx/access.log main; 23 | 24 | sendfile on; 25 | #tcp_nopush on; 26 | 27 | keepalive_timeout 65; 28 | 29 | #gzip on; 30 | 31 | include /etc/nginx/conf.d/*.conf; 32 | } 33 | -------------------------------------------------------------------------------- /demo-4b-facts/templates/nginx.conf.j2: -------------------------------------------------------------------------------- 1 | 2 | user nginx; 3 | worker_processes {{ worker_processes }}; 4 | 5 | error_log /var/log/nginx/error.log warn; 6 | pid /var/run/nginx.pid; 7 | 8 | 9 | events { 10 | worker_connections {{ worker_connections }}; 11 | } 12 | 13 | 14 | http { 15 | include /etc/nginx/mime.types; 16 | default_type application/octet-stream; 17 | 18 | log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 19 | '$status $body_bytes_sent "$http_referer" ' 20 | '"$http_user_agent" "$http_x_forwarded_for"'; 21 | 22 | access_log /var/log/nginx/access.log main; 23 | 24 | sendfile on; 25 | #tcp_nopush on; 26 | 27 | keepalive_timeout 65; 28 | 29 | #gzip on; 30 | 31 | include /etc/nginx/conf.d/*.conf; 32 | } 33 | -------------------------------------------------------------------------------- /demo-5-roles/roles/nginx/templates/nginx.conf.j2: -------------------------------------------------------------------------------- 1 | 2 | user nginx; 3 | worker_processes {{ worker_processes }}; 4 | 5 | error_log /var/log/nginx/error.log warn; 6 | pid /var/run/nginx.pid; 7 | 8 | 9 | events { 10 | worker_connections {{ worker_connections }}; 11 | } 12 | 13 | 14 | http { 15 | include /etc/nginx/mime.types; 16 | default_type application/octet-stream; 17 | 18 | log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 19 | '$status $body_bytes_sent "$http_referer" ' 20 | '"$http_user_agent" "$http_x_forwarded_for"'; 21 | 22 | access_log /var/log/nginx/access.log main; 23 | 24 | sendfile on; 25 | #tcp_nopush on; 26 | 27 | keepalive_timeout 65; 28 | 29 | #gzip on; 30 | 31 | include /etc/nginx/conf.d/*.conf; 32 | } 33 | -------------------------------------------------------------------------------- /demo-full/playbook.yml: -------------------------------------------------------------------------------- 1 | - hosts: all 2 | sudo: True 3 | 4 | roles: 5 | - geerlingguy.git 6 | - williamyeh.nginx 7 | - williamyeh.nodejs 8 | - project_deploy 9 | - williamyeh.init-installer 10 | 11 | vars: 12 | 13 | project_root: "/opt/app" 14 | project_deploy_strategy: git 15 | project_git_repo: "https://github.com/ccoenraets/react-trader.git" 16 | project_has_npm: true 17 | project_copy_previous_npm_modules: true 18 | 19 | nginx_conf_others: 20 | app_1: 21 | src: "templates/app.nginx.conf.j2" 22 | dest: "app.conf" 23 | 24 | init_sysv: 25 | app_1: 26 | src: "templates/app.sysvinit.sh.j2" 27 | dest: "app" 28 | #init_upstart: 29 | # app_1: 30 | # src: "templates/app.upstart.conf.j2" 31 | # dest: "app.conf" 32 | 33 | tasks: 34 | - name: start the app 35 | service: name=app state=started enabled=yes 36 | -------------------------------------------------------------------------------- /demo-2c-template/playbook.yml: -------------------------------------------------------------------------------- 1 | - hosts: all 2 | 3 | vars: 4 | worker_processes: auto 5 | worker_connections: 10240 6 | 7 | tasks: 8 | 9 | - name: install add-apt-repository binary for Ansible to work 10 | apt: name=python-software-properties state=present update_cache=yes 11 | 12 | - name: add Nginx stable repository (deb) 13 | apt_repository: > 14 | repo='deb http://nginx.org/packages/ubuntu/ trusty nginx' 15 | state=present 16 | 17 | - name: add Nginx stable repository (deb-src) 18 | apt_repository: > 19 | repo='deb-src http://nginx.org/packages/ubuntu/ trusty nginx' 20 | state=present 21 | 22 | - name: add Nginx.org key 23 | apt_key: > 24 | url=http://nginx.org/keys/nginx_signing.key 25 | state=present 26 | 27 | - name: install Nginx 28 | apt: name=nginx update_cache=yes state=present 29 | 30 | - name: copy Nginx configuration 31 | template: src=nginx.conf.j2 dest=/etc/nginx/nginx.conf 32 | notify: 33 | - restart nginx 34 | 35 | 36 | handlers: 37 | - name: restart nginx 38 | service: name=nginx state=restarted 39 | 40 | -------------------------------------------------------------------------------- /demo-2b-variables/playbook.yml: -------------------------------------------------------------------------------- 1 | - hosts: all 2 | tasks: 3 | 4 | - name: install add-apt-repository binary for Ansible to work 5 | apt: name=python-software-properties state=present update_cache=yes 6 | 7 | - name: add Nginx stable repository (deb) 8 | apt_repository: > 9 | repo='deb http://nginx.org/packages/ubuntu/ trusty nginx' 10 | state=present 11 | 12 | - name: add Nginx stable repository (deb-src) 13 | apt_repository: > 14 | repo='deb-src http://nginx.org/packages/ubuntu/ trusty nginx' 15 | state=present 16 | 17 | - name: add Nginx.org key 18 | apt_key: > 19 | url=http://nginx.org/keys/nginx_signing.key 20 | state=present 21 | 22 | - name: install Nginx 23 | apt: name=nginx update_cache=yes state=present 24 | 25 | - name: increase Nginx worker_processes 26 | lineinfile: > 27 | dest=/etc/nginx/nginx.conf 28 | regexp="^(worker_processes\s+)1;" 29 | line="\1auto;" 30 | backrefs=yes 31 | notify: 32 | - restart nginx 33 | 34 | handlers: 35 | - name: restart nginx 36 | service: name=nginx state=restarted 37 | 38 | -------------------------------------------------------------------------------- /demo-4a-ubuntu-and-debian/setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -f /etc/lsb-release ]; then # Ubuntu 4 | 5 | . /etc/lsb-release 6 | APT_OS_NAME=${DISTRIB_ID,,} 7 | APT_OS_VERSION=$DISTRIB_CODENAME 8 | 9 | elif [ -f /etc/os-release ]; then # Debian 10 | 11 | . /etc/os-release 12 | APT_OS_NAME=$ID 13 | 14 | if [[ "$VERSION" =~ [0-9]+[[:space:]]+\((.+)\)$ ]]; then 15 | APT_OS_VERSION=${BASH_REMATCH[1]} 16 | else 17 | echo "ERROR: Unknown Debian format..." 18 | exit 1 19 | fi 20 | 21 | else 22 | echo "ERROR: Neithor Debian nor Ubuntu..." 23 | exit 1 24 | fi 25 | 26 | 27 | 28 | echo "deb http://nginx.org/packages/$APT_OS_NAME/ $APT_OS_VERSION nginx" \ 29 | | sudo tee /etc/apt/sources.list.d/nginx.list 30 | 31 | echo "deb-src http://nginx.org/packages/$APT_OS_NAME/ $APT_OS_VERSION nginx" \ 32 | | sudo tee -a /etc/apt/sources.list.d/nginx.list 33 | 34 | curl -sSL http://nginx.org/keys/nginx_signing.key \ 35 | | sudo apt-key add - 36 | 37 | apt-get update 38 | apt-get install -y nginx 39 | 40 | 41 | 42 | sed -i 's/^\(worker_processes\s*\)1;/\1auto;/' \ 43 | /etc/nginx/nginx.conf 44 | 45 | service nginx restart 46 | -------------------------------------------------------------------------------- /demo-4a-ubuntu-and-debian/Vagrantfile: -------------------------------------------------------------------------------- 1 | Vagrant.configure(2) do |config| 2 | 3 | config.vm.define "main", primary: true do |node| 4 | node.vm.box = "ubuntu/trusty64" 5 | node.vm.provision "shell", path: "setup.sh" 6 | node.vm.provider "virtualbox" do |v| 7 | v.customize ["modifyvm", :id, "--memory", "256"] 8 | end 9 | end 10 | 11 | config.vm.define "precise" do |node| 12 | node.vm.box = "ubuntu/precise64" 13 | node.vm.provision "shell", path: "setup.sh" 14 | node.vm.provider "virtualbox" do |v| 15 | v.customize ["modifyvm", :id, "--memory", "256"] 16 | end 17 | end 18 | 19 | config.vm.define "jessie" do |node| 20 | node.vm.box = "debian/jessie64" 21 | node.vm.provision "shell", path: "setup.sh" 22 | node.vm.provider "virtualbox" do |v| 23 | v.customize ["modifyvm", :id, "--memory", "256"] 24 | end 25 | end 26 | 27 | config.vm.define "wheezy" do |node| 28 | node.vm.box = "debian/wheezy64" 29 | node.vm.provision "shell", path: "setup.sh" 30 | node.vm.provider "virtualbox" do |v| 31 | v.customize ["modifyvm", :id, "--memory", "256"] 32 | end 33 | end 34 | 35 | end 36 | -------------------------------------------------------------------------------- /demo-full/templates/app.sysvinit.sh.j2: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | ### BEGIN INIT INFO 4 | # Provides: app 5 | # Required-Start: $all 6 | # Required-Stop: $all 7 | # Default-Start: 2 3 4 5 8 | # Default-Stop: 0 1 6 9 | # Short-Description: starts myapp daemon 10 | # Description: starts myapp daemon 11 | ### END INIT INFO 12 | 13 | # 14 | # @see http://werxltd.com/wp/2012/01/05/simple-init-d-script-template/ 15 | # 16 | 17 | 18 | DAEMON_PATH="{{ project_root }}/current" 19 | 20 | DAEMON=node 21 | DAEMONOPTS="server.js" 22 | 23 | NAME=app 24 | DESC="react-trader sample application" 25 | PIDFILE=/var/run/$NAME.pid 26 | SCRIPTNAME=/etc/init.d/$NAME 27 | 28 | 29 | case "$1" in 30 | start) 31 | printf "%-20s" "Starting $NAME..." 32 | cd $DAEMON_PATH 33 | PID=`$DAEMON $DAEMONOPTS > /dev/null 2>&1 & echo $!` 34 | #echo "Saving PID" $PID " to " $PIDFILE 35 | 36 | if [ -z $PID ]; then 37 | printf "%s\n" "Fail" 38 | else 39 | echo $PID > $PIDFILE 40 | printf "%s\n" "Ok" 41 | fi 42 | ;; 43 | 44 | status) 45 | printf "%-20s" "Checking $NAME..." 46 | if [ -f $PIDFILE ]; then 47 | PID=`cat $PIDFILE` 48 | if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then 49 | printf "%s\n" "Process dead but pidfile exists" 50 | else 51 | echo "Running" 52 | fi 53 | else 54 | printf "%s\n" "Service not running" 55 | fi 56 | ;; 57 | 58 | stop) 59 | printf "%-20s" "Stopping $NAME" 60 | PID=`cat $PIDFILE` 61 | cd $DAEMON_PATH 62 | 63 | if [ -f $PIDFILE ]; then 64 | kill -HUP $PID 65 | printf "%s\n" "Ok" 66 | rm -f $PIDFILE 67 | else 68 | printf "%s\n" "pidfile not found" 69 | fi 70 | ;; 71 | 72 | restart) 73 | $0 stop 74 | $0 start 75 | ;; 76 | 77 | info) 78 | echo $NAME "-" $DESC 79 | ;; 80 | 81 | *) 82 | echo "Usage: $0 {status|start|stop|restart|info}" 83 | exit 1 84 | esac 85 | -------------------------------------------------------------------------------- /demo-5-roles/Vagrantfile: -------------------------------------------------------------------------------- 1 | Vagrant.configure(2) do |config| 2 | 3 | config.vm.define "main", primary: true do |node| 4 | node.vm.box = "ubuntu/trusty64" 5 | node.vm.provision "ansible" do |ansible| 6 | ansible.playbook = "playbook.yml" 7 | end 8 | node.vm.provider "virtualbox" do |v| 9 | v.customize ["modifyvm", :id, "--memory", "256"] 10 | end 11 | end 12 | 13 | 14 | config.vm.define "precise" do |node| 15 | node.vm.box = "ubuntu/precise64" 16 | node.vm.provision "ansible" do |ansible| 17 | ansible.playbook = "playbook.yml" 18 | end 19 | node.vm.provider "virtualbox" do |v| 20 | v.customize ["modifyvm", :id, "--memory", "256"] 21 | end 22 | end 23 | 24 | 25 | config.vm.define "jessie" do |node| 26 | node.vm.box = "debian/jessie64" 27 | node.vm.provision "ansible" do |ansible| 28 | ansible.playbook = "playbook.yml" 29 | end 30 | node.vm.provider "virtualbox" do |v| 31 | v.customize ["modifyvm", :id, "--memory", "256"] 32 | end 33 | end 34 | 35 | 36 | config.vm.define "wheezy" do |node| 37 | node.vm.box = "debian/wheezy64" 38 | node.vm.provision "ansible" do |ansible| 39 | ansible.playbook = "playbook.yml" 40 | end 41 | node.vm.provider "virtualbox" do |v| 42 | v.customize ["modifyvm", :id, "--memory", "256"] 43 | end 44 | end 45 | 46 | 47 | config.vm.define "centos7" do |node| 48 | node.vm.box = "bento/centos-7.1" 49 | node.vm.provision "ansible" do |ansible| 50 | ansible.playbook = "playbook.yml" 51 | ansible.verbose = "vvv" 52 | end 53 | node.vm.provider "virtualbox" do |v| 54 | v.customize ["modifyvm", :id, "--memory", "256"] 55 | end 56 | end 57 | 58 | 59 | config.vm.define "centos6" do |node| 60 | node.vm.box = "bento/centos-6.6" 61 | node.vm.provision "ansible" do |ansible| 62 | ansible.playbook = "playbook.yml" 63 | ansible.verbose = "vvv" 64 | end 65 | node.vm.provider "virtualbox" do |v| 66 | v.customize ["modifyvm", :id, "--memory", "256"] 67 | end 68 | end 69 | 70 | end 71 | -------------------------------------------------------------------------------- /demo-4b-facts/Vagrantfile: -------------------------------------------------------------------------------- 1 | Vagrant.configure(2) do |config| 2 | 3 | config.vm.define "main", primary: true do |node| 4 | node.vm.box = "ubuntu/trusty64" 5 | node.vm.provision "ansible" do |ansible| 6 | ansible.playbook = "playbook.yml" 7 | end 8 | node.vm.provider "virtualbox" do |v| 9 | v.customize ["modifyvm", :id, "--memory", "256"] 10 | end 11 | end 12 | 13 | 14 | config.vm.define "precise" do |node| 15 | node.vm.box = "ubuntu/precise64" 16 | node.vm.provision "ansible" do |ansible| 17 | ansible.playbook = "playbook.yml" 18 | end 19 | node.vm.provider "virtualbox" do |v| 20 | v.customize ["modifyvm", :id, "--memory", "256"] 21 | end 22 | end 23 | 24 | 25 | config.vm.define "jessie" do |node| 26 | node.vm.box = "debian/jessie64" 27 | node.vm.provision "ansible" do |ansible| 28 | ansible.playbook = "playbook.yml" 29 | end 30 | node.vm.provider "virtualbox" do |v| 31 | v.customize ["modifyvm", :id, "--memory", "256"] 32 | end 33 | end 34 | 35 | 36 | config.vm.define "wheezy" do |node| 37 | node.vm.box = "debian/wheezy64" 38 | node.vm.provision "ansible" do |ansible| 39 | ansible.playbook = "playbook.yml" 40 | end 41 | node.vm.provider "virtualbox" do |v| 42 | v.customize ["modifyvm", :id, "--memory", "256"] 43 | end 44 | end 45 | 46 | 47 | config.vm.define "centos7" do |node| 48 | node.vm.box = "bento/centos-7.1" 49 | node.vm.provision "ansible" do |ansible| 50 | ansible.playbook = "playbook.yml" 51 | ansible.verbose = "vvv" 52 | end 53 | node.vm.provider "virtualbox" do |v| 54 | v.customize ["modifyvm", :id, "--memory", "256"] 55 | end 56 | end 57 | 58 | 59 | config.vm.define "centos6" do |node| 60 | node.vm.box = "bento/centos-6.6" 61 | node.vm.provision "ansible" do |ansible| 62 | ansible.playbook = "playbook.yml" 63 | ansible.verbose = "vvv" 64 | end 65 | node.vm.provider "virtualbox" do |v| 66 | v.customize ["modifyvm", :id, "--memory", "256"] 67 | end 68 | end 69 | 70 | end 71 | -------------------------------------------------------------------------------- /demo-6-galaxy/Vagrantfile: -------------------------------------------------------------------------------- 1 | Vagrant.configure(2) do |config| 2 | 3 | config.vm.define "main", primary: true do |node| 4 | node.vm.box = "ubuntu/trusty64" 5 | node.vm.provision "ansible" do |ansible| 6 | ansible.playbook = "playbook.yml" 7 | end 8 | node.vm.provider "virtualbox" do |v| 9 | v.customize ["modifyvm", :id, "--memory", "256"] 10 | end 11 | end 12 | 13 | 14 | config.vm.define "precise" do |node| 15 | node.vm.box = "ubuntu/precise64" 16 | node.vm.provision "ansible" do |ansible| 17 | ansible.playbook = "playbook.yml" 18 | end 19 | node.vm.provider "virtualbox" do |v| 20 | v.customize ["modifyvm", :id, "--memory", "256"] 21 | end 22 | end 23 | 24 | 25 | config.vm.define "jessie" do |node| 26 | node.vm.box = "debian/jessie64" 27 | node.vm.provision "ansible" do |ansible| 28 | ansible.playbook = "playbook.yml" 29 | end 30 | node.vm.provider "virtualbox" do |v| 31 | v.customize ["modifyvm", :id, "--memory", "256"] 32 | end 33 | end 34 | 35 | 36 | config.vm.define "wheezy" do |node| 37 | node.vm.box = "debian/wheezy64" 38 | node.vm.provision "ansible" do |ansible| 39 | ansible.playbook = "playbook.yml" 40 | end 41 | node.vm.provider "virtualbox" do |v| 42 | v.customize ["modifyvm", :id, "--memory", "256"] 43 | end 44 | end 45 | 46 | 47 | config.vm.define "centos7" do |node| 48 | node.vm.box = "bento/centos-7.1" 49 | node.vm.provision "ansible" do |ansible| 50 | ansible.playbook = "playbook.yml" 51 | ansible.verbose = "vvv" 52 | end 53 | node.vm.provider "virtualbox" do |v| 54 | v.customize ["modifyvm", :id, "--memory", "256"] 55 | end 56 | end 57 | 58 | 59 | config.vm.define "centos6" do |node| 60 | node.vm.box = "bento/centos-6.6" 61 | node.vm.provision "ansible" do |ansible| 62 | ansible.playbook = "playbook.yml" 63 | ansible.verbose = "vvv" 64 | end 65 | node.vm.provider "virtualbox" do |v| 66 | v.customize ["modifyvm", :id, "--memory", "256"] 67 | end 68 | end 69 | 70 | end 71 | -------------------------------------------------------------------------------- /demo-full/templates/app.nginx.conf.j2: -------------------------------------------------------------------------------- 1 | # file: /etc/nginx/conf.d/default.conf 2 | # 3 | # 4 | # proxy for Node.js app 5 | # 6 | # @see https://engineering.gosquared.com/optimising-nginx-node-js-and-networking-for-heavy-workloads 7 | # 8 | 9 | upstream app_nodejs { 10 | server 127.0.0.1:3000 max_fails=0 fail_timeout=10s; 11 | keepalive 512; 12 | } 13 | 14 | 15 | 16 | server { 17 | listen 80; 18 | server_name localhost; 19 | server_tokens off; 20 | client_max_body_size 16M; 21 | keepalive_timeout 10; 22 | 23 | 24 | # 25 | # trust connections from internal addresses; 26 | # useful for packet inputs from load balancers or CDNs 27 | # (e.g., Linode NodeBalancer, Amazon ELB) 28 | # 29 | #------> set_real_ip_from 192.168.0.0/16; 30 | real_ip_header X-Forwarded-For; 31 | 32 | 33 | # 34 | # proxy for Node.js app 35 | # 36 | location / { 37 | 38 | # use this when packet inputs are from load balancers or CDNs 39 | #proxy_set_header X-Forwarded-For $http_x_forwarded_for; 40 | 41 | # use this when packet inputs are directly from real clients; 42 | # "This variable contains the value of the `X-Forwarded-For` 43 | # request header, followed by the remote address of the client. 44 | # Both values are separated by a comma. 45 | # If the `X-Forwarded-For` request header is unavailable, 46 | # the variable only contains the client remote address." 47 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 48 | 49 | proxy_set_header X-Real-IP $remote_addr; 50 | proxy_set_header Host $http_host; 51 | proxy_set_header X-NginX-Proxy true; 52 | 53 | proxy_headers_hash_bucket_size 1024; 54 | proxy_headers_hash_max_size 512; 55 | 56 | proxy_set_header Connection ""; 57 | proxy_http_version 1.1; 58 | 59 | proxy_pass http://app_nodejs; 60 | proxy_redirect off; 61 | proxy_next_upstream error timeout http_500 http_502 http_503 http_504; 62 | } 63 | 64 | 65 | 66 | #error_page 404 /404.html; 67 | 68 | # redirect server error pages to the static page /50x.html 69 | # 70 | error_page 500 502 503 504 /50x.html; 71 | location = /50x.html { 72 | root /usr/share/nginx/html; 73 | } 74 | } 75 | 76 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | A Gentle Introduction to Ansible 2 | === 3 | 4 | 5 | ## Background 6 | 7 | Companion lab materials for my talk given at [Modern Web 2015, Taipei](http://modernweb.tw/) (2015-05-16) by William Yeh. 8 | 9 | Forty minutes presentation, with some live demos on Vagrant and IaaS instances (e.g., EC2, Google Compute Engine). 10 | 11 | 12 | ## Topic 13 | 14 | A gentle introduction to [Ansible](https://github.com/ansible/ansible), using a set of working examples: Nginx, Node.js, and React. 15 | 16 | Ansible positions itself as an “IT automation system”, but only the “*configuration management*” subset is discussed here. 17 | 18 | ## Videos 19 | 20 | View online: https://youtu.be/FboNN3OSq60 21 | 22 | 23 | ## Slides 24 | 25 | View online: http://bit.ly/ansible-slide 26 | 27 | Due to time constaints (40 minutes), not all details are explained in the talk and slides. If more details needs to be explained, together with all labs demonstrated, 2 hours may be more appropriated. 28 | 29 | 30 | ## Lab materials 31 | 32 | The following figure illustrates the mapping between each `demo-*` directory and associated topic in the slides: 33 | 34 | ![Demo roadmap](demo-roadmap.jpg) 35 | 36 | 37 | ## Preparation 38 | 39 | Before experiment with the lab material, complete the following environment setup: 40 | 41 | 1. Install VM software: 42 | 43 | - Install [Vagrant](http://www.vagrantup.com/downloads.html), an excellent programmable VM environment. 44 | - Install [VirtualBox](https://www.virtualbox.org/wiki/Downloads), or purchase more powerful VM software such as [VMware Workstation](http://www.vmware.com/tw/products/workstation/), [VMware Fusion](http://www.vmware.com/tw/products/fusion), and [Parallels Desktop](http://www.parallels.com/products/desktop/). 45 | 46 | Or, read the article "[Playing VMs with Vagrant](http://www.codedata.com.tw/social-coding/vagrant-tutorial-2-playing-vm-with-vagrant/)" (in Traditional Chinese) for more information. 47 | 48 | 49 | 2. Install [Ansible](https://github.com/ansible/ansible) client: 50 | 51 | ... using Homebrew mechanism (on Mac): 52 | 53 | ```bash 54 | brew install ansible 55 | ``` 56 | 57 | or, using Pip (on Linux or Mac) since Ansible was written in Python: 58 | 59 | ```bash 60 | pip install ansible 61 | ``` 62 | 63 | 3. Done! 64 | 65 | 66 | 67 | ## License 68 | 69 | Author: William Yeh, william.pjyeh@gmail.com 70 | 71 | Apache License V2. 72 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2015 William Yeh 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | --------------------------------------------------------------------------------