├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── defaults └── main.yml ├── handlers └── main.yml ├── hooks ├── post_folder_creation.yml └── post_live_switch.yml ├── meta └── main.yml ├── tasks ├── 00-facts.yml ├── 10-config.yml ├── 20-composer.yml ├── 30-cache.yml ├── 40-assets.yml ├── 50-migrations.yml ├── 60-clean_releases.yml ├── empty.yml └── main.yml ├── tests ├── inventory ├── test_2_1.yml ├── test_2_2.yml ├── test_2_3.yml ├── test_2_4.yml ├── test_2_5.yml ├── test_2_6.yml ├── test_2_7.yml ├── test_2_8.yml └── test_3_0.yml └── vars └── main.yml /.gitignore: -------------------------------------------------------------------------------- 1 | ansible.cfg 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: python 3 | python: "2.7" 4 | 5 | sudo: false 6 | 7 | addons: 8 | apt: 9 | packages: 10 | - php-cli 11 | - php-common 12 | - php-curl 13 | 14 | install: 15 | # Install Ansible. 16 | - pip install ansible==1.9.4 17 | 18 | # Add ansible.cfg to pick up roles path. 19 | - "{ echo '[defaults]'; echo 'roles_path = ../'; } >> ansible.cfg" 20 | 21 | # Install required dependencies. 22 | - ansible-galaxy install geerlingguy.php 23 | 24 | script: 25 | # Check the role/playbook's syntax. 26 | #- "ansible-playbook -i tests/inventory tests/test_2_1.yml --syntax-check" 27 | #- "ansible-playbook -i tests/inventory tests/test_2_2.yml --syntax-check" 28 | #- "ansible-playbook -i tests/inventory tests/test_2_3.yml --syntax-check" 29 | #- "ansible-playbook -i tests/inventory tests/test_2_4.yml --syntax-check" 30 | - "ansible-playbook -i tests/inventory tests/test_2_5.yml --syntax-check" 31 | - "ansible-playbook -i tests/inventory tests/test_2_6.yml --syntax-check" 32 | - "ansible-playbook -i tests/inventory tests/test_2_7.yml --syntax-check" 33 | - "ansible-playbook -i tests/inventory tests/test_2_8.yml --syntax-check" 34 | - "ansible-playbook -i tests/inventory tests/test_3_0.yml --syntax-check" 35 | # Run playbooks 36 | #- "ansible-playbook -i tests/inventory tests/test_2_1.yml --connection=local" 37 | #- "ansible-playbook -i tests/inventory tests/test_2_2.yml --connection=local" 38 | #- "ansible-playbook -i tests/inventory tests/test_2_3.yml --connection=local" 39 | #- "ansible-playbook -i tests/inventory tests/test_2_4.yml --connection=local" 40 | - "ansible-playbook -i tests/inventory tests/test_2_5.yml --connection=local" 41 | - "ansible-playbook -i tests/inventory tests/test_2_6.yml --connection=local" 42 | - "ansible-playbook -i tests/inventory tests/test_2_7.yml --connection=local" 43 | - "ansible-playbook -i tests/inventory tests/test_2_8.yml --connection=local" 44 | #- "ansible-playbook -i tests/inventory tests/test_3_0.yml --connection=local" 45 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## v2.1 4 | 5 | * refactoring to have more control over folders when deploying 6 | * more tests for current symfony versions 7 | * compatibility with new symfony folder and command structure 8 | 9 | ## v2.0 10 | 11 | * bugfixes for folders 12 | * stability release 13 | 14 | ## v2.0.1-alpha 15 | 16 | * bugfixes for parameters file 17 | * bugfix for migrations (@vviippola) 18 | * renamed includes to mirror their order 19 | 20 | ## v2.0.0-alpha 21 | reworked and more flexible configuration 22 | 23 | * creates release version in a file per release 24 | * more control over shared folders with additional config options 25 | * possibilities for shallow git copy 26 | * optional cache warmup for sf2 27 | * added tags for specific tasks to allow e.g. cache flush only in later versions 28 | * minified composer.json read overhead 29 | * allow for role hooks 30 | 31 | ## v1.0 32 | 33 | * created stable release for later refactoring 34 | 35 | ## v0.3 36 | 37 | * working travis-ci tests 38 | * datetime release dirs by default 39 | * configurable migrations and schema update 40 | * README update 41 | 42 | ## v0.2 43 | 44 | * fixed merge errors 45 | * fixed deployment issues with config if already exists in project 46 | * fixed issue with missing SYMFONY_ENV while composer install 47 | * fixed composer path variable missing 48 | * added tests directory and travis.yml for testing 49 | 50 | ## v0.1 51 | 52 | * structural refactoring (creating files, directories, ...) 53 | * added cleanup-script to remove old releases 54 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 ServerGrove 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Symfony2 2 | [![Build Status](https://travis-ci.org/servergrove/ansible-symfony2.svg?branch=master)](https://travis-ci.org/servergrove/ansible-symfony2) 3 | 4 | If you use ansible <2.0, please do a ```ansible-galaxy install servergrove.symfony2,v1.9.0``` to get the last backwards-compatible version. 5 | Otherwise you can stick with stable "master" :-) 6 | 7 | Ansible role to easily deploy Symfony2 applications. 8 | It will clone a git repository, a specific branch or a tag, download and run composer install, and run assetic:dump when finished. 9 | The resulting directory structure is similar to what capifony/capistrano creates: 10 | 11 | ``` 12 | project 13 | composer.phar 14 | releases 15 | release 16 | shared 17 | web 18 | uploads 19 | app 20 | config 21 | logs 22 | current -> symlink to latest deployed release 23 | ``` 24 | 25 | It will also keep the ```releases``` directory clean and deletes all but your configured amount of releases. 26 | You're also able to switch on/off whether ansible should execute doctrine migrations, or mongodb schema update, etc. 27 | 28 | ## Requirements 29 | 30 | Installed version of Ansible. 31 | 32 | ## Installation 33 | 34 | ### Ansible galaxy 35 | 36 | ``` 37 | $ ansible-galaxy install servergrove.symfony2 38 | ``` 39 | 40 | ### Usage 41 | 42 | This playbook is taken from the travis testcase. You can always pass these values as commandline parameters. 43 | 44 | ```yaml 45 | --- 46 | - hosts: servers 47 | roles: 48 | - servergrove.symfony2 49 | 50 | vars: 51 | symfony_project_root: /tmp/test_app 52 | symfony_project_name: travis-test 53 | symfony_project_composer_path: /tmp/test_app/shared/composer.phar 54 | symfony_project_repo: https://github.com/symfony/symfony-standard.git 55 | symfony_project_env: prod 56 | 57 | symfony_project_console_opts: '--no-debug' 58 | symfony_project_keep_releases: 5 59 | 60 | symfony_project_branch: "2.6" 61 | symfony_project_php_path: php 62 | symfony_project_keep_releases: 5 63 | 64 | symfony_project_manage_composer: True 65 | symfony_project_composer_opts: '--no-dev --optimize-autoloader --no-interaction' 66 | ``` 67 | 68 | Commandline: ```~$ ansible-playbook -i inventory --extra-vars "symfony_project_release=20150417142505,symfony_project_branch=master" test.yml``` 69 | 70 | ## Role Variables 71 | 72 | ### Possible variables 73 | 74 | These are the possible role variables - you only need to have a small set defined, there are defaults. 75 | 76 | ```yaml 77 | --- 78 | - vars: 79 | # necessary project vars 80 | symfony_project_root: Path where application will be deployed on server. 81 | symfony_project_composer_path: path where composer.phar will be stored (e.g. project_root/shared) 82 | symfony_project_repo: URL of git repository. 83 | symfony_project_release: Release number, can be numeric, we recommend to set it to release date/time, 20140327100911 84 | symfony_project_env: prod 85 | 86 | # optional parameters, covered by defaults 87 | symfony_project_post_folder_creation_tasks: task hook after folder creation 88 | symfony_project_pre_cache_warmup_tasks: after cache warmup 89 | symfony_project_pre_live_switch_tasks: before live symlink is switched 90 | symfony_project_post_live_switch_tasks: after live symlink is switched 91 | 92 | symfony_project_branch: git branch, commit hash or version tag to deploy - defaults to master 93 | symfony_project_php_path: php 94 | symfony_project_php_options: "" 95 | symfony_project_keep_releases: 5 96 | symfony_project_git_clone_depth: 1 # uses git shallow copy 97 | symfony_project_github_token: Auth token for github rate limits 98 | symfony_project_console_opts: '' 99 | symfony_project_console_command: 'app/console' # sf >= 3.0 bin/console 100 | symfony_project_config_dir: 'app/config' # symfony configuration dir 101 | symfony_project_parameters_file: parameters.yml # optional fixed parameters file in shared 102 | symfony_project_cache_command: cache:warmup 103 | 104 | symfony_project_manage_composer: True 105 | symfony_project_composer_opts: '--no-dev --optimize-autoloader --no-interaction' 106 | symfony_project_composer_run_install: True 107 | 108 | symfony_project_enable_cache_warmup: True warmup symfony cache, check out cache command! 109 | symfony_project_fire_schema_update: False # rund mongodb schema update if installed 110 | symfony_project_fire_migrations: run doctrine migrations, if installed 111 | symfony_project_symlink_assets: run assets:create with symlink options 112 | 113 | symfony_project_shared_folders: # folders to be linked from shared directory to release dir 114 | - {name: logs, src: app/logs, path: app/logs} 115 | 116 | symfony_project_managed_folders: # folderst to be created/checked in release dir 117 | - {name: cache, path: app/cache} 118 | ``` 119 | 120 | ### Role variable defaults 121 | 122 | As you can see, the release number default is the current date/time with seconds to allow for easy multiple releases per day. But you can always overwrite with ```--extra-vars=""``` option. 123 | 124 | ```yaml 125 | --- 126 | - vars 127 | symfony_project_release: # internally replaced with YmdHis 128 | symfony_project_branch: master 129 | symfony_project_php_path: /usr/bin/php 130 | symfony_project_keep_releases: 5 131 | symfony_project_git_clone_depth: 1 132 | symfony_project_console_opts: '' 133 | symfony_project_composer_opts: '--no-dev --optimize-autoloader --no-interaction' 134 | symfony_project_fire_migrations: False 135 | symfony_project_symlink_assets: True 136 | ``` 137 | 138 | ## hooks 139 | If you need any more tasks and stuff in your deployment, you now have the option to include hook scripts. 140 | In my projects there's often e.g. a gulp task that has to be started before finishing the release. You're also free to create more folders yourself or do whatever you need. 141 | As an additional goodie, you can use the internal dynamically created facts from main role: 142 | 143 | ```yaml 144 | --- 145 | symfony_project_release # release timestamp 146 | symfony_current_release # release name 147 | symfony_current_release_dir # fully qualified path to release 148 | symfony_shared_dir # shared folder base path 149 | symfony_console # fully qualified console command path 150 | ``` 151 | possible hooks: 152 | 153 | ```yaml 154 | --- 155 | symfony_project_post_folder_creation_tasks: task hook after folder creation 156 | symfony_project_pre_cache_warmup_tasks: after cache warmup 157 | symfony_project_pre_live_switch_tasks: before live symlink is switched 158 | symfony_project_post_live_switch_tasks: after live symlink is switched 159 | ``` 160 | 161 | These hooks trigger an include when defined. 162 | Define hooks: 163 | ```yaml 164 | symfony_project_post_folder_creation_tasks: "{{playbook_dir}}/hooks/post_folder_creation.yml" 165 | ``` 166 | The "hooks" dir should be in your deployment project as a subfolder. I'd recommend to use this name as a convention. Also it's convinient to use the name of the hook task as a yml name. 167 | 168 | ## hook examples 169 | These examples can be found in the package's hooks dir. 170 | 171 | ### php-fpm process restart 172 | E.g. restart php-fpm after successfully finishing deployment. 173 | This is much easier to maintain for different environments. 174 | 175 | Create ```/hooks/post_live_switch.yml```: 176 | 177 | ```yaml 178 | --- 179 | - name: hook | Restart php-fpm 180 | service: name=php5-fpm state=restarted 181 | when: symfony_project_env == "prod" 182 | ``` 183 | 184 | ### create and maintain web/downloads folder 185 | Example for managing additional directories 186 | 187 | Create ```/hooks/post_folder_creation.yml```: 188 | 189 | ```yaml 190 | --- 191 | - name: hook | Create web/uploads folder. 192 | file: state=directory path={{symfony_shared_dir}}/web/uploads 193 | 194 | - name: hook | Symlink to release. 195 | file: state=link src="{{symfony_shared_dir}}/web/uploads" path="{{symfony_current_release_dir}}/web/uploads" 196 | ``` 197 | As an alternative to managing folders via hooks, you can also configure either the shared folders or the creation of folders in your release directory in your confguration: 198 | 199 | ```yaml 200 | --- 201 | symfony_project_shared_folders: # folders to be linked from shared directory to release dir 202 | - {name: logs, src: app/logs, path: app/logs} 203 | - {name: uploads, src: web/uploads, path: web/uploads} 204 | ``` 205 | ## Passing PHP options 206 | 207 | Suppose you need to overide some of php's options on the command line. Simply set the symfony_project_php_options. For example 208 | ```yaml 209 | --- 210 | - hosts: servers 211 | roles: 212 | - servergrove.symfony2 213 | 214 | vars: 215 | symfony_project_root: /tmp/test_app 216 | symfony_project_name: travis-test 217 | symfony_project_composer_path: /tmp/test_app/shared/composer.phar 218 | symfony_project_repo: https://github.com/symfony/symfony-standard.git 219 | symfony_project_env: prod 220 | 221 | symfony_project_console_opts: '--no-debug' 222 | symfony_project_keep_releases: 5 223 | 224 | symfony_project_php_path: php 225 | symfony_project_php_options: -dmemory_limit=512M -dzend.enable_gc=0 226 | ``` 227 | This will set the php variables memory_limit to 512M and zend.enable_gc to 0 when any php command is run, such as composer install or cache:warmup. 228 | 229 | ## Dependencies 230 | 231 | None 232 | 233 | ## Testing 234 | 235 | The deployment contains a basic test, executed by travis. If you want to locally test the role, have a look into ```.travis.yml``` for the exceution statements. Make sure you have a local php executable (needed for composer install and symfony console scripts). 236 | Add a file ```ansible.cfg```to your deployment project folder with contents: 237 | 238 | ``` 239 | [defaults] 240 | roles_path = ../ 241 | ``` 242 | 243 | The test setup looks like this: 244 | 245 | ``` 246 | servergrove.symfony2 247 | tests 248 | inventory # hosts information 249 | test.yml # playbook 250 | .travis.yml # travis config 251 | ``` 252 | 253 | ## License 254 | 255 | [MIT](LICENSE) license 256 | 257 | ### Author Information 258 | 259 | Contributions are welcome: https://github.com/servergrove/ansible-symfony2 260 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # necessary project vars 3 | 4 | #symfony_project_root: "" 5 | #symfony_project_composer_path: "" 6 | #symfony_project_repo: "" 7 | #symfony_project_env: "" 8 | 9 | # hooks 10 | symfony_project_post_folder_creation_tasks: "{{ role_path }}/tasks/empty.yml" 11 | symfony_project_pre_cache_warmup_tasks: "{{ role_path }}/tasks/empty.yml" 12 | symfony_project_pre_live_switch_tasks: "{{ role_path }}/tasks/empty.yml" 13 | symfony_project_post_live_switch_tasks: "{{ role_path }}/tasks/empty.yml" 14 | 15 | symfony_project_release: ~ 16 | symfony_project_branch: master 17 | symfony_project_php_path: php 18 | symfony_project_php_options: "" 19 | symfony_project_keep_releases: 5 20 | symfony_project_git_clone_depth: 1 21 | symfony_project_github_token: ~ 22 | symfony_project_console_opts: "" 23 | symfony_project_console_command: "app/console" 24 | symfony_project_config_dir: "app/config" 25 | symfony_project_parameters_file: parameters.yml 26 | symfony_project_cache_command: cache:warmup 27 | 28 | symfony_project_manage_composer: True 29 | symfony_project_composer_opts: "--no-dev --optimize-autoloader --no-interaction" 30 | symfony_project_composer_run_install: True 31 | 32 | symfony_project_enable_cache_warmup: True 33 | symfony_project_fire_schema_update: False 34 | symfony_project_fire_migrations: False 35 | symfony_project_symlink_assets: True 36 | symfony_project_assetic_dump: True 37 | 38 | # ensured to be absent in release and linked from shared 39 | symfony_project_shared_folders: 40 | - {name: logs, src: app/logs, path: app/logs} 41 | 42 | # ensured to be present 43 | symfony_project_managed_folders: 44 | - {name: cache, path: app/cache} 45 | -------------------------------------------------------------------------------- /handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # handlers file for symfony2 3 | -------------------------------------------------------------------------------- /hooks/post_folder_creation.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: hook | Create web/uploads folder. 3 | file: state=directory path={{ symfony_shared_dir }}/web/uploads 4 | 5 | - name: hook | Symlink to release. 6 | file: state=link src="{{ symfony_shared_dir }}/web/uploads" path="{{ symfony_current_release_dir }}/web/uploads" 7 | -------------------------------------------------------------------------------- /hooks/post_live_switch.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: hook | Restart php-fpm 3 | service: name=php5-fpm state=restarted 4 | when: symfony_project_env == "prod" 5 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | author: servergrove 4 | description: 5 | company: ServerGrove 6 | license: MIT 7 | min_ansible_version: 1.2 8 | # 9 | # Below are all platforms currently available. Just uncomment 10 | # the ones that apply to your role. If you don't see your 11 | # platform on this list, let us know and we'll get it added! 12 | # 13 | #platforms: 14 | #- name: EL 15 | # versions: 16 | # - all 17 | # - 5 18 | # - 6 19 | #- name: GenericUNIX 20 | # versions: 21 | # - all 22 | # - any 23 | #- name: Fedora 24 | # versions: 25 | # - all 26 | # - 16 27 | # - 17 28 | # - 18 29 | # - 19 30 | # - 20 31 | #- name: opensuse 32 | # versions: 33 | # - all 34 | # - 12.1 35 | # - 12.2 36 | # - 12.3 37 | # - 13.1 38 | # - 13.2 39 | #- name: Amazon 40 | # versions: 41 | # - all 42 | # - 2013.03 43 | # - 2013.09 44 | #- name: GenericBSD 45 | # versions: 46 | # - all 47 | # - any 48 | #- name: FreeBSD 49 | # versions: 50 | # - all 51 | # - 8.0 52 | # - 8.1 53 | # - 8.2 54 | # - 8.3 55 | # - 8.4 56 | # - 9.0 57 | # - 9.1 58 | # - 9.1 59 | # - 9.2 60 | #- name: Ubuntu 61 | # versions: 62 | # - all 63 | # - lucid 64 | # - maverick 65 | # - natty 66 | # - oneiric 67 | # - precise 68 | # - quantal 69 | # - raring 70 | # - saucy 71 | # - trusty 72 | #- name: SLES 73 | # versions: 74 | # - all 75 | # - 10SP3 76 | # - 10SP4 77 | # - 11 78 | # - 11SP1 79 | # - 11SP2 80 | # - 11SP3 81 | #- name: GenericLinux 82 | # versions: 83 | # - all 84 | # - any 85 | #- name: Debian 86 | # versions: 87 | # - all 88 | # - etch 89 | # - lenny 90 | # - squeeze 91 | # - wheezy 92 | # 93 | # Below are all categories currently available. Just as with 94 | # the platforms above, uncomment those that apply to your role. 95 | # 96 | categories: 97 | #- cloud 98 | #- cloud:ec2 99 | #- cloud:gce 100 | #- cloud:rax 101 | #- database 102 | #- database:nosql 103 | #- database:sql 104 | #- development 105 | #- monitoring 106 | #- networking 107 | #- packaging 108 | #- system 109 | - web 110 | dependencies: [] 111 | # List your role dependencies here, one per line. Only 112 | # dependencies available via galaxy should be listed here. 113 | # Be sure to remove the '[]' above if you add dependencies 114 | # to this list. -------------------------------------------------------------------------------- /tasks/00-facts.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # simplify folder and command vars 3 | 4 | - name: Check/define release name. 5 | set_fact: symfony_project_release="{{ lookup('pipe', 'date +%Y%m%d%H%M%S') }}" 6 | when: symfony_project_release == None 7 | 8 | - name: Set symfony_current_release. 9 | set_fact: symfony_current_release="{{ symfony_project_release }}_{{ symfony_project_branch }}" 10 | 11 | - name: Set symfony_current_release_dir. 12 | set_fact: symfony_current_release_dir="{{ symfony_project_root }}/releases/{{ symfony_current_release }}" 13 | 14 | - name: Set symfony_shared_dir. 15 | set_fact: symfony_shared_dir="{{ symfony_project_root }}/shared" 16 | 17 | - name: Set symfony_console. 18 | set_fact: symfony_console="{{ symfony_current_release_dir }}/{{ symfony_project_console_command }} --env={{ symfony_project_env }}" 19 | -------------------------------------------------------------------------------- /tasks/10-config.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Check if config dir exists. 3 | stat: path={{ symfony_current_release_dir }}/{{ symfony_project_config_dir }} 4 | register: config_dir 5 | 6 | - name: Set shared config dir. 7 | set_fact: symfony_shared_config_dir={{ symfony_shared_dir }}/{{ symfony_project_config_dir }} 8 | 9 | - name: Set config dir. 10 | set_fact: symfony_config_dir={{ symfony_current_release_dir }}/{{ symfony_project_config_dir }} 11 | 12 | - name: Link configs dir if not yet exists. 13 | file: state=link src={{ symfony_shared_config_dir }} path={{ symfony_config_dir }} 14 | when: not config_dir.stat.exists 15 | 16 | - name: Check if parameters file exists. 17 | stat: path={{ symfony_shared_config_dir }}/{{ symfony_project_parameters_file }} 18 | register: symfony_parameters 19 | 20 | - name: Create symlink for parameters file from shared directory. 21 | file: state=link src={{ symfony_shared_config_dir }}/{{ symfony_project_parameters_file }} path={{ symfony_config_dir }}/{{ symfony_project_parameters_file }} 22 | when: symfony_parameters.stat.exists 23 | -------------------------------------------------------------------------------- /tasks/20-composer.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Check if composer exists. 3 | stat: path={{ symfony_project_composer_path }} 4 | register: composer_file 5 | when: symfony_project_manage_composer 6 | 7 | - name: Install composer. 8 | get_url: url=https://getcomposer.org/composer.phar dest={{ symfony_project_composer_path }} mode=0755 validate_certs=no 9 | when: symfony_project_manage_composer and not composer_file.stat.exists 10 | 11 | - name: Update composer if already exists. 12 | shell: "{{ symfony_project_composer_path }} selfupdate" 13 | when: symfony_project_manage_composer and composer_file.stat.exists 14 | 15 | - name: Add github token 16 | shell: "{{ symfony_project_composer_path }} config -g github-oauth.github.com {{ symfony_project_github_token }}" 17 | when: symfony_project_github_token != None 18 | 19 | - name: Link composer to project dir. 20 | file: state=link src={{ symfony_project_composer_path }} path={{ symfony_current_release_dir }}/composer 21 | when: symfony_project_manage_composer 22 | 23 | - name: Run composer install. 24 | shell: > 25 | cd {{ symfony_current_release_dir }} && export SYMFONY_ENV={{ symfony_project_env }}; {{ symfony_project_php_path }} 26 | {{ symfony_project_php_options }} {{ symfony_project_composer_path }} install {{ symfony_project_composer_opts }} 27 | when: symfony_project_composer_run_install 28 | -------------------------------------------------------------------------------- /tasks/30-cache.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Remove cache dir manually. 3 | file: state=absent path={{ symfony_current_release_dir }}/app/cache/{{ symfony_project_env }} 4 | when: symfony_project_enable_cache_warmup 5 | tags: 6 | - cache 7 | 8 | - name: Warmup sf cache. 9 | shell: > 10 | cd {{ symfony_current_release_dir }} && export SYMFONY_ENV={{ symfony_project_env }}; {{ symfony_project_php_path }} 11 | {{ symfony_project_php_options }} {{ symfony_console }} {{ symfony_project_cache_command }} 12 | {{ symfony_project_console_opts }} 13 | when: symfony_project_enable_cache_warmup 14 | tags: 15 | - cache 16 | -------------------------------------------------------------------------------- /tasks/40-assets.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Dump assetic assets. 3 | shell: > 4 | cd {{ symfony_current_release_dir }} && {{ symfony_project_php_path }} {{ symfony_project_php_options }} 5 | {{ symfony_console }} assetic:dump {{ symfony_project_console_opts }} 6 | when: symfony_project_assetic_dump and composer_content.stdout.find('assetic-bundle') != -1 7 | 8 | - name: Symlink/install assets. 9 | shell: > 10 | cd {{ symfony_current_release_dir }} && {{ symfony_project_php_path }} {{ symfony_project_php_options }} 11 | {{ symfony_console }} assets:install --symlink {{ symfony_project_console_opts }} 12 | when: symfony_project_symlink_assets 13 | -------------------------------------------------------------------------------- /tasks/50-migrations.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Run migrations. 3 | action: shell {{ symfony_project_php_path }} {{ symfony_project_php_options }} {{ symfony_console }} doctrine:migrations:migrate -n 4 | when: symfony_project_fire_migrations and composer_content.stdout.find('doctrine-migrations-bundle') != -1 5 | 6 | - name: Run mongodb schema update. 7 | action: shell {{ symfony_project_php_path }} {{ symfony_project_php_options }} {{ symfony_console }} doctrine:mongodb:schema:update --no-interaction 8 | when: symfony_project_fire_schema_update and composer_content.stdout.find('mongodb-odm') != -1 9 | -------------------------------------------------------------------------------- /tasks/60-clean_releases.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Cleanup releases. 3 | shell: "cd {{ symfony_project_root }}/releases && ls -t1 | tail -n +$(({{ symfony_project_keep_releases }}+1)) |\ 4 | xargs -n1 rm -rf" 5 | when: symfony_project_keep_releases 6 | -------------------------------------------------------------------------------- /tasks/empty.yml: -------------------------------------------------------------------------------- 1 | --- -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # tasks file for symfony2 3 | - include: 00-facts.yml 4 | 5 | - name: Create base deployment directories. 6 | file: state=directory path={{ item.path }} 7 | with_items: 8 | - { path: "{{ symfony_current_release_dir }}" } 9 | - { path: "{{ symfony_shared_dir }}" } 10 | 11 | - name: Create managed shared directories. 12 | file: state=directory path="{{ symfony_shared_dir }}/{{ item.path }}" 13 | with_items: "{{ symfony_project_shared_folders }}" 14 | 15 | - name: Pull sources from the repository. 16 | git: 17 | repo: "{{ symfony_project_repo }}" 18 | dest: "{{ symfony_current_release_dir }}" 19 | version: "{{ symfony_project_branch }}" 20 | accept_hostkey: yes 21 | depth: "{{ symfony_project_git_clone_depth }}" 22 | 23 | - name: Ensure shared folders are absent in release. 24 | file: state=absent path="{{ symfony_current_release_dir }}/{{ item.path }}" 25 | with_items: "{{ symfony_project_shared_folders }}" 26 | 27 | - name: Ensure managed folders are present. 28 | file: state=directory path="{{ symfony_current_release_dir }}/{{ item.path }}" 29 | with_items: "{{ symfony_project_managed_folders }}" 30 | 31 | - name: Read composer.json 32 | shell: cat {{ symfony_current_release_dir }}/composer.json 33 | register: composer_content 34 | 35 | - include: "{{ symfony_project_post_folder_creation_tasks }}" 36 | 37 | - name: Create symlinks to shared directories. 38 | file: 39 | state: link 40 | src: "{{ symfony_shared_dir }}/{{ item.src }}" 41 | path: "{{ symfony_current_release_dir }}/{{ item.path }}" 42 | with_items: "{{ symfony_project_shared_folders }}" 43 | 44 | - include: 10-config.yml 45 | 46 | - include: 20-composer.yml 47 | 48 | - include: "{{ symfony_project_pre_cache_warmup_tasks }}" 49 | 50 | - include: 30-cache.yml 51 | 52 | - include: 40-assets.yml 53 | 54 | - include: 50-migrations.yml 55 | 56 | - name: Create release file. 57 | copy: content="{{ symfony_current_release }}" dest="{{ symfony_current_release_dir }}/RELEASE" mode=644 58 | 59 | - include: "{{ symfony_project_pre_live_switch_tasks }}" 60 | 61 | - name: Create symlink for release. 62 | file: state=link src="{{ symfony_current_release_dir }}" path="{{ symfony_project_root }}/current" 63 | 64 | - include: "{{ symfony_project_post_live_switch_tasks }}" 65 | 66 | - include: 60-clean_releases.yml 67 | -------------------------------------------------------------------------------- /tests/inventory: -------------------------------------------------------------------------------- 1 | localhost -------------------------------------------------------------------------------- /tests/test_2_1.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: localhost 3 | roles: 4 | - ansible-symfony2 5 | 6 | vars: 7 | # necessary project vars 8 | symfony_project_root: /tmp/test_app 9 | symfony_project_name: travis-test 10 | symfony_project_composer_path: /tmp/test_app/shared/composer.phar 11 | symfony_project_repo: https://github.com/symfony/symfony-standard.git 12 | symfony_project_env: prod 13 | 14 | symfony_project_post_folder_creation_tasks: "{{playbook_dir}}/../hooks/post_folder_creation.yml" 15 | 16 | # optional parameters, covered by defaults 17 | symfony_project_console_opts: '--no-debug' 18 | 19 | symfony_project_release: ~ 20 | symfony_project_branch: "2.1" 21 | symfony_project_php_path: php 22 | symfony_project_keep_releases: 5 23 | symfony_project_git_clone_depth: 1 24 | 25 | symfony_project_manage_composer: True 26 | symfony_project_composer_opts: '--no-dev --optimize-autoloader --no-interaction' 27 | 28 | symfony_project_parameters_file: parameters.yml 29 | 30 | symfony_project_enable_post_cmd: True 31 | symfony_project_fire_schema_update: True 32 | symfony_project_fire_migrations: True 33 | -------------------------------------------------------------------------------- /tests/test_2_2.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: localhost 3 | roles: 4 | - ansible-symfony2 5 | 6 | vars: 7 | # necessary project vars 8 | symfony_project_root: /tmp/test_app 9 | symfony_project_name: travis-test 10 | symfony_project_composer_path: /tmp/test_app/shared/composer.phar 11 | symfony_project_repo: https://github.com/symfony/symfony-standard.git 12 | symfony_project_env: prod 13 | 14 | symfony_project_post_folder_creation_tasks: "{{playbook_dir}}/../hooks/post_folder_creation.yml" 15 | 16 | # optional parameters, covered by defaults 17 | symfony_project_console_opts: '--no-debug' 18 | 19 | symfony_project_release: ~ 20 | symfony_project_branch: "2.2" 21 | symfony_project_php_path: php 22 | symfony_project_keep_releases: 5 23 | symfony_project_git_clone_depth: 1 24 | 25 | symfony_project_manage_composer: True 26 | symfony_project_composer_opts: '--no-dev --optimize-autoloader --no-interaction' 27 | 28 | symfony_project_parameters_file: parameters.yml 29 | 30 | symfony_project_enable_post_cmd: True 31 | symfony_project_fire_schema_update: True 32 | symfony_project_fire_migrations: True 33 | -------------------------------------------------------------------------------- /tests/test_2_3.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: localhost 3 | roles: 4 | - ansible-symfony2 5 | 6 | vars: 7 | # necessary project vars 8 | symfony_project_root: /tmp/test_app 9 | symfony_project_name: travis-test 10 | symfony_project_composer_path: /tmp/test_app/shared/composer.phar 11 | symfony_project_repo: https://github.com/symfony/symfony-standard.git 12 | symfony_project_env: prod 13 | 14 | symfony_project_post_folder_creation_tasks: "{{playbook_dir}}/../hooks/post_folder_creation.yml" 15 | 16 | # optional parameters, covered by defaults 17 | symfony_project_console_opts: '--no-debug' 18 | 19 | symfony_project_release: ~ 20 | symfony_project_branch: "2.3" 21 | symfony_project_php_path: php 22 | symfony_project_keep_releases: 5 23 | symfony_project_git_clone_depth: 1 24 | 25 | symfony_project_manage_composer: True 26 | symfony_project_composer_opts: '--no-dev --optimize-autoloader --no-interaction' 27 | 28 | symfony_project_parameters_file: parameters.yml 29 | 30 | symfony_project_enable_post_cmd: True 31 | symfony_project_fire_schema_update: True 32 | symfony_project_fire_migrations: True 33 | -------------------------------------------------------------------------------- /tests/test_2_4.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: localhost 3 | roles: 4 | - ansible-symfony2 5 | 6 | vars: 7 | # necessary project vars 8 | symfony_project_root: /tmp/test_app 9 | symfony_project_name: travis-test 10 | symfony_project_composer_path: /tmp/test_app/shared/composer.phar 11 | symfony_project_repo: https://github.com/symfony/symfony-standard.git 12 | symfony_project_env: prod 13 | 14 | symfony_project_post_folder_creation_tasks: "{{playbook_dir}}/../hooks/post_folder_creation.yml" 15 | 16 | # optional parameters, covered by defaults 17 | symfony_project_console_opts: '--no-debug' 18 | 19 | symfony_project_release: ~ 20 | symfony_project_branch: "2.4" 21 | symfony_project_php_path: php 22 | symfony_project_keep_releases: 5 23 | symfony_project_git_clone_depth: 1 24 | 25 | symfony_project_manage_composer: True 26 | symfony_project_composer_opts: '--no-dev --optimize-autoloader --no-interaction' 27 | 28 | symfony_project_parameters_file: parameters.yml 29 | 30 | symfony_project_enable_post_cmd: True 31 | symfony_project_fire_schema_update: True 32 | symfony_project_fire_migrations: True 33 | -------------------------------------------------------------------------------- /tests/test_2_5.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: localhost 3 | roles: 4 | - ansible-symfony2 5 | 6 | vars: 7 | # necessary project vars 8 | symfony_project_root: /tmp/test_app 9 | symfony_project_name: travis-test 10 | symfony_project_composer_path: /tmp/test_app/shared/composer.phar 11 | symfony_project_repo: https://github.com/symfony/symfony-standard.git 12 | symfony_project_env: prod 13 | 14 | symfony_project_post_folder_creation_tasks: "{{playbook_dir}}/../hooks/post_folder_creation.yml" 15 | 16 | # optional parameters, covered by defaults 17 | symfony_project_console_opts: '--no-debug' 18 | 19 | symfony_project_release: ~ 20 | symfony_project_branch: "2.5" 21 | symfony_project_php_path: php 22 | symfony_project_keep_releases: 5 23 | symfony_project_git_clone_depth: 1 24 | 25 | symfony_project_manage_composer: True 26 | symfony_project_composer_opts: '--no-dev --optimize-autoloader --no-interaction' 27 | 28 | symfony_project_parameters_file: parameters.yml 29 | 30 | symfony_project_enable_post_cmd: True 31 | symfony_project_fire_schema_update: True 32 | symfony_project_fire_migrations: True 33 | -------------------------------------------------------------------------------- /tests/test_2_6.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: localhost 3 | roles: 4 | - ansible-symfony2 5 | 6 | vars: 7 | # necessary project vars 8 | symfony_project_root: /tmp/test_app 9 | symfony_project_name: travis-test 10 | symfony_project_composer_path: /tmp/test_app/shared/composer.phar 11 | symfony_project_repo: https://github.com/symfony/symfony-standard.git 12 | symfony_project_env: prod 13 | 14 | symfony_project_post_folder_creation_tasks: "{{playbook_dir}}/../hooks/post_folder_creation.yml" 15 | 16 | # optional parameters, covered by defaults 17 | symfony_project_console_opts: '--no-debug' 18 | 19 | symfony_project_release: ~ 20 | symfony_project_branch: "2.6" 21 | symfony_project_php_path: php 22 | symfony_project_keep_releases: 5 23 | symfony_project_git_clone_depth: 1 24 | 25 | symfony_project_manage_composer: True 26 | symfony_project_composer_opts: '--no-dev --optimize-autoloader --no-interaction' 27 | 28 | symfony_project_parameters_file: parameters.yml 29 | 30 | symfony_project_enable_post_cmd: True 31 | symfony_project_fire_schema_update: True 32 | symfony_project_fire_migrations: True 33 | -------------------------------------------------------------------------------- /tests/test_2_7.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: localhost 3 | roles: 4 | - ansible-symfony2 5 | 6 | vars: 7 | # necessary project vars 8 | symfony_project_root: /tmp/test_app 9 | symfony_project_name: travis-test 10 | symfony_project_composer_path: /tmp/test_app/shared/composer.phar 11 | symfony_project_repo: https://github.com/symfony/symfony-standard.git 12 | symfony_project_env: prod 13 | 14 | symfony_project_post_folder_creation_tasks: "{{playbook_dir}}/../hooks/post_folder_creation.yml" 15 | 16 | # optional parameters, covered by defaults 17 | symfony_project_console_opts: '--no-debug' 18 | 19 | symfony_project_release: ~ 20 | symfony_project_branch: "2.7" 21 | symfony_project_php_path: php 22 | symfony_project_keep_releases: 5 23 | symfony_project_git_clone_depth: 1 24 | 25 | symfony_project_manage_composer: True 26 | symfony_project_composer_opts: '--no-dev --optimize-autoloader --no-interaction' 27 | 28 | symfony_project_parameters_file: parameters.yml 29 | 30 | symfony_project_enable_post_cmd: True 31 | symfony_project_fire_schema_update: True 32 | symfony_project_fire_migrations: True 33 | -------------------------------------------------------------------------------- /tests/test_2_8.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: localhost 3 | roles: 4 | - ansible-symfony2 5 | 6 | vars: 7 | # necessary project vars 8 | symfony_project_root: /tmp/test_app 9 | symfony_project_name: travis-test 10 | symfony_project_composer_path: /tmp/test_app/shared/composer.phar 11 | symfony_project_repo: https://github.com/symfony/symfony-standard.git 12 | symfony_project_env: prod 13 | 14 | symfony_project_post_folder_creation_tasks: "{{playbook_dir}}/../hooks/post_folder_creation.yml" 15 | 16 | # optional parameters, covered by defaults 17 | symfony_project_console_opts: '--no-debug' 18 | 19 | symfony_project_release: ~ 20 | symfony_project_branch: "2.8" 21 | symfony_project_php_path: php 22 | symfony_project_keep_releases: 5 23 | symfony_project_git_clone_depth: 1 24 | 25 | symfony_project_manage_composer: True 26 | symfony_project_composer_opts: '--no-dev --optimize-autoloader --no-interaction' 27 | 28 | symfony_project_parameters_file: parameters.yml 29 | 30 | symfony_project_enable_post_cmd: True 31 | symfony_project_fire_schema_update: True 32 | symfony_project_fire_migrations: True 33 | -------------------------------------------------------------------------------- /tests/test_3_0.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: localhost 3 | roles: 4 | - ansible-symfony2 5 | 6 | vars: 7 | # necessary project vars 8 | symfony_project_root: /tmp/test_app 9 | symfony_project_name: travis-test 10 | symfony_project_composer_path: /tmp/test_app/shared/composer.phar 11 | symfony_project_repo: https://github.com/symfony/symfony-standard.git 12 | symfony_project_env: prod 13 | 14 | symfony_project_post_folder_creation_tasks: "{{playbook_dir}}/../hooks/post_folder_creation.yml" 15 | 16 | # optional parameters, covered by defaults 17 | symfony_project_console_opts: '--no-debug' 18 | 19 | symfony_project_release: ~ 20 | symfony_project_branch: "3.0.2" 21 | symfony_project_php_path: php 22 | symfony_project_keep_releases: 5 23 | symfony_project_git_clone_depth: 1 24 | 25 | symfony_project_manage_composer: True 26 | symfony_project_composer_opts: '--no-dev -o --no-interaction' 27 | 28 | symfony_project_parameters_file: parameters.yml 29 | 30 | symfony_project_enable_post_cmd: True 31 | symfony_project_fire_schema_update: True 32 | symfony_project_fire_migrations: True 33 | 34 | symfony_project_console_command: 'bin/console' 35 | 36 | symfony_project_shared_folders: 37 | - {name: logs, src: var/logs, path: var/logs} 38 | 39 | symfony_project_managed_folders: 40 | - {name: cache, path: var/cache} -------------------------------------------------------------------------------- /vars/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # vars file for symfony2 3 | --------------------------------------------------------------------------------