From ec822f14411785bd722ef030d198d877dd14ec02 Mon Sep 17 00:00:00 2001 From: Anton Vakhrushev Date: Sat, 31 Dec 2016 10:21:27 +0300 Subject: [PATCH] Reconfigure vagrant --- .gitignore | 1 + Vagrantfile | 68 ++++------------------ ansible/provision.yml | 16 +++++ ansible/requirements.yml | 13 +++++ ansible/roles/nginx/handlers/main.yml | 3 - ansible/roles/nginx/tasks/main.yml | 33 +---------- ansible/roles/nginx/templates/homepage.j2 | 10 ---- ansible/roles/nginx/templates/site.conf.j2 | 12 ++++ ansible/roles/server/tasks/main.yml | 16 +---- ansible/roles/server/templates/timezone.j2 | 1 - ansible/setup.yml | 12 ---- ansible/vars/all.yml | 23 ++++++-- 12 files changed, 77 insertions(+), 131 deletions(-) create mode 100644 ansible/provision.yml create mode 100644 ansible/requirements.yml delete mode 100755 ansible/roles/nginx/handlers/main.yml delete mode 100755 ansible/roles/nginx/templates/homepage.j2 create mode 100755 ansible/roles/nginx/templates/site.conf.j2 delete mode 100755 ansible/roles/server/templates/timezone.j2 delete mode 100644 ansible/setup.yml diff --git a/.gitignore b/.gitignore index 95fbdff..2932423 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +/ansible/galaxy.roles/ /output_* /vendor/ diff --git a/Vagrantfile b/Vagrantfile index aadb43c..349a669 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,66 +1,22 @@ # -*- 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. +ENV["LC_ALL"] = "en_US.UTF-8" + +# For installing ansible_local from pip on guest +Vagrant.require_version ">= 1.8.3" + +Vagrant.configure("2") do |config| - # Every Vagrant development environment requires a box. You can search for - # boxes at https://atlas.hashicorp.com/search. config.vm.box = "ubuntu/trusty64" - # Disable automatic box update checking. If you disable this, then - # boxes will only be checked for updates when the user runs - # `vagrant box outdated`. This is not recommended. - # config.vm.box_check_update = false - - # Create a forwarded port mapping which allows access to a specific port - # within the machine from a port on the host machine. In the example below, - # accessing "localhost:8080" will access port 80 on the guest machine. config.vm.network "forwarded_port", guest: 80, host: 8080 - # Create a private network, which allows host-only access to the machine - # using a specific IP. - config.vm.network "private_network", ip: "192.168.33.20" + config.vm.provision "ansible_local" do |ansible| + ansible.playbook = "ansible/provision.yml" + ansible.galaxy_role_file = "ansible/requirements.yml" + ansible.galaxy_roles_path = "ansible/galaxy.roles" + ansible.sudo = true + end - # Share an additional folder to the guest VM. The first argument is - # the path on the host to the actual folder. The second argument is - # the path on the guest to mount the folder. And the optional third - # argument is a set of non-required options. - # config.vm.synced_folder "../data", "/vagrant_data" - - # Provider-specific configuration so you can fine-tune various - # backing providers for Vagrant. These expose provider-specific options. - # Example for VirtualBox: - # - # config.vm.provider "virtualbox" do |vb| - # # Display the VirtualBox GUI when booting the machine - # vb.gui = true - # - # # Customize the amount of memory on the VM: - # vb.memory = "1024" - # end - # - # View the documentation for the provider you are using for more - # information on available options. - - # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies - # such as FTP and Heroku are also available. See the documentation at - # https://docs.vagrantup.com/v2/push/atlas.html for more information. - # config.push.define "atlas" do |push| - # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME" - # end - - # Enable provisioning with a shell script. Additional provisioners such as - # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the - # documentation for more information about their specific syntax and use. - # config.vm.provision "shell", inline: <<-SHELL - # apt-get update - # apt-get install -y apache2 - # SHELL end diff --git a/ansible/provision.yml b/ansible/provision.yml new file mode 100644 index 0000000..8964f64 --- /dev/null +++ b/ansible/provision.yml @@ -0,0 +1,16 @@ +--- +- hosts: all + + vars_files: + - vars/all.yml + + pre_tasks: + - name: Ensure that PHP Ondrej PPA is added + apt_repository: repo=ppa:ondrej/php state=present + + roles: + - yatesr.timezone + - server + - geerlingguy.nginx + - nginx + - geerlingguy.php diff --git a/ansible/requirements.yml b/ansible/requirements.yml new file mode 100644 index 0000000..0773e50 --- /dev/null +++ b/ansible/requirements.yml @@ -0,0 +1,13 @@ +--- +- src: yatesr.timezone + version: 1.0.0 + +- src: geerlingguy.nginx + version: 1.9.6 + +- src: geerlingguy.php + version: 3.4.2 + +- src: geerlingguy.composer + version: 1.5.0 + diff --git a/ansible/roles/nginx/handlers/main.yml b/ansible/roles/nginx/handlers/main.yml deleted file mode 100755 index 1899c9c..0000000 --- a/ansible/roles/nginx/handlers/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -- name: restart nginx - service: name=nginx enabled=yes state=restarted \ No newline at end of file diff --git a/ansible/roles/nginx/tasks/main.yml b/ansible/roles/nginx/tasks/main.yml index e6f637c..7119917 100755 --- a/ansible/roles/nginx/tasks/main.yml +++ b/ansible/roles/nginx/tasks/main.yml @@ -1,33 +1,6 @@ --- -- name: Install Nginx - become: yes - apt: pkg=nginx state=latest - -- name: Create nginx congig - become: yes +- name: Create nginx config template: - src: homepage.j2 - dest: /etc/nginx/sites-available/{{ site.domain }} - notify: restart nginx - -- name: Create symlink to site - become: yes - file: - src: /etc/nginx/sites-available/{{ site.domain }} - dest: /etc/nginx/sites-enabled/{{ site.domain }} - state: link - notify: restart nginx - -- name: Delete default site - become: yes - file: - path: /etc/nginx/sites-available/default - state: absent - notify: restart nginx - -- name: Delete default site symlink - become: yes - file: - path: /etc/nginx/sites-enabled/default - state: absent + src: site.conf.j2 + dest: /etc/nginx/sites-enabled/{{ nginx_conf_name }} notify: restart nginx diff --git a/ansible/roles/nginx/templates/homepage.j2 b/ansible/roles/nginx/templates/homepage.j2 deleted file mode 100755 index 3987025..0000000 --- a/ansible/roles/nginx/templates/homepage.j2 +++ /dev/null @@ -1,10 +0,0 @@ -server { - listen 80; - server_name {{ site.domain }} www.{{ site.domain }}; - - location / { - root /var/www/{{ site.www_dir }}/current/web; - index index.html; - try_files $uri /index.html; - } -} diff --git a/ansible/roles/nginx/templates/site.conf.j2 b/ansible/roles/nginx/templates/site.conf.j2 new file mode 100755 index 0000000..de18b12 --- /dev/null +++ b/ansible/roles/nginx/templates/site.conf.j2 @@ -0,0 +1,12 @@ +server { + listen 80; + server_name {{ nginx_conf_domain }} www.{{ nginx_conf_domain }}; + + location / { + root {{ nginx_conf_root }}; + index index.html; + try_files $uri /index.html; + } + + sendfile off; +} diff --git a/ansible/roles/server/tasks/main.yml b/ansible/roles/server/tasks/main.yml index 917b9f3..aec75ae 100755 --- a/ansible/roles/server/tasks/main.yml +++ b/ansible/roles/server/tasks/main.yml @@ -1,9 +1,9 @@ --- -- name: Update apt +- name: Update apt cache sudo: yes apt: update_cache=yes -- name: Install System Packages +- name: Install system packages sudo: yes apt: pkg={{ item }} state=latest with_items: @@ -11,15 +11,3 @@ - wget - python-software-properties - git - -- name: Configure the timezone - sudo: yes - template: src=timezone.j2 dest=/etc/timezone - -- name: Configure the timezone - sudo: yes - file: src=/usr/share/zoneinfo/{{ server.timezone }} dest=/etc/localtime state=link force=yes backup=yes - -- name: Set default system language pack - shell: locale-gen {{ server.locale }} - sudo: yes diff --git a/ansible/roles/server/templates/timezone.j2 b/ansible/roles/server/templates/timezone.j2 deleted file mode 100755 index 15f415e..0000000 --- a/ansible/roles/server/templates/timezone.j2 +++ /dev/null @@ -1 +0,0 @@ -{{ server.timezone }} diff --git a/ansible/setup.yml b/ansible/setup.yml deleted file mode 100644 index 91b9516..0000000 --- a/ansible/setup.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- -- hosts: all - - become: true - become_method: sudo - - vars_files: - - vars/all.yml - - roles: - - server - - nginx diff --git a/ansible/vars/all.yml b/ansible/vars/all.yml index bf77352..060269d 100755 --- a/ansible/vars/all.yml +++ b/ansible/vars/all.yml @@ -1,17 +1,30 @@ --- -server: - timezone: UTC - locale: en_US.UTF-8 +application_root: /vagrant site: www_dir: anwinged domain: anwinged.ru + conf_name: anwinged.conf +timezone: UTC + +nginx_conf_name: 'anwinged.conf' +nginx_conf_root: '{{ application_root }}/output_dev' +nginx_conf_domain: 'anwinged' + +nginx_remove_default_vhost: true + +php_enable_webserver: false +php_packages: + - php7.1 + - php7.1-mbstring + - php7.1-intl + - php7.1-curl + - php7.1-xml # Vars for ansistrano -ansistrano_deploy_from: "{{ playbook_dir }}/../web" +ansistrano_deploy_from: "{{ playbook_dir }}/../output_prod" ansistrano_deploy_to: "/var/www/{{ site.www_dir }}" ansistrano_keep_releases: 3 ansistrano_deploy_via: copy -