diff --git a/Readme.md b/Readme.md index 32f4093..a145f1b 100644 --- a/Readme.md +++ b/Readme.md @@ -9,21 +9,21 @@ Installation * Install vagrant using the installation instructions in the [Getting Started document](https://www.vagrantup.com/docs/getting-started/) * Clone this repository and cd into it * Run ```vagrant up``` in order to set up the box using the ```ansible_local``` provisioner -* You should now have your working +* You should now have your working * Symfony2 Standard Edition under http://192.168.50.4:8081/ * Laravel Quickstart example app under http://192.168.50.4:8082/ -The installation process will create a folder symfony-standard inside -the main directory of the repository. You can now start working inside -this folder directly on your host computer using your favourite IDE. -Changes done there will be reflected directly on the vagrant box as the -directory is mounted in the vagrant box under ```/vagrant```. Also you -can login into the box using ```vagrant ssh``` and have the full control +The installation process will create a folder symfony-standard inside +the main directory of the repository. You can now start working inside +this folder directly on your host computer using your favourite IDE. +Changes done there will be reflected directly on the vagrant box as the +directory is mounted in the vagrant box under ```/vagrant```. Also you +can login into the box using ```vagrant ssh``` and have the full control over processes etc. -As the provisioning using the ansible provisioner is very fast you can +As the provisioning using the ansible provisioner is very fast you can repeat the whole procedure at any time. In order to start fresh just run -```vagrant destroy``` and ```vagrant up```. This will undo all you manual +```vagrant destroy``` and ```vagrant up```. This will undo all you manual changes done on the vagrant box and provide you with a clean setup. Installed components @@ -31,6 +31,7 @@ Installed components * [Nginx](http://nginx.org) * [MySQL](http://dev.mysql.com/downloads/mysql/) +* [PostgreSQL](https://www.postgresql.org/) * [PHP 7.0](http://www.php.net/) * [php-fpm](http://php-fpm.org) * [git](http://git-scm.com/) @@ -45,6 +46,9 @@ Changes ------- ### unreleased +* Added PostgreSQL 9.3 Database + + ### v1.4.1 * Introduce php_version variable, set PHP default version to 7.0 [#33](https://github.com/dirkaholic/vagrant-php-dev-box/pull/33) diff --git a/playbooks/roles/laravel-quickstart/tasks/main.yml b/playbooks/roles/laravel-quickstart/tasks/main.yml index 03a126e..7200570 100644 --- a/playbooks/roles/laravel-quickstart/tasks/main.yml +++ b/playbooks/roles/laravel-quickstart/tasks/main.yml @@ -5,6 +5,39 @@ - name: Create MySQL user for laravel mysql_user: name=laravel password=laravel priv=*.*:ALL state=present +- name: Create PostgreSQL database for laravel + sudo: yes + sudo_user: postgres + postgresql_db: name=laravel state=present + +- name: init database user + postgresql_user: name=laravel password=laravel db=symfony priv=ALL + sudo: yes + sudo_user: postgres + +- name: psql check schema laravel + command: psql -t -d symfony -c "SELECT EXISTS(SELECT 1 FROM pg_namespace WHERE nspname = 'laravel');" + register: check_schema + changed_when: "'f' in '{{ check_schema.stdout }}'" + sudo: yes + sudo_user: postgres + +- name: psql schema laravel + command: psql -d laravel -c "CREATE SCHEMA laravel; ALTER USER laravel SET search_path TO laravel;" + when: check_schema.changed + sudo: yes + sudo_user: postgres + +- name: psql grant access to schema laravel to all + postgresql_privs: database=laravel type=schema objs=laravel roles=PUBLIC privs=USAGE + sudo: yes + sudo_user: postgres + +- name: psql grant access to tables of schema laravel + postgresql_privs: database=laravel schema=laravel type=table objs=ALL_IN_SCHEMA roles=PUBLIC privs=SELECT + sudo: yes + sudo_user: postgres + - name: Clone Laravel quickstart application git: repo=https://github.com/laravel/quickstart-basic dest=/vagrant/laravel-quickstart @@ -54,4 +87,4 @@ dest=/etc/nginx/sites-enabled/laravel.conf state=link notify: - - restart nginx \ No newline at end of file + - restart nginx diff --git a/playbooks/roles/php/tasks/main.yml b/playbooks/roles/php/tasks/main.yml index dcfb046..33a7cf6 100644 --- a/playbooks/roles/php/tasks/main.yml +++ b/playbooks/roles/php/tasks/main.yml @@ -18,6 +18,7 @@ apt: name={{ item }} state=present with_items: - php{{ php_version }}-mysql + - php{{ php_version }}-pgsql - php{{ php_version }}-intl - php{{ php_version }}-cli - php{{ php_version }}-mcrypt @@ -31,4 +32,4 @@ shell: curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer - name: Configure composer cache directory to avoid using slow NFS - shell: composer config --global cache-dir /dev/shm/composer/cache \ No newline at end of file + shell: composer config --global cache-dir /dev/shm/composer/cache diff --git a/playbooks/roles/postgresql/defaults/main.yml b/playbooks/roles/postgresql/defaults/main.yml new file mode 100644 index 0000000..3a203e5 --- /dev/null +++ b/playbooks/roles/postgresql/defaults/main.yml @@ -0,0 +1,2 @@ +--- +locale: UTF-8 diff --git a/playbooks/roles/postgresql/tasks/main.yml b/playbooks/roles/postgresql/tasks/main.yml new file mode 100644 index 0000000..80b60b2 --- /dev/null +++ b/playbooks/roles/postgresql/tasks/main.yml @@ -0,0 +1,32 @@ +- name: Add PostgreSQL repository + apt_repository: repo='deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main' state=present + sudo: yes + +- name: Add PostgreSQL repository key + apt_key: url=https://www.postgresql.org/media/keys/ACCC4CF8.asc state=present + sudo: yes + +- name: Update apt cache + apt: update_cache=yes + sudo: yes + +- name: Install PostgreSQL server + shell: > + LANG={{ locale }} LC_COLLATE={{ locale }} LC_CTYPE={{ locale }} + LC_MESSAGES={{ locale }} LC_MONETARY={{ locale }} + LC_NUMERIC={{ locale }} LC_TIME={{ locale }} + LC_ALL={{ locale }} + apt-get install -y postgresql-9.3 + sudo: yes + +- name: Install PostgreSQL development library + apt: pkg=libpq-dev state=present + sudo: yes + +- name: Install Python Psycopg2 library + apt: pkg=python-psycopg2 state=present + sudo: yes + +- name: Restart postgresql server + service: name=postgresql state=started enabled=yes + sudo: yes diff --git a/playbooks/roles/symfony-standard/tasks/main.yml b/playbooks/roles/symfony-standard/tasks/main.yml index 2b517ce..13a204b 100644 --- a/playbooks/roles/symfony-standard/tasks/main.yml +++ b/playbooks/roles/symfony-standard/tasks/main.yml @@ -5,6 +5,39 @@ - name: Create MySQL user for symfony mysql_user: name=symfony password=symfony priv=*.*:ALL state=present +- name: Create PostgreSQL database for symfony + sudo: yes + sudo_user: postgres + postgresql_db: name=symfony state=present + +- name: init database user + postgresql_user: name=symfony password=symfony db=symfony priv=ALL + sudo: yes + sudo_user: postgres + +- name: psql check schema symfony + command: psql -t -d symfony -c "SELECT EXISTS(SELECT 1 FROM pg_namespace WHERE nspname = 'symfony');" + register: check_schema + changed_when: "'f' in '{{ check_schema.stdout }}'" + sudo: yes + sudo_user: postgres + +- name: psql schema symfony + command: psql -d symfony -c "CREATE SCHEMA symfony; ALTER USER symfony SET search_path TO symfony;" + when: check_schema.changed + sudo: yes + sudo_user: postgres + +- name: psql grant access to schema symfony to all + postgresql_privs: database=symfony type=schema objs=symfony roles=PUBLIC privs=USAGE + sudo: yes + sudo_user: postgres + +- name: psql grant access to tables of schema symfony + postgresql_privs: database=symfony schema=symfony type=table objs=ALL_IN_SCHEMA roles=PUBLIC privs=SELECT + sudo: yes + sudo_user: postgres + - name: Clone Symfony2 standard edition git: repo=https://github.com/symfony/symfony-standard.git dest=/vagrant/symfony-standard @@ -44,4 +77,10 @@ dest=/etc/nginx/sites-enabled/symfony.conf state=link notify: - - restart nginx \ No newline at end of file + - restart nginx + +- name: Change to Symfony development enviroment for reflect the changes directly on the vagrant box + replace: + dest: /vagrant/symfony-standard/web/app.php + regexp: \$kernel = new.*$ + replace: $kernel = new AppKernel('dev', true); diff --git a/playbooks/vagrant.yml b/playbooks/vagrant.yml index 4841caa..f3ab039 100644 --- a/playbooks/vagrant.yml +++ b/playbooks/vagrant.yml @@ -12,8 +12,9 @@ - base - nginx - mysql + - postgresql - php - php-devtools - php-fpm - symfony-standard - - laravel-quickstart \ No newline at end of file + - laravel-quickstart