diff --git a/.vagrant_provisioning/playbook.yml b/.vagrant_provisioning/playbook.yml index aca28ac..edb2256 100644 --- a/.vagrant_provisioning/playbook.yml +++ b/.vagrant_provisioning/playbook.yml @@ -8,279 +8,284 @@ become: true tasks: - - name: fix debian sudoers file - become: yes - lineinfile: - dest: /etc/sudoers - backup: yes - regexp: "^%sudo\\s+ALL=\\(ALL:ALL\\)\\s+ALL$" - line: "%sudo ALL=(ALL) NOPASSWD: ALL" - tags: - - system - - - name: apt | install https transport for apt - apt: - pkg: apt-transport-https - state: installed - update_cache: yes - tags: - -system - - - name: apt | add node key - become: yes - apt_key: - url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key - state: present - tags: - - system - - - name: apt | add nodejs sources - apt_repository: - repo: 'deb https://deb.nodesource.com/node wheezy main' - state: present - tags: - - system - - - name: apt | add nodejs sourcecode sources - apt_repository: - repo: 'deb-src https://deb.nodesource.com/node wheezy main' - state: present - tags: - - system - - - name: apt | add elasticsearch key - become: yes - apt_key: - url: https://packages.elastic.co/GPG-KEY-elasticsearch - state: present - tags: - - system - - - name: apt | add elasticsearch sources - apt_repository: - repo: 'deb http://packages.elastic.co/elasticsearch/2.x/debian stable main' - state: present - tags: - - system - - - name: apt | install required system packages - apt: - pkg: '{{ item }}' - state: installed - update_cache: yes - with_items: '{{ system_packages }}' - tags: - - system - - - name: zsh | clone oh-my-zsh repo - git: repo={{ zsh.oh_my_zsh }} dest={{ user_home }}/.oh-my-zsh - tags: - - system - - - name: zsh | deploy .zshrc - copy: src={{ zsh.zshrc }} dest={{ user_home }}/.zshrc owner=vagrant - tags: - - system - - - name: zsh | as default shell - user: name=vagrant shell=/bin/zsh - tags: - - system + # - name: apt | add node key + # become: yes + # apt_key: + # url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key + # state: present + # tags: + # - system + + # - name: apt | add nodejs sources + # apt_repository: + # repo: 'deb https://deb.nodesource.com/node wheezy main' + # state: present + # tags: + # - system + + # - name: apt | add nodejs sourcecode sources + # apt_repository: + # repo: 'deb-src https://deb.nodesource.com/node wheezy main' + # state: present + # tags: + # - system + + - name: apt | add elasticsearch key + become: yes + apt_key: + url: https://packages.elastic.co/GPG-KEY-elasticsearch + state: present + tags: + - system + + - name: apt | add elasticsearch sources + apt_repository: + repo: 'deb http://packages.elastic.co/elasticsearch/2.x/debian stable main' + state: present + tags: + - system + + - name: apt | install required system packages + apt: + pkg: '{{ system_packages }}' + state: present + update_cache: yes + tags: + - system + + - name: zsh | clone oh-my-zsh repo + git: repo={{ zsh.oh_my_zsh }} dest={{ user_home }}/.oh-my-zsh + tags: + - system + + - name: zsh | deploy .zshrc + copy: src={{ zsh.zshrc }} dest={{ user_home }}/.zshrc owner=vagrant + tags: + - system + + - name: zsh | as default shell + user: name=vagrant shell=/bin/zsh + tags: + - system - hosts: all vars_files: - vars.yml gather_facts: false tasks: - - name: pip | create virtualenv directory - file: path={{ python.virtualenv_location }} state=directory owner=vagrant - tags: - - python - - - name: pip | init virtualenv - command: virtualenv {{ python.virtualenv_location }} - tags: - - python - - - name: pip | update setuptools - pip: - name: setuptools - virtualenv: "{{ python.virtualenv_location }}" - state: latest - tags: - - python - - - name: pip | update pip - pip: - name: pip - virtualenv: "{{ python.virtualenv_location }}" - state: latest - tags: - - python - - - name: pip | ensure python requirements are installed to latest version - pip: - requirements: "{{ project_root }}/{{ python.requirements }}" - virtualenv: "{{ python.virtualenv_location }}" - tags: - - python + - name: python | easy install pip + become: yes + easy_install: name=pip state=latest + tags: + - python + + - name: python | install virtualenv + become: yes + pip: name=virtualenv state=latest + tags: + - python + + - name: python | install psycopg2 + become: yes + pip: name=psycopg2 state=latest + tags: + - python + + - name: python | setup virtualenv + file: path={{ python.virtualenv_location }} state=directory + - command: virtualenv {{ python.virtualenv_location }} + tags: + - python + + - name: pip | update pip + pip: + name: pip + virtualenv: '{{ python.virtualenv_location }}' + state: latest + tags: + - python + + - name: pip | ensure python requirements are installed to latest version + pip: + requirements: '{{ project_root }}/{{ python.requirements }}' + virtualenv: '{{ python.virtualenv_location }}' + tags: + - python - hosts: all vars_files: - vars.yml # gather_facts: false tasks: - - name: locale | setup gb locale - locale_gen: - name: "{{ postgresql.locale }}" - state: present - become: yes - tags: - - db - - - name: postgresql | ensure postgresql user can authenticate - become: yes - lineinfile: - dest: /etc/postgresql/{{ postgresql.version }}/main/pg_hba.conf - backup: yes - regexp: "^local\\s+all\\s+{{ postgresql.admin_user }}\\s+peer$" - line: "local all {{ postgresql.admin_user }} {{ postgresql.default_auth_method }}" - tags: - - db - - - name: postgresql | ensure all users can authenticate - become: yes - lineinfile: - dest: /etc/postgresql/{{ postgresql.version }}/main/pg_hba.conf - backup: yes - regexp: "^local\\s+all\\s+all\\s+peer$" - line: "local all all {{ postgresql.default_auth_method }}" - notify: - - postgresql | restart postgres - - elasticsearch | restart elasticsearch - tags: - - db + - name: locale | setup gb locale + locale_gen: + name: '{{ postgresql.locale }}' + state: present + become: yes + tags: + - db + + - name: postgresql | get installed version + shell: 'ls /etc/postgresql/*/main/pg_hba.conf | cut -d / -f4' + register: postgresql_version + tags: + - db + + - name: postgresql | ensure postgresql user can authenticate + become: yes + lineinfile: + dest: /etc/postgresql/{{ postgresql_version.stdout }}/main/pg_hba.conf + backup: yes + regexp: "^local\\s+all\\s+{{ postgresql.admin_user }}\\s+peer$" + line: 'local all {{ postgresql.admin_user }} {{ postgresql.default_auth_method }}' + tags: + - db + + - name: postgresql | ensure all users can authenticate + become: yes + lineinfile: + dest: /etc/postgresql/{{ postgresql_version.stdout }}/main/pg_hba.conf + backup: yes + regexp: "^local\\s+all\\s+all\\s+peer$" + line: 'local all all {{ postgresql.default_auth_method }}' + notify: + - postgresql | restart postgres + tags: + - db + + # https://discuss.elastic.co/t/cant-start-elasticsearch-with-ubuntu-16-04/48730/9 + - name: elasticsearch | enable start daemon + become: yes + lineinfile: + dest: /etc/default/elasticsearch + backup: yes + regexp: '^#START_DAEMON=true' + line: 'START_DAEMON=true' + notify: + - elasticsearch | restart elasticsearch + tags: + - elasticsearch handlers: - - name: postgresql | restart postgres - become: yes - service: - name: postgresql - state: restarted - tags: - - db - - - name: elasticsearch | restart elasticsearch - become: yes - service: - name: elasticsearch - state: started - tags: - - db + - name: postgresql | restart postgres + become: yes + service: + name: postgresql + state: restarted + tags: + - db + + - name: elasticsearch | restart elasticsearch + become: yes + service: + name: elasticsearch + state: restarted + tags: + - db - hosts: all vars_files: - vars.yml tasks: - - name: postgresql | create user - become_user: "{{ postgresql.admin_user }}" - postgresql_user: - user: "{{ postgresql.user }}" - password: "{{ app.name }}" - role_attr_flags: CREATEDB # NOSUPERUSER NOCREATEROLE - tags: - - db - - - name: postgresql | create db - become_user: "{{ postgresql.admin_user }}" - postgresql_db: - name: "{{ app.name }}" - encoding: "{{postgresql.encoding}}" - lc_collate: "{{postgresql.locale}}" - lc_ctype: "{{postgresql.locale}}" - template: "template0" - state: present - owner: "{{ postgresql.user }}" - notify: - - postgresql | apply privileges - tags: - - db - - - name: check if initial data file exists - stat: - path: "{{ project_root }}/.vagrant_provisioning/{{ postgresql.initial_data_file }}" - register: idf - tags: - - db - - data - - - name: posgresql | load initial data file - command: psql -U {{ postgresql.user }} -d {{ app.name }} -f {{ project_root }}/.vagrant_provisioning/{{ postgresql.initial_data_file }} - when: idf.stat.exists - notify: - - postgresql | apply privileges after data import - tags: - - db - - data + - name: postgresql | create user + become_user: '{{ postgresql.admin_user }}' + postgresql_user: + user: '{{ postgresql.user }}' + password: '{{ app.name }}' + role_attr_flags: CREATEDB # NOSUPERUSER NOCREATEROLE + tags: + - db + + - name: postgresql | create db + become_user: '{{ postgresql.admin_user }}' + postgresql_db: + name: '{{ app.name }}' + encoding: '{{postgresql.encoding}}' + lc_collate: '{{postgresql.locale}}' + lc_ctype: '{{postgresql.locale}}' + template: 'template0' + state: present + owner: '{{ postgresql.user }}' + notify: + - postgresql | apply privileges + tags: + - db + + - name: check if initial data file exists + stat: + path: '{{ project_root }}/.vagrant_provisioning/{{ postgresql.initial_data_file }}' + register: idf + tags: + - db + - data + + - name: posgresql | load initial data file + command: psql -U {{ postgresql.user }} -d {{ app.name }} -f {{ project_root }}/.vagrant_provisioning/{{ postgresql.initial_data_file }} + when: idf.stat.exists + notify: + - postgresql | apply privileges after data import + tags: + - db + - data handlers: - - name: postgresql | apply privileges - become_user: "{{ postgresql.admin_user }}" - postgresql_privs: - db: "{{ app.name }}" - privs: ALL - roles: "{{ postgresql.user }}" - state: present - type: database - tags: - - db - - data - - - name: postgresql | apply privileges after data import - become_user: "{{ postgresql.admin_user }}" - postgresql_privs: - db: "{{ app.name }}" - objs: ALL_IN_SCHEMA - privs: ALL - roles: "{{ postgresql.user }}" - state: present - type: table - tags: - - db - - data + - name: postgresql | apply privileges + become_user: '{{ postgresql.admin_user }}' + postgresql_privs: + db: '{{ app.name }}' + privs: ALL + roles: '{{ postgresql.user }}' + state: present + type: database + tags: + - db + - data + + - name: postgresql | apply privileges after data import + become_user: '{{ postgresql.admin_user }}' + postgresql_privs: + db: '{{ app.name }}' + objs: ALL_IN_SCHEMA + privs: ALL + roles: '{{ postgresql.user }}' + state: present + type: table + tags: + - db + - data - hosts: all vars_files: - vars.yml tasks: - - name: django | default local settings - copy: src=local_settings.py dest={{ project_root }}/{{ app.name }}/settings/local.py owner=vagrant - tags: - - django + - name: django | default local settings + copy: src=local_settings.py dest={{ project_root }}/{{ app.name }}/settings/local.py owner=vagrant + tags: + - django - - name: django | migrations - command: "{{ user_home }}/venv/bin/python {{ project_root }}/manage.py makemigrations" - - command: "{{ user_home }}/venv/bin/python {{ project_root }}/manage.py migrate" - tags: - - django + - name: django | migrations + command: '{{ user_home }}/venv/bin/python {{ project_root }}/manage.py makemigrations' + - command: '{{ user_home }}/venv/bin/python {{ project_root }}/manage.py migrate' + tags: + - django - hosts: all vars_files: - - vars.yml + - vars.yml tasks: - - name: git | init - command: "git init" - args: - chdir: "{{ project_root }}" - tags: - - git - - - name: git | flake8 pre-commit hook - command: "{{ user_home }}/venv/bin/flake8 --install-hook" - args: - chdir: "{{ project_root }}" - - command: "git config flake8.strict True" - args: - chdir: "{{ project_root }}" - tags: - - git + - name: git | init + command: 'git init' + args: + chdir: '{{ project_root }}' + tags: + - git + + - name: git | flake8 pre-commit hook + command: '{{ user_home }}/venv/bin/flake8 --install-hook' + args: + chdir: '{{ project_root }}' + - command: 'git config flake8.strict True' + args: + chdir: '{{ project_root }}' + tags: + - git diff --git a/.vagrant_provisioning/vars.yml b/.vagrant_provisioning/vars.yml index 717d510..53c1418 100644 --- a/.vagrant_provisioning/vars.yml +++ b/.vagrant_provisioning/vars.yml @@ -1,12 +1,48 @@ -app: {name: kdl} -postgresql: {admin_user: postgres, cluster_name: main, cluster_reset: false, default_auth_method: trust, - encoding: UTF-8, initial_data_file: data.sql, locale: en_GB.UTF-8, user: kdl, version: 9.4} +app: { name: kdl } +postgresql: + { + admin_user: postgres, + cluster_name: main, + cluster_reset: false, + default_auth_method: trust, + encoding: UTF-8, + initial_data_file: data.sql, + locale: en_GB.UTF-8, + user: kdl, + version: 9.4, + } project_root: /vagrant -python: {requirements: requirements-vagrant.txt, virtualenv_location: /home/vagrant/venv} -system_packages: [ack-grep, zsh, vim-nox, python-dev, python-pip, python-psycopg2, - python-setuptools, python-virtualenv, nfs-common, postgresql, postgresql-client, - postgresql-server-dev-all, libldap2-dev, libsasl2-dev, libjpeg-dev, nodejs, openjdk-7-jre, - elasticsearch, libxml2-dev, libxslt-dev, git, git-core, libz-dev, libfreetype6-dev, flite, sox] +python: + { + requirements: requirements-vagrant.txt, + virtualenv_location: /home/vagrant/venv, + } +system_packages: + [ + ack-grep, + elasticsearch, + flite, + git, + git-core, + libfreetype6-dev, + libjpeg-dev, + libldap2-dev, + libsasl2-dev, + libxml2-dev, + libxslt-dev, + libz-dev, + linux-headers-generic, + nfs-common, + openjdk-8-jre, + postgresql, + postgresql-client, + postgresql-server-dev-all, + python-dev, + python-setuptools, + sox, + vim-nox, + zsh, + ] user_home: /home/vagrant -vim: {spf13: 'http://j.mp/spf13-vim3', spf13_install: /home/vagrant/spf13.install} -zsh: {oh_my_zsh: 'https://github.com/robbyrussell/oh-my-zsh.git', zshrc: zshrc} +zsh: + { oh_my_zsh: 'https://github.com/robbyrussell/oh-my-zsh.git', zshrc: zshrc } diff --git a/Vagrantfile b/Vagrantfile index c34be64..76b5e64 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -5,36 +5,22 @@ VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| - config.ssh.insert_key = false + config.vm.box = "bento/ubuntu-16.04" - # config.vm.box = "debian/contrib-jessie64" - config.vm.box = "puphpet/debian75-x64" - - config.vm.provision "ansible" do |ansible| - ansible.playbook = ".vagrant_provisioning/playbook.yml" - # ansible.tags = "" - # ansible.verbose = "vvv" + config.vm.define "kdl" do |machine| end config.vm.network "forwarded_port", guest: 8000, host: 8000 config.vm.network "forwarded_port", guest: 5432, host: 5432 config.vm.network "forwarded_port", guest: 9200, host: 9200 - config.vm.network "private_network", ip: "192.168.33.99" - config.vm.provider "virtualbox" do |provider| provider.customize ["modifyvm", :id, "--memory", "1024"] - provider.customize ["modifyvm", :id, "--cableconnected1", "on"] end - config.vm.provider "vmware" do |provider| - provider.customize ["modifyvm", :id, "--memory", "1024"] - end - - # vagrant-hostupdater configuration - config.vm.define "kdl" do |machine| - machine.vm.box = "debian/contrib-jessie64" - machine.vm.hostname = "kdl.vagrant" - machine.vm.network "private_network", ip: "192.168.33.99" + config.vm.provision "ansible" do |ansible| + ansible.playbook = ".vagrant_provisioning/playbook.yml" + # ansible.tags = "" + # ansible.verbose = "vvv" end end diff --git a/requirements.txt b/requirements.txt index 5eeb118..01432f7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ django<2.0 django-activecollab-digger django-compressor -django-countries +django-countries>=5,<6 django-extensions django-grappelli django-libsass