Published on

SET UP UBUNTU VAGRANT BOX - NGINX

Authors
  • avatar
    Name
    Jimmy Lai
    Twitter

Spining up Vagrant box ubuntu 16.04 (focal)

# -*- mode: ruby -*-
# vi: set ft=ruby :
#

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search fory
  # boxes at https://vagrantcloud.com/search.
  config.vm.box = "ubuntu/focal64"
  # config.hostmanager.include_offline = true

  # if Vagrant.has_plugin?("vagrant-vbguest")
  #     config.vbguest.auto_update = true
  # end

  config.vm.provider "virtualbox" do |vb|
    vb.name = "web"
    vb.customize ["modifyvm", :id,
         "--audio", "none",
         "--cpus", 2,
         "--memory", 4096,
         "--graphicscontroller", "VMSVGA",
         "--vram", "64"
      ]
  end
  # config.vm.network "forwarded_port", guest: 80, host: 8080

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine and only allow access
  # via 127.0.0.1 to disable public access
  # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"

  # Create a private network, which allows host-only access to the machine
  #
  # using a specific IP.
  config.vm.network "private_network", ip: "192.168.56.10"

  config.ssh.forward_agent=true
  #config.vagrant.plugins = ["vagrant-hostmanager", "vagrant-vbguest"]

  # SHELL
end


GenErate Cert Openssl

openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
     -subj /CN=localhost \
     -keyout files/nginx.key -out files/nginx.crt
---
- name: Configure webserver with nginx
  hosts: webservers
  become: True
  tasks:
    - name: Ensure nginx is installed
      package: name=nginx update_cache=yes

    - name: Copy nginx config file
      copy:
        src: nginx.conf
        dest: /etc/nginx/sites-available/default

    - name: Enable configuration
      file: >
        dest=/etc/nginx/sites-enabled/default
        src=/etc/nginx/sites-available/default
        state=link

    - name: Copy index.html
      template: >
        src=index.html.j2
        dest=/usr/share/nginx/html/index.html

    - name: Restart nginx
      service: name=nginx state=restarted