├── .gitignore ├── README.md ├── Vagrantfile └── provisioning ├── roles ├── apache │ ├── handlers │ │ └── main.yml │ └── tasks │ │ └── main.yml ├── git │ └── tasks │ │ └── main.yml ├── hhvm │ ├── handlers │ │ └── main.yml │ └── tasks │ │ ├── main.yml │ │ └── pdo_psql.yml ├── mysql │ └── tasks │ │ └── main.yml ├── php │ ├── files │ │ └── php-extra.ini │ ├── handlers │ │ └── main.yml │ └── tasks │ │ └── main.yml ├── postgresql │ └── tasks │ │ └── main.yml ├── symfony │ └── tasks │ │ └── main.yml ├── vagrantbox │ ├── files │ │ └── php.ini │ ├── handlers │ │ └── main.yml │ └── tasks │ │ ├── main.yml │ │ ├── vagrantify_apache.yml │ │ ├── vagrantify_hhvm.yml │ │ ├── vagrantify_php5-fpm.yml │ │ └── vm_swapfile.yml ├── webapp-container │ ├── tasks │ │ └── main.yml │ └── templates │ │ ├── apache2.vhost.j2 │ │ └── php-fpm-pool.conf.j2 └── webapp │ ├── defaults │ └── main.yml │ ├── files │ └── Symfony.gitignore │ └── tasks │ ├── init_app_via_composer.yml │ ├── init_app_via_installer.yml │ └── main.yml └── site.yml /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant 2 | *.phar 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Usage 2 | 3 | You should already have [Vagrant](http://vagrantup.com/) installed. 4 | 5 | Then edit the Vagrantfile to uncomment the application name part, to put your project very own name. 6 | After that simply run 7 | 8 | ```bash 9 | vagrant up 10 | ``` 11 | 12 | Note: if you already have a service using the port 8080, or if you have already use this repository to create an other symfony2 project, you need to the Vagrantfile to chose an other port than 8080, then run `vagrant up` 13 | 14 | The virtual machine will be automatically prepared ("provisioned", through [Ansible](http://docs.ansible.com/) "playbooks") in accordance with the "roles" defined in the `provisioning` directory: 15 | 16 | 0. "apache", "php", "git", etc. installs and configures these system services. 17 | 0. "postgresql" OR "mysql" (depending on the `DBTYPE` variable declared in the `Vagrantfile`) creates the database server and credentials 18 | 0. "symfony" downloads the basic tools required to work with Symfony (-its installer) and PHP (-Composer, for dependency management). 19 | 0. If APPNAME is set in the Vagrantfile, then "webapp" initializes a shiny new application in an eponymous directory. Also if APPNAME is set, "webapp-container" prepares the frontend web server (-a VirtualHost entry) and backend processes (-a FastCGI process group) for your application. 20 | 0. Finally, "vagrantbox" just applies a few additional system-level optimizations to the virtual server. 21 | 22 | You can then go in your virtual machine using `vagrant ssh` and your project's files will be accessible in `/vagrant/your_application_name`. From there you can run composer to install any new additional dependencies you will add, or run the `php app/console ....` of symfony2. 23 | 24 | To open the website itself, you simply need to open `localhost:8080` (if you changed the port, of course replace 8080) in your browser. 25 | 26 | ## Starting off a new project 27 | 28 | Using this template for starting a new Symfony webapp project from scratch, a typical workflow could resemble something like the following: 29 | 1. Initialize a new empty git repo for your project, let's say it is at `http://gitlab.local/projects/my-app-repo.git/ 30 | 2. Clone it into a working copy, thereby setting it's `origin` remote: `cd ~/Projects/; git clone http://gitlab.local/projects/my-app-repo.git/; cd my-app-repo/` 31 | 3. Merge a remote branch originating from this template repo, e.g. `git remote add -t master gh-base https://github.com/we-bridge/vagrant-ansible-symfony.git ; git fetch gh-base; git merge gh-base/master` _or_ simply `git pull https://github.com/we-bridge/vagrant-ansible-symfony.git` 32 | 4. (optional) If the previous commit log bothers you, replace it all with a single commit before doing anything else: `git reset $(git commit-tree HEAD^{tree} -m "Initialized from template")` 33 | 34 | ### Checking out existing projects 35 | Usually `composer install` is run automatically during provisioning. However, if for some reason (network problems? Github API limits?) this step fails, your project will typically generate errors related to `PHP Fatal error: require_once(): Failed opening required '(...)/app/bootstrap.php.cache'` etc, since the cache bootstrap file is built during composer's post-install step. If this happens, simply re-run either `vagrant provision` or `composer install` manually once to fix up these issues. 36 | 37 | ## Requirements 38 | 39 | * ansible > 1.6 40 | 41 | Note: on ubuntu 14.04 you have to install ansible with `pip` rather than `apt-get` 42 | or if you don't want to use `pip` to install system-wide commands, you can install ansible PPA 43 | 44 | ``` 45 | apt-get install python-software-properties 46 | add-apt-repository ppa:ansible/ansible 47 | apt-get update 48 | apt-get install ansible 49 | ``` 50 | 51 | ## Customization 52 | 53 | If you want to replace apache2, by say Nginx, you can still use this repository and simply add an additional role to the provisioning. Pull Request / Patches are welcome. 54 | 55 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | ## Define some app-specific stuff to be used later during provisioning: ## 5 | app_vars = { 6 | # APPNAME: 'MyApplication', 7 | DBNAME: 'symfony', 8 | DBUSER: 'vagrant', 9 | DBPASSWORD: 'vagrant', 10 | DBTYPE: 'postgresql' # 'mysql' or 'postgresql' 11 | } 12 | # ansible_verbosity = 'vvvv' 13 | ########################################################################## 14 | 15 | #Fix for people with strange locale settings 16 | ENV.keys.each {|k| k.start_with?('LC_') && ENV.delete(k)} 17 | 18 | def host_box_is_unixy? 19 | (RUBY_PLATFORM !~ /cygwin|mswin|mingw|bccwin|wince|emx/) 20 | end 21 | 22 | Vagrant.configure(2) do |config| 23 | config.vm.box = "ubuntu/trusty64" 24 | 25 | verbosity_arg = if defined? ansible_verbosity then ansible_verbosity else '' end 26 | if host_box_is_unixy? 27 | config.vm.synced_folder "./", "/vagrant", type: "nfs" 28 | config.vm.provision :ansible do |ansible| 29 | ansible.playbook = 'provisioning/site.yml' 30 | ansible.extra_vars = app_vars 31 | ansible.verbose = verbosity_arg 32 | end 33 | else 34 | config.vm.synced_folder "./", "/vagrant", type: "smb", mount_options: ['ip=192.168.50.1'] #host side of :private_network 35 | extra_vars_arg = '{' + app_vars.map{|k,v| '"' + k.to_s + '":"' + v.to_s + '"'}.join(',') + '}' 36 | 37 | config.vm.provision :shell, :inline => <<-END 38 | set -e 39 | if ! which ansible-playbook ; then 40 | echo "Windows host environment: the devbox will install Ansible and self-provision itself" >&2 41 | sudo apt-get update 42 | sudo apt-get -y install python-software-properties 43 | sudo add-apt-repository ppa:ansible/ansible 44 | sudo apt-get update 45 | sudo apt-get -y install ansible 46 | fi 47 | PYTHONUNBUFFERED=1 ansible-playbook --connection=local -i "[default] $(hostname)," \\ 48 | --extra-vars='#{ extra_vars_arg }' #{ verbosity_arg.empty? ? '' : '-'+ansible_verbosity } /vagrant/provisioning/site.yml 49 | END 50 | end 51 | 52 | config.vm.network "forwarded_port", guest: 80, host: 8080 53 | config.vm.network "private_network", ip: "192.168.50.4" 54 | 55 | end 56 | -------------------------------------------------------------------------------- /provisioning/roles/apache/handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: restart Apache 3 | command: service apache2 restart 4 | 5 | -------------------------------------------------------------------------------- /provisioning/roles/apache/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: APT install package 3 | apt: name=apache2 4 | 5 | - name: enable FastCGI module 6 | apache2_module: name=proxy_fcgi 7 | 8 | - name: enable Rewrite module 9 | apache2_module: name=rewrite 10 | -------------------------------------------------------------------------------- /provisioning/roles/git/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: APT install Git 3 | apt: name=git 4 | 5 | - name: Install Git completions for bash 6 | shell: creates=/etc/bash_completion.d/git 7 | curl -Ls https://github.com/git/git/raw/master/contrib/completion/git-completion.bash > /etc/bash_completion.d/git 8 | -------------------------------------------------------------------------------- /provisioning/roles/hhvm/handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: restart HHVM 3 | command: service hhvm restart 4 | -------------------------------------------------------------------------------- /provisioning/roles/hhvm/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: (purge PHP5-) 3 | apt: name=libapache2-mod-php5,php5-cli state=absent 4 | 5 | - name: software-properties common components 6 | apt: name=software-properties-common 7 | 8 | - name: APT add signing key 9 | apt_key: url=http://dl.hhvm.com/conf/hhvm.gpg.key 10 | 11 | - name: APT add repository 12 | apt_repository: repo="deb http://dl.hhvm.com/ubuntu trusty main" 13 | 14 | - name: APT install package 15 | apt: name=hhvm 16 | 17 | - include: pdo_psql.yml 18 | -------------------------------------------------------------------------------- /provisioning/roles/hhvm/tasks/pdo_psql.yml: -------------------------------------------------------------------------------- 1 | --- 2 | -------------------------------------------------------------------------------- /provisioning/roles/mysql/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: MySQL server and client 3 | apt: name=mysql-server,python-mysqldb 4 | 5 | - name: MySQL database init 6 | mysql_db: name={{ DBNAME }} 7 | 8 | - name: MySQL database user 9 | mysql_user: name={{ DBUSER }} password={{ DBPASSWORD }} priv={{ DBNAME }}.*:ALL 10 | -------------------------------------------------------------------------------- /provisioning/roles/php/files/php-extra.ini: -------------------------------------------------------------------------------- 1 | ; priority=90 2 | date.timezone = Asia/Phnom_Penh 3 | 4 | [xdebug] 5 | xdebug.default_enable = 1 6 | xdebug.idekey = "sublime.xdebug" 7 | xdebug.max_nesting_level=250 8 | xdebug.remote_enable = 1 9 | xdebug.remote_autostart = 0 10 | xdebug.remote_handler=dbgp 11 | xdebug.remote_log="/tmp/xdebug.log" 12 | xdebug.remote_host=10.0.2.2 13 | -------------------------------------------------------------------------------- /provisioning/roles/php/handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: restart PHP5-FPM 3 | command: service php5-fpm restart 4 | -------------------------------------------------------------------------------- /provisioning/roles/php/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: (purge HHVM) 3 | apt: name=hhvm state=absent 4 | 5 | - name: PHP 5.x and extensions 6 | apt: name={{ item }} 7 | with_items: 8 | - php5-cli 9 | - php5-curl 10 | - php5-fpm 11 | - php5-pgsql 12 | - php5-mysql 13 | - php5-xdebug 14 | - php5-intl 15 | notify: 16 | restart Apache 17 | 18 | - name: copy php.ini customizations 19 | copy: src=php-extra.ini dest=/etc/php5/mods-available/extra.ini 20 | notify: 21 | - restart PHP5-FPM 22 | 23 | - name: enable php.ini customizations 24 | command: creates=/etc/php5/fpm/conf.d/90-extra.ini 25 | php5enmod extra 26 | -------------------------------------------------------------------------------- /provisioning/roles/postgresql/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: PostgreSQL server and client 3 | apt: name=postgresql-9.3,libpq-dev,python-psycopg2 4 | 5 | - name: PostgreSQL database user 6 | sudo_user: postgres 7 | postgresql_user: name={{ DBUSER }} password={{ DBPASSWORD }} 8 | 9 | - name: PostgreSQL database init 10 | sudo_user: postgres 11 | postgresql_db: name={{ DBNAME }} owner={{ DBUSER }} 12 | 13 | # - name: PostgreSQL database grants 14 | # sudo_user: postgres 15 | # postgresql_privs: db=symfony role=vagrant objs=ALL_IN_SCHEMA priv=ALL 16 | -------------------------------------------------------------------------------- /provisioning/roles/symfony/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: setup PHP Composer 3 | shell: creates=composer.phar chdir={{ APPCOMMONDIR }} 4 | curl -sS https://getcomposer.org/installer | php 5 | sudo_user: vagrant 6 | 7 | - name: setup framework installer 8 | shell: creates=symfony.phar chdir={{ APPCOMMONDIR }} 9 | curl -LsS http://symfony.com/installer > symfony.phar 10 | sudo_user: vagrant 11 | 12 | - name: make framework installer executable 13 | file: path={{ APPCOMMONDIR }}/symfony.phar mode='ugo+x' 14 | 15 | - name: symlink PHAR files 16 | file: src={{ APPCOMMONDIR }}/{{item}}.phar dest=/usr/local/bin/{{item}} state=link 17 | with_items: 18 | - composer 19 | - symfony 20 | -------------------------------------------------------------------------------- /provisioning/roles/vagrantbox/files/php.ini: -------------------------------------------------------------------------------- 1 | ; php options 2 | session.save_handler = files 3 | session.save_path = /var/lib/php5 4 | session.gc_maxlifetime = 1440 5 | 6 | ; hhvm specific 7 | hhvm.log.level = Warning 8 | hhvm.log.always_log_unhandled_exceptions = true 9 | hhvm.log.runtime_error_reporting_level = 8191 10 | hhvm.mysql.typed_results = false 11 | hhvm.libxml.ext_entity_whitelist = file,http 12 | 13 | date.timezone = Asia/Phnom_Penh 14 | 15 | [xdebug] 16 | xdebug.default_enable = 1 17 | xdebug.idekey = "sublime.xdebug" 18 | xdebug.max_nesting_level=250 19 | xdebug.remote_enable = 1 20 | xdebug.remote_autostart = 0 21 | xdebug.remote_handler=dbgp 22 | xdebug.remote_log="/tmp/xdebug.log" 23 | xdebug.remote_host=10.0.2.2 24 | -------------------------------------------------------------------------------- /provisioning/roles/vagrantbox/handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: restart SSH 3 | command: service ssh restart 4 | 5 | - name: enable swapping 6 | command: swapon -a 7 | -------------------------------------------------------------------------------- /provisioning/roles/vagrantbox/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: disable SSHd reverse DNS lookup 3 | lineinfile: dest=/etc/ssh/sshd_config 4 | regexp='^\s*#*\s*UseDNS' 5 | line='UseDNS no' 6 | insertafter=EOF 7 | notify: 8 | restart SSH 9 | 10 | - name: probe for HHVM init 11 | stat: path=/etc/init.d/hhvm 12 | register: hhvm 13 | 14 | - include: vagrantify_apache.yml 15 | 16 | - include: vagrantify_hhvm.yml 17 | when: hhvm.stat.exists 18 | 19 | - include: vagrantify_php5-fpm.yml 20 | when: not hhvm.stat.exists 21 | 22 | - include: vm_swapfile.yml 23 | -------------------------------------------------------------------------------- /provisioning/roles/vagrantbox/tasks/vagrantify_apache.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: apache | disable default site 3 | command: removes=/etc/apache2/sites-enabled/000-default.conf 4 | a2dissite 000-default 5 | notify: 6 | restart Apache 7 | 8 | - name: apache | run process under the 'vagrant' user account 9 | lineinfile: dest=/etc/apache2/envvars 10 | regexp='export {{ item }}' 11 | line='export {{ item }}=vagrant' 12 | with_items: 13 | - APACHE_RUN_USER 14 | - APACHE_RUN_GROUP 15 | notify: 16 | restart Apache 17 | -------------------------------------------------------------------------------- /provisioning/roles/vagrantbox/tasks/vagrantify_hhvm.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: hhvm | php.ini customization 3 | copy: src=php.ini dest=/etc/hhvm/php.ini 4 | notify: 5 | restart HHVM 6 | 7 | - name: hhvm | run process under the 'vagrant' user account 8 | lineinfile: dest=/etc/init.d/hhvm 9 | regexp='^{{ item }}=' 10 | line='{{ item }}="vagrant"' 11 | with_items: 12 | - RUN_AS_USER 13 | - RUN_AS_GROUP 14 | notify: 15 | restart HHVM 16 | -------------------------------------------------------------------------------- /provisioning/roles/vagrantbox/tasks/vagrantify_php5-fpm.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: php5-fpm | start application after the /vagrant share has become available 3 | lineinfile: dest=/etc/init/php5-fpm.conf 4 | regexp='^start on' 5 | line='start on vagrant-mounted' 6 | 7 | - name: php5-fpm | don't hide error logs while in development 8 | replace: dest=/etc/php5/fpm/php.ini 9 | regexp='^(display(_startup)?_errors).*' 10 | replace='\1 = On' 11 | notify: restart PHP5-FPM 12 | -------------------------------------------------------------------------------- /provisioning/roles/vagrantbox/tasks/vm_swapfile.yml: -------------------------------------------------------------------------------- 1 | - name: create system swapfile 2 | shell: creates=/.swapfile 3 | umask u=rw,go= 4 | && dd if=/dev/zero of=/.swapfile bs=1M count=512 5 | && mkswap /.swapfile 6 | 7 | - name: add swapfile to fstab 8 | lineinfile: dest=/etc/fstab 9 | regexp="/.swapfile" 10 | line="/.swapfile none swap sw 0 0" 11 | state=present 12 | notify: 13 | enable swapping 14 | 15 | - name: set swapiness to minimum 16 | sysctl: 17 | name: vm.swappiness 18 | value: "1" 19 | -------------------------------------------------------------------------------- /provisioning/roles/webapp-container/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: create Apache VirtualHost for app 3 | template: src=apache2.vhost.j2 dest=/etc/apache2/sites-available/{{ APPNAME }}.conf 4 | notify: 5 | restart Apache 6 | 7 | - name: add FastCGI worker pool 8 | template: src=php-fpm-pool.conf.j2 dest=/etc/php5/fpm/pool.d/{{ APPNAME }}.conf 9 | notify: 10 | restart PHP5-FPM 11 | 12 | - name: enable Apache VirtualHost for app 13 | command: creates=/etc/apache2/sites-enabled/{{ APPNAME }}.conf 14 | a2ensite {{ APPNAME }} 15 | notify: 16 | restart Apache 17 | 18 | -------------------------------------------------------------------------------- /provisioning/roles/webapp-container/templates/apache2.vhost.j2: -------------------------------------------------------------------------------- 1 | 2 | ServerName Symfony 3 | ServerAlias Symfony 4 | 5 | ErrorLog /var/log/apache2/project_error.log 6 | CustomLog /var/log/apache2/project_access.log combined 7 | 8 | # used for http basic auth and oauth2 bearer token 9 | SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1 10 | 11 | SetEnv SYMFONY__DATABASE__USER {{ DBUSER }} 12 | SetEnv SYMFONY__DATABASE__PASSWORD {{ DBPASSWORD }} 13 | 14 | DocumentRoot {{ APPWEBROOT }} 15 | 16 | AllowOverride None 17 | Require all granted 18 | 19 | ## Start directives copied from standard Sf .htaccess 20 | DirectoryIndex app.php 21 | 22 | RewriteEngine On 23 | 24 | RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ 25 | RewriteRule ^(.*) - [E=BASE:%1] 26 | 27 | RewriteCond %{ENV:REDIRECT_STATUS} ^$ 28 | RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L] 29 | 30 | RewriteCond %{REQUEST_FILENAME} -f 31 | RewriteCond %{REQUEST_URI} .*\.php 32 | # Need to add the phpfpm call here so that php files (including app_dev.php) are passed to FPM 33 | RewriteRule ^(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/%{REQUEST_FILENAME} [P,END] 34 | 35 | RewriteCond %{REQUEST_FILENAME} -f 36 | RewriteRule .? - [L] 37 | 38 | RewriteRule .? %{ENV:BASE}/app.php [L] 39 | 40 | # The main phpfpm call is added at the end to pass php requests through to FPM 41 | RewriteRule ^(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/%{REQUEST_FILENAME} [P,END] 42 | 43 | ## End directives copied from standard Sf .htaccess 44 | 45 | 46 | -------------------------------------------------------------------------------- /provisioning/roles/webapp-container/templates/php-fpm-pool.conf.j2: -------------------------------------------------------------------------------- 1 | [{{ APPNAME }}] 2 | 3 | user = {{ APPUSER }} 4 | group = {{ APPUSER }} 5 | 6 | listen = 127.0.0.1:9000 7 | listen.owner = {{ APPUSER }} 8 | listen.group = {{ APPUSER }} 9 | 10 | pm = dynamic 11 | pm.max_children = 5 12 | pm.start_servers = 2 13 | pm.min_spare_servers = 1 14 | pm.max_spare_servers = 3 15 | 16 | chdir = {{ APPDIR }} 17 | -------------------------------------------------------------------------------- /provisioning/roles/webapp/defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | db_drivers: 3 | mysql: pdo_mysql 4 | postgresql: pdo_pgsql 5 | -------------------------------------------------------------------------------- /provisioning/roles/webapp/files/Symfony.gitignore: -------------------------------------------------------------------------------- 1 | # Cache and logs (Symfony2) 2 | /app/cache/* 3 | /app/logs/* 4 | !app/cache/.gitkeep 5 | !app/logs/.gitkeep 6 | 7 | # Cache and logs (Symfony3) 8 | /var/cache/* 9 | /var/logs/* 10 | !var/cache/.gitkeep 11 | !var/logs/.gitkeep 12 | 13 | # Parameters 14 | /app/config/parameters.yml 15 | /app/config/parameters.ini 16 | 17 | # Managed by Composer 18 | /app/bootstrap.php.cache 19 | /var/bootstrap.php.cache 20 | /bin/* 21 | !bin/console 22 | !bin/symfony_requirements 23 | /vendor/ 24 | 25 | # Assets and user uploads 26 | /web/bundles/ 27 | /web/uploads/ 28 | 29 | # PHPUnit 30 | /app/phpunit.xml 31 | /phpunit.xml 32 | 33 | # Build data 34 | /build/ 35 | 36 | # Composer PHAR 37 | /composer.phar 38 | -------------------------------------------------------------------------------- /provisioning/roles/webapp/tasks/init_app_via_composer.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: initialize application via composer.phar 3 | sudo_user: vagrant 4 | command: creates={{ APPDIR }}/ 5 | /vagrant/composer.phar create-project --no-interaction --quiet symfony/framework-standard-edition {{ APPDIR }} 6 | -------------------------------------------------------------------------------- /provisioning/roles/webapp/tasks/init_app_via_installer.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: initialize application via symfony.phar 3 | sudo_user: vagrant 4 | shell: creates={{ APPDIR }}/ chdir=/tmp 5 | symfony new --no-interaction --quiet {{ APPNAME }}-install 6 | && mv {{ APPNAME }}-install {{ APPDIR }} 7 | 8 | -------------------------------------------------------------------------------- /provisioning/roles/webapp/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: initialize application 3 | sudo_user: vagrant 4 | # include: init_app_via_composer.yml 5 | include: init_app_via_installer.yml 6 | 7 | - name: create parameters.yml based on parameters.yml.dist 8 | sudo_user: vagrant 9 | command: creates={{ APPDIR }}/app/config/parameters.yml 10 | cp {{ APPDIR }}/app/config/parameters.yml.dist {{ APPDIR }}/app/config/parameters.yml 11 | 12 | - name: update parameters.yml database user 13 | replace: > # see https://github.com/ansible/ansible/issues/2769 14 | dest={{ APPDIR }}/app/config/parameters.yml 15 | regexp="{{ item.key }}:.+$" 16 | replace='{{ item.key }}: {{ item.value }}' 17 | with_items: 18 | - {key: database_user, value: "{{ DBUSER }}" } 19 | - {key: database_password, value: "{{ DBPASSWORD }}"} 20 | 21 | - name: update config.yml with correct DB adapter 22 | replace: > 23 | dest={{ APPDIR }}/app/config/config.yml 24 | regexp="(driver:\s+)pdo_.+$" 25 | replace='\1{{ db_drivers[DBTYPE] }}' 26 | 27 | - name: allow vagrant host to access dev frontend controller 28 | replace: dest={{ APPWEBROOT }}/app_dev.php 29 | regexp="array\('127.0.0.1'" 30 | replace="array('10.0.2.2', '127.0.0.1'" 31 | 32 | - name: default gitignore 33 | copy: src=Symfony.gitignore dest={{ APPDIR }}/.gitignore force=no 34 | 35 | - name: install app dependencies (composer install) 36 | sudo_user: vagrant 37 | command: creates={{ APPDIR }}/vendor/ chdir={{ APPDIR }} 38 | composer install --quiet --no-ansi --no-interaction 39 | -------------------------------------------------------------------------------- /provisioning/site.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: all 3 | sudo: yes 4 | vars: 5 | APPDIR: "/vagrant/{{ APPNAME }}" 6 | when: APPNAME is defined 7 | APPWEBROOT: "{{ APPDIR }}/web" 8 | when: APPNAME is defined 9 | APPCOMMONDIR: "/vagrant" 10 | APPUSER: "vagrant" 11 | 12 | pre_tasks: 13 | - name: check last APT update time 14 | apt: update_cache=yes cache_valid_time=86400 15 | 16 | roles: 17 | - apache 18 | - "{{ DBTYPE }}" 19 | # - hhvm 20 | - php 21 | - git 22 | - symfony 23 | - { role: webapp, when: APPNAME is defined } 24 | - { role: webapp-container, when: APPNAME is defined } 25 | - vagrantbox 26 | --------------------------------------------------------------------------------