diff --git a/provisioning/group_vars/all b/provisioning/group_vars/all index 3ea60f4..955179e 100644 --- a/provisioning/group_vars/all +++ b/provisioning/group_vars/all @@ -1,2 +1,3 @@ shelfzilla_base_path: /opt/shelfzilla +shelfzillla_config_file: "{{ shelfzilla_base_path }}/shelfzilla.toml" system_init_path: /etc/init.d \ No newline at end of file diff --git a/provisioning/group_vars/production b/provisioning/group_vars/production index e69de29..0b19ac6 100644 --- a/provisioning/group_vars/production +++ b/provisioning/group_vars/production @@ -0,0 +1,11 @@ +local_environment: False +filer_base_url: "https://media.shelfzilla.com/" +logpath: "/var/log/shelfzilla" +logfile: "{{ logpath }}/django.log" +debug: "false" +template_debug: "false" +static_root: "/opt/shelfzilla/shelfzilla/static" +static_url: "https://static.shelfzilla.com/" +media_root: "/opt/media" +media_url: "https://media.shelfzilla.com/" +secret_key: "d279ffd2f5b0e3b825ad3ec2362210da" \ No newline at end of file diff --git a/provisioning/group_vars/vagrant b/provisioning/group_vars/vagrant index 8ca3248..558d23b 100644 --- a/provisioning/group_vars/vagrant +++ b/provisioning/group_vars/vagrant @@ -1 +1,12 @@ -local_environment: True \ No newline at end of file +local_environment: True +filer_base_url: "https://media.shelfzilla.com/" +logpath: "/var/log/shelfzilla" +logfile: "{{ logpath }}/django.log" +debug: "false" +template_debug: "false" +static_root: "/opt/shelfzilla/shelfzilla/static" +static_url: "https://static.shelfzilla.com/" +media_root: "/opt/media" +media_url: "https://media.shelfzilla.com/" +secret_key: "d279ffd2f5b0e3b825ad3ec2362210da" + diff --git a/provisioning/roles/common/tasks/security.yml b/provisioning/roles/common/tasks/security.yml index 113147c..bf06f8e 100644 --- a/provisioning/roles/common/tasks/security.yml +++ b/provisioning/roles/common/tasks/security.yml @@ -14,7 +14,7 @@ register: st - name: Install Iptables statements - file: + copy: src=iptables dest=/etc/sysconfig/iptables sudo: yes diff --git a/provisioning/roles/shelfzilla/files/shelfzilla.key b/provisioning/roles/shelfzilla/files/shelfzilla.key new file mode 100644 index 0000000..cf54051 --- /dev/null +++ b/provisioning/roles/shelfzilla/files/shelfzilla.key @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXQIBAAKBgQDTrqIau+Yww3BF9X4FiU+NW29QVPSe3Pp9I5W0ea8sDf8SUYol +jBozV7zhIcHInAzEAzafGrFioX7rJWjMn+uVTVgngFQNy3mgvJXBpzJUkh0v/Eo3 +XMFpB8I1qP5J0IjXQ+mQ0mnD4MTSHbGw7IMheiNXeNLBUdivhS5TuzQ5wQIDAQAB +AoGAIUgTtKBWUNRpkpZGehhcqZz2o2q4C0IzH/m4T+fR4ttQf1DSp5SfifMBf2QP +U7s1Rpw6ukk4GonJqq73CzUZlNZ2EB0siTUMgtAfSiv+VOd66lOi6pQfnt+U6vwl +9kkuq2s0CXt0MArtW647C0W5mr/E0i8qP/poDuTuqwz/jAECQQD5C4eQZtLOh/Dm +awKTmboQg9+YTeJ1Zm9+ZCLYmlBWbrRfqsm6NQXEckUZqV5xGmHnmLZ+WeZ5uYR5 +d9YXIuXNAkEA2Zf9Rd+ObUyFyJllwLOcvzfguYUfEHGPBbIVkfUB2JZxwHt7LoZY +Xl/m9r9XO69+i2WcgbdJPOQa0of7XQvvxQJAbGKyKww07qGHHCCyTF549bsO0pAC +4KkmGNGnwLDYCeXAJmqDxMBStD4vCI4Hhh2/QjXaJn8lqRAuMVcQG52aeQJBAMaQ +2sIO1oyLjnKW+bI2tk4RkfP6tXRuDNRnxSNi8IJUGA5NIQY99xp4be6ygcqnxdUz +rvT4686zYn7JNOueXvkCQQDCWhjJG073KyIYZ6PXL/rCSMCrWmdJxvYdT/9KUN0O +Hh0mpORMDm4js9BxZ7m7TIm6dE+TMCxWR8hC6aMlP3km +-----END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/provisioning/roles/shelfzilla/files/shelfzilla.pem b/provisioning/roles/shelfzilla/files/shelfzilla.pem new file mode 100644 index 0000000..a0418ad --- /dev/null +++ b/provisioning/roles/shelfzilla/files/shelfzilla.pem @@ -0,0 +1,16 @@ +-----BEGIN CERTIFICATE----- +MIICfTCCAeYCCQCqDrpm8z+ghTANBgkqhkiG9w0BAQUFADCBgjELMAkGA1UEBhMC +RVMxDzANBgNVBAgMBk1hZHJpZDEPMA0GA1UEBwwGTWFkcmlkMRMwEQYDVQQKDApT +aGVsZnppbGxhMRcwFQYDVQQDDA5zaGVsZnppbGxhLmNvbTEjMCEGCSqGSIb3DQEJ +ARYUc2hlbGZ6aWxsYUBnbWFpbC5jb20wHhcNMTQxMTA5MTAwMTEyWhcNMTUxMTA5 +MTAwMTEyWjCBgjELMAkGA1UEBhMCRVMxDzANBgNVBAgMBk1hZHJpZDEPMA0GA1UE +BwwGTWFkcmlkMRMwEQYDVQQKDApTaGVsZnppbGxhMRcwFQYDVQQDDA5zaGVsZnpp +bGxhLmNvbTEjMCEGCSqGSIb3DQEJARYUc2hlbGZ6aWxsYUBnbWFpbC5jb20wgZ8w +DQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANOuohq75jDDcEX1fgWJT41bb1BU9J7c ++n0jlbR5rywN/xJRiiWMGjNXvOEhwcicDMQDNp8asWKhfuslaMyf65VNWCeAVA3L +eaC8lcGnMlSSHS/8SjdcwWkHwjWo/knQiNdD6ZDSacPgxNIdsbDsgyF6I1d40sFR +2K+FLlO7NDnBAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAxootiRyWVIgIaLAIDbGZ +/l9n5UTSuk4ittSbkUrwnLubO9MxDx0Y8RUhksLn1wU88wVt/u65+kP36UdPvk1P +km2azDwiJ1z5rVaJ/pLD6J8q2tJj79WQKpVZ7XTyoSwESCVokI/HR/OWzfb6tHHW +lZfV+f9HBqxNuz7I87eNbBM= +-----END CERTIFICATE----- \ No newline at end of file diff --git a/provisioning/roles/shelfzilla/tasks/main.yml b/provisioning/roles/shelfzilla/tasks/main.yml index 0678258..3a8e58c 100644 --- a/provisioning/roles/shelfzilla/tasks/main.yml +++ b/provisioning/roles/shelfzilla/tasks/main.yml @@ -1,6 +1,7 @@ --- - debug: msg="Starting Shelfzilla module" - include: shelfzilla.yml +- include: nginx.yml - include: post_nodejs.yml -#- include: post_python.yml +- include: post_python.yml #- include: postgre.yml diff --git a/provisioning/roles/shelfzilla/tasks/nginx.yml b/provisioning/roles/shelfzilla/tasks/nginx.yml new file mode 100644 index 0000000..fb63c57 --- /dev/null +++ b/provisioning/roles/shelfzilla/tasks/nginx.yml @@ -0,0 +1,28 @@ +--- +- name: Install Shelfzilla vhost for Nginx + template: src=shelfzilla.conf + dest="/etc/nginx/conf.d/shelfzilla.conf" + owner=root + group=root + mode=0755 + sudo: yes + +- name: Create nginx ssl folder + file: path='/etc/nginx/ssl' + owner=nginx + group=nginx + mode=0775 + state=directory + sudo: yes + +- name: Install Shelfzilla SSL + copy: src="{{ item }}" + dest="/etc/nginx/ssl/{{ item }}" + owner=nginx + group=nginx + mode=0644 + sudo: yes + with_items: + - shelfzilla.pem + - shelfzilla.key + diff --git a/provisioning/roles/shelfzilla/tasks/post_python.yml b/provisioning/roles/shelfzilla/tasks/post_python.yml index 9052cde..aa78b97 100644 --- a/provisioning/roles/shelfzilla/tasks/post_python.yml +++ b/provisioning/roles/shelfzilla/tasks/post_python.yml @@ -3,10 +3,18 @@ executable="/usr/bin/pip2" sudo: yes -- name: Python Migrate - shell: /usr/bin/python2.7 {{shelfzilla_base_path}}/manage.py migrate install --no-initial-data --settings=shelfzilla.settings.configfile +- lineinfile: dest="{{shelfzilla_base_path}}/shelfzilla/settings/configfile.py" + regexp="^(.*)os\.environ\[\'APP\_CONFIGFILE\'\](.*)$" + state=present + line="\'\1{{ shelfzillla_config_file }}\2\'" + backrefs=yes sudo: yes +- name: Python Migrate + shell: /usr/bin/python2.7 {{shelfzilla_base_path}}/manage.py migrate --no-initial-data --settings=shelfzilla.settings.configfile + sudo: yes + sudo_user: postgres + - name: Python Collectstatic shell: /usr/bin/python2.7 {{shelfzilla_base_path}}/manage.py collectstatic --clear --noinput --settings=shelfzilla.settings.configfile sudo: yes diff --git a/provisioning/roles/shelfzilla/tasks/shelfzilla.yml b/provisioning/roles/shelfzilla/tasks/shelfzilla.yml index 341dcea..64c9c8a 100644 --- a/provisioning/roles/shelfzilla/tasks/shelfzilla.yml +++ b/provisioning/roles/shelfzilla/tasks/shelfzilla.yml @@ -1,4 +1,16 @@ --- +- name: Group Shelfzilla + group: name=shelfzilla state=present + sudo: yes + +- name: User Shelfzilla + user: name=shelfzilla comment="Shelfzilla" groups=shelfzilla,nginx,postgres + sudo: yes + +- name: Modify Nginx user + user: name=nginx groups=shelfzilla,nginx,postgres + sudo: yes + - name: Install shelfzilla RPM yum: pkg=shelfzilla state=installed sudo: yes @@ -33,4 +45,44 @@ with_items: - "{{shelfzilla_base_path}}/init/" sudo: yes - when: st.stat.exists \ No newline at end of file + when: st.stat.exists + +- name: Install Shelfzilla config file + template: src=shelfzilla.toml + dest="{{shelfzilla_base_path}}/shelfzilla.toml" + owner=root + group=root + mode=0755 + sudo: yes + +- name: Create necessary folders + file: path="{{ item }}" + owner=shelfzilla + group=shelfzilla + mode=0775 + state=directory + sudo: yes + with_items: + - "{{ logpath }}" + - "{{ static_root }}" + - "{{ media_root }}" + +- stat: path="{{ logfile }}" + register: st + +- name: Create Logfile + file: path="{{ logfile }}" + owner=root + group=root + mode=0666 + state=file + sudo: yes + when: not st.stat.exists + +- name: Create Static base path + file: path="{{ logpath }}" + owner=root + group=root + mode=0755 + state=directory + sudo: yes diff --git a/provisioning/roles/shelfzilla/templates/shelfzilla.conf b/provisioning/roles/shelfzilla/templates/shelfzilla.conf new file mode 100644 index 0000000..bfc636d --- /dev/null +++ b/provisioning/roles/shelfzilla/templates/shelfzilla.conf @@ -0,0 +1,76 @@ +# Shelfzilla Vhost +server { + listen 443 ssl; + server_name shelfzilla.com www.shelfzilla.com; + ssl_certificate ./ssl/shelfzilla.pem; + ssl_certificate_key ./ssl/shelfzilla.key; + client_max_body_size 10M; + client_body_temp_path /tmp/; + server_tokens off; + + if ($host = 'www.shelfzilla.com') { + return 301 $scheme://shelfzilla.com; + } + + location /static/ { + alias {{ static_root }}; + expires 1d; + } + + location /media/ { + alias {{ media_root }}; + expires 1d; + } + + location /files/ { + alias {{ media_root }}/filer/public/; + expires 31d; + } + + location /files/thumbnails/ { + alias {{ media_root }}/filer/public/thumbnails/; + expires 31d; + } + + location / { + proxy_pass http://127.0.0.1:8000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + + location /landing { + return 301 $scheme://$server_name; + } + +} + +server { + listen 443 ssl; + server_name media.shelfzilla.com; + ssl_certificate ./ssl/shelfzilla.pem; + ssl_certificate_key ./ssl/shelfzilla.key; + + location / { + alias {{ media_root }}; + expires 1d; + } + + location /files/ { + alias {{ media_root }}/filer/public/; + expires 31d; + } +} + +server { + listen 443 ssl; + server_name static.shelfzilla.com; + ssl_certificate ./ssl/shelfzilla.pem; + ssl_certificate_key ./ssl/shelfzilla.key; + + location / { + add_header 'Access-Control-Allow-Origin' "https://shelfzilla.com"; + alias {{ static_root }}/; + expires 1d; + } +} \ No newline at end of file diff --git a/provisioning/roles/shelfzilla/templates/shelfzilla.repo b/provisioning/roles/shelfzilla/templates/shelfzilla.repo deleted file mode 100644 index 40a3170..0000000 --- a/provisioning/roles/shelfzilla/templates/shelfzilla.repo +++ /dev/null @@ -1,5 +0,0 @@ -[Shelfzilla] -name=Shelfzilla Awesome App -baseurl=http://37.139.15.172/ -gpgcheck=0 -enabled=1 \ No newline at end of file diff --git a/provisioning/roles/shelfzilla/templates/shelfzilla.toml b/provisioning/roles/shelfzilla/templates/shelfzilla.toml new file mode 100644 index 0000000..57ef3d7 --- /dev/null +++ b/provisioning/roles/shelfzilla/templates/shelfzilla.toml @@ -0,0 +1,28 @@ +[global] +database_url = "postgres:///shelfzilla" +installed_apps = [ + "gunicorn", +] + +[filer] +base_url = "{{ filer_base_url }}" + +[log] +logfile = "{{ logfile }}" + +[overwrite] +debug = {{ debug }} +template_debug = {{template_debug}} + +site_id = 1 + +static_root = "{{ static_root }}" +static_url = "{{ static_url }}" + +media_root = "{{ media_root }}" +media_url = "{{ media_url }}" + +secret_key = "{{ secret_key }}" + +internal_ips = ["127.0.0.1"] +allowed_hosts = ["shelfzilla.com"] \ No newline at end of file diff --git a/provisioning/roles/shelfzilla_base/tasks/main.yml b/provisioning/roles/shelfzilla_base/tasks/main.yml index ed253b2..ea3d5d6 100644 --- a/provisioning/roles/shelfzilla_base/tasks/main.yml +++ b/provisioning/roles/shelfzilla_base/tasks/main.yml @@ -1,6 +1,7 @@ --- - debug: msg="Starting Shelfzilla Base module" - include: yum_repository.yml +- include: nginx.yml - include: python.yml - include: nodejs.yml - include: postgre.yml diff --git a/provisioning/roles/shelfzilla_base/tasks/nginx.yml b/provisioning/roles/shelfzilla_base/tasks/nginx.yml new file mode 100644 index 0000000..1d7030c --- /dev/null +++ b/provisioning/roles/shelfzilla_base/tasks/nginx.yml @@ -0,0 +1,11 @@ +--- +- name: Install Nginx + yum: pkg=nginx state=installed + sudo: yes + +- name: Install Nginx base template + template: + src=nginx.conf + dest=/etc/nginx/nginx.conf + backup=yes + sudo: yes diff --git a/provisioning/roles/shelfzilla_base/templates/nginx.conf b/provisioning/roles/shelfzilla_base/templates/nginx.conf new file mode 100644 index 0000000..c7dea3f --- /dev/null +++ b/provisioning/roles/shelfzilla_base/templates/nginx.conf @@ -0,0 +1,39 @@ +# For more information on configuration, see: +# * Official English Documentation: http://nginx.org/en/docs/ +# * Official Russian Documentation: http://nginx.org/ru/docs/ + +user shelfzilla; +worker_processes 1; + +error_log /var/log/nginx/error.log; +#error_log /var/log/nginx/error.log notice; +#error_log /var/log/nginx/error.log info; +pid /var/run/nginx.pid; + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + #tcp_nopush on; + + #keepalive_timeout 0; + keepalive_timeout 65; + server_names_hash_bucket_size 128; + #gzip on; + + # Load config files from the /etc/nginx/conf.d directory + # The default server is in conf.d/default.conf + include /etc/nginx/conf.d/shelfzilla.conf; + +} \ No newline at end of file