├── .gitignore ├── .rspec ├── .travis.yml ├── CHANGELOG.md ├── Gemfile ├── LICENSE ├── README.md ├── Rakefile ├── VERSION ├── Vagrantfile ├── ansible.cfg ├── defaults └── main.yml ├── envvars-vagrant.sample ├── handlers └── main.yml ├── meta └── main.yml ├── requirements.yml ├── scripts └── release.sh ├── spec ├── default │ └── magento_spec.rb ├── lib │ └── vagrant.rb └── spec_helper.rb ├── tasks ├── install.yml ├── magento.yml ├── main.yml └── modman.yml ├── templates ├── handle_extensions.sh.j2 ├── local.xml.template.j2 ├── magento-install.j2 └── patch.j2 ├── tests ├── hosts ├── playbook.yml ├── requirements.yml └── test.yml └── vars └── main.yml /.gitignore: -------------------------------------------------------------------------------- 1 | ### Files to be ignored by Git ### 2 | 3 | # Ruby 4 | Gemfile.lock 5 | 6 | # Vagrant 7 | /\.vagrant/ 8 | /tests/roles/ 9 | 10 | # IntelliJ IDEA 11 | /*\.ipr 12 | /*\.iws 13 | /\.idea/ 14 | **/*\.iml 15 | 16 | # Eclipse 17 | /\.classpath 18 | /\.project 19 | /\.settings/ 20 | 21 | # Emacs 22 | .*~ 23 | 24 | # Python 25 | **/*.pyc 26 | 27 | # Mac 28 | **/\.DS_Store 29 | 30 | # Custom 31 | /temp/ 32 | /tmp/ 33 | envvars-vagrant 34 | \.*\.swp 35 | \.*\.swo 36 | \.environ 37 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | --format documentation 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: python 3 | python: "2.7" 4 | before_install: 5 | - sudo apt-get update --assume-yes -qq 6 | - sudo apt-get install --assume-yes -qq python-apt python-pycurl 7 | install: 8 | - sudo pip install ansible 9 | script: 10 | - ansible --version 11 | - ansible-playbook --inventory-file tests/hosts --syntax-check tests/playbook.yml 12 | - ansible-playbook --inventory-file tests/hosts --connection=local -vvvv tests/playbook.yml 13 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 2.1.0 2 | Anja Siek (4): 3 | 4 | * fix permissions 5 | * rerun generator 6 | * add vafiable for path to lib role 7 | * fix bare variables; fix lib includes 8 | 9 | # 2.0.2 10 | Anja Siek (1): 11 | 12 | * add option to modify modman-extensions permission 13 | 14 | # 2.0.1 15 | Anja Siek (1): 16 | 17 | * Fixup dependency management 18 | 19 | # 2.0.0 20 | 21 | Anja Siek (3): 22 | 23 | * use code generator 24 | * fix readme and merge conflicts 25 | * add small fixes 26 | 27 | # 1.1.0 28 | 29 | Anja Siek (1): 30 | 31 | * change patch install to local download 32 | 33 | # 1.0.0 34 | 35 | Anja Siek (1): 36 | 37 | * fix magento local download 38 | 39 | # 0.9.0 40 | 41 | Anja Siek (1): 42 | 43 | * allow to only use the modman part of this role 44 | 45 | # 0.8.1 46 | 47 | Mark Kusch (1): 48 | 49 | * Ensure ssh private keys are mode 0600 after cloning this repository with Git 50 | 51 | # 0.8.0 52 | 53 | Anja Siek (7): 54 | 55 | * remove requirement of ssh-keys on remote 56 | * fix variables 57 | * fix documentation 58 | * do not use sudo on local_action 59 | * fix version 60 | 61 | # 0.7.1 62 | 63 | Mark Kusch (2): 64 | 65 | * Make a list of documented variables 66 | * ansible-magento 0.7.1: Fix markdown rendering for documentation 67 | 68 | # 0.7.0 69 | 70 | Anja Siek (1): 71 | 72 | * mv patch-install to default yml add advanced download and copy management 73 | 74 | Mark Kusch (1): 75 | 76 | * Update role documentation to be more precise 77 | 78 | # 0.6.0 79 | 80 | Anja Siek (2): 81 | 82 | * reduce modman downtime 83 | * rename template 84 | 85 | # 0.5.0 86 | 87 | Anja Siek (2): 88 | 89 | * fix umask download 90 | * change permission foobar and split magento install out 91 | 92 | # 0.4.0 93 | 94 | Anja Siek (1): 95 | 96 | * add local.xml.template override 97 | 98 | Mark Kusch (1): 99 | 100 | * Add some minor typo fixes 101 | 102 | 103 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'rake' 4 | gem 'serverspec' 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2014 Silpion IT Solutions GmbH 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ansible magento 2 | 3 | Install/configure magento in different versions (including optional installation of patches). 4 | Allows to configure extensions to be managed with modman. 5 | 6 | ## Variables 7 | 8 | * ``magento_version``: magento version to install (string, default: ``1.7.0.2``) 9 | * ``magento_root``: Configure magento root directory (string, default: ``/var/www/magento``) 10 | * ``magento_bin_dir``: Directory to save binary-files like install-script (string, default: ``/root/bin``) 11 | * ``magento_webuser``: Service user to run magento with (string, default: ``www-data``) 12 | * ``magento_webgroup``: Service group for the ``magento_webuser`` service user (string, default: ``www-data``) 13 | * ``magento_download``: Whether to download magento (boolean, default: ``true``) 14 | * ``magento_download_host``: Mirror URI where to download magento from when ``magento_download`` is true (string, default: ``http://www.magentocommerce.com/downloads/assets/{{ magento_version }}``) 15 | * ``magento_download_package``: Package name for the magento redistributable archive (string, default: ``magento-{{ magento_version }}.tar.gz``) 16 | * ``magento_download_url``: Full Download-Url (string, default: ``{{ magento_download_host }}/{{ magento_download_package }}``) 17 | * ``magento_install``: Whether to install magento even if app/etc/local.xml does not exist (boolean, default: ``false``) 18 | * ``magento_archive_subdir``: Allows to configure a known base directory name within the redistributable archive (string, default: ``magento``) 19 | * ``magento_permissions_list``: Allows to configure access controls for magento internal directory structure (dict, default: ``[]``) 20 | * ``magento_config``: Configure magento (dict, default: see below) 21 | * ``magento_patch_files``: Configure list of patches to apply into magento (list, default: ``[]``) 22 | * ``magento_manage_magento``: If you only want to manage modman extensions set this to false and all the magento-suff will not run (boolean, default: ``true``) 23 | * ``magento_modman``: Wether to install modman into magento (boolean, default: ``true``) 24 | * ``magento_modman_bin_dir``: Directory where to install modman to (string, default: ``magento_bin_dir``) 25 | * ``magento_modman_extensions_git``: List of extensions to be installed/managed with modman from Git resources (dict, default: ``[]``) 26 | * ``magento_modman_extensions_other`` List of non-git extensions to be managed with modman (dict, default: ``[]``) 27 | 28 | 29 | ### magento_permissions_list 30 | 31 | Allows to configure access crontrols for magento internal directory structure. 32 | 33 | ``` 34 | magento_permissions_list: 35 | - mode: "2771" 36 | type: "d" 37 | - mode: "0644" 38 | type: "f" 39 | ``` 40 | 41 | ### magento_config 42 | 43 | Configure magento installation with the following defaults: 44 | 45 | ``` 46 | magento_config: [] 47 | license_agreement_accepted: "yes" 48 | locale: "de_DE" 49 | timezone: "Europe/Berlin" 50 | default_currency: "EUR" 51 | db_host: "localhost" 52 | db_name: "magento" 53 | db_user: "magento" 54 | db_pass: "magento" 55 | url: "http://localhost:8080/" 56 | use_rewrites: "yes" 57 | use_secure: "yes" 58 | secure_base_url: "https://localhost:8080" 59 | use_secure_admin: "yes" 60 | admin_firstname: "Magento" 61 | admin_lastname: "Admin" 62 | admin_email: "magento@test.de" 63 | admin_username: "admin" 64 | admin_password: "magento12" 65 | skip_url_validation: "no" 66 | 67 | ``` 68 | 69 | **NOTE**: Configure ``magento_config.skip_url_validation`` to ``true`` if you install nginx as web server. 70 | 71 | 72 | Example (configure database and disable ssl for admin panel): 73 | 74 | ``` 75 | magento_config: [] 76 | db_host: "localhost" 77 | db_name: "test" 78 | db_user: "testuser" 79 | db_pass: "password" 80 | url: "http://magento-local.de/" 81 | use_secure: "no" 82 | secure_base_url: "" 83 | use_secure_admin: "no" 84 | skip_url_validation: "yes" 85 | ``` 86 | 87 | ### magento_patch_files 88 | 89 | Configure list of patches to apply into magento, e.g. install magento-patch for php5.4 in magento version 1.7.0.2. 90 | 91 | ``` 92 | magento_patch_files: 93 | - url: "http://www.magentocommerce.com/downloads/assets/ce_patches/PATCH_SUPEE-2629_EE_1.12.0.0_v1.sh" 94 | ``` 95 | 96 | ### magento_modman_extensions_git 97 | 98 | List of extensions witch will be cloned from git and linked into magento with modman. 99 | 100 | Required Variables in list: 101 | 102 | ``` 103 | repo 104 | name 105 | dest 106 | ``` 107 | 108 | Optional variables (defaults) 109 | 110 | ``` 111 | version: "HEAD" 112 | remote: "origin" 113 | key_file: None 114 | ssh_opts: None 115 | accept_hostkey: "no" 116 | bare: "no" 117 | depth: 0 118 | executable: "" 119 | reference: "" 120 | gitupdate: "yes" 121 | force: "yes" 122 | 123 | ``` 124 | 125 | Example: 126 | 127 | ``` 128 | magento_modman_extensions_git: 129 | - repo: https://github.com/path/to/repo.git 130 | name: "repo" 131 | dest: /var/www/extensions 132 | - repo: https://github.com/path/to/repo2.git 133 | name: "repo2" 134 | dest: /var/www/extensions 135 | remote: test 136 | force: no 137 | ``` 138 | 139 | ### magento_modman_extensions_other 140 | 141 | List of non-git extensions for modman to link. 142 | 143 | Required Variables in list: 144 | 145 | ``` 146 | dest 147 | ``` 148 | 149 | Example: 150 | 151 | ``` 152 | magento_modman_extensions_other: 153 | - dest: /var/www/extensions/extension 154 | - dest: /var/www/extensions/extension2 155 | ``` 156 | 157 | ## Dependencies 158 | 159 | ### Soft dependencies 160 | 161 | See magento system requirements: http://magento.com/resources/system-requirements 162 | 163 | ### Hard dependencies 164 | 165 | This role depends on [silpion.lib](https://github.com/silpion/ansible-lib) 166 | role. This is configured for ``ansible-galaxy install`` in **requirements.yml**. 167 | 168 | **NOTE**: Check lib configuration Variables to configure privilege escalation, download/upload -path etc. 169 | 170 | **NOTE**: Requirements are installed as virtual user ``silpion`` 171 | (``silpion.lib``). 172 | 173 | Be sure to install required roles with 174 | 175 | ansible-galaxy install --role-file requirements.yml 176 | 177 | ## License 178 | 179 | Apache Version 2.0 180 | 181 | ## Author Information 182 | 183 | Anja Siek @anja.siek silpion.de 184 | 185 | 186 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rake' 2 | require 'rspec/core/rake_task' 3 | 4 | 5 | desc "Run integration tests with serverspec" 6 | RSpec::Core::RakeTask.new(:spec) do |t| 7 | t.pattern = 'spec/*/*_spec.rb' 8 | end 9 | 10 | 11 | desc "Test ansible playbook syntax" 12 | task :lint do 13 | sh %{ansible-playbook --inventory-file tests/hosts --syntax-check tests/test.yml} 14 | end 15 | task :default => :lint 16 | 17 | 18 | desc "vagrant up --no-provision" 19 | task :up do 20 | if ENV['ANSIBLE_MAGENTO_VAGRANT_PROVIDER'] 21 | sh 'vagrant', 'up', '--no-provision', '--provider', ENV['ANSIBLE_MAGENTO_VAGRANT_PROVIDER'] 22 | else 23 | sh %{vagrant up --no-provision} 24 | end 25 | end 26 | 27 | desc "vagrant halt; vagrant destroy --force" 28 | task :clean do 29 | if ENV['RAKE_ANSIBLE_VAGRANT_DONT_CLEANUP'] != '1' 30 | sh %{vagrant halt} 31 | sh %{vagrant destroy --force} 32 | end 33 | end 34 | 35 | desc "vagrant provision" 36 | task :provision => :up do 37 | sh %{vagrant provision} 38 | end 39 | 40 | desc "Run test suite with Vagrant" 41 | task :suite => [ 42 | :lint, 43 | :up, 44 | :provision, 45 | :spec, 46 | :clean 47 | ] 48 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 2.1.0 2 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # vim: set ft=ruby ts=2 sw=2 et: 2 | # -*- mode: ruby -*- 3 | 4 | 5 | VAGRANT_API_VERSION = '2' 6 | Vagrant.configure(VAGRANT_API_VERSION) do |config| 7 | 8 | # user based configuration with nugrant 9 | # - vagrant plugin: https://github.com/maoueh/nugrant 10 | # 11 | # defaults for user configurable items 12 | cfg = { 13 | 'vm' => { 14 | 'box' => 'centos/7', 15 | 'check_update' => false, 16 | 'synced_folders' => false 17 | }, 18 | 'provisioner' => { 19 | 'ansible' => { 20 | 'verbose' => nil, 21 | 'diff' => nil, 22 | 'ask_sudo_pass' => false, 23 | 'ask_vault_pass' => false 24 | } 25 | } 26 | } 27 | 28 | if Vagrant.has_plugin?('nugrant') 29 | # get defaults from cfg as user defaults 30 | config.user.defaults = cfg 31 | c = config.user 32 | else 33 | c = cfg 34 | end 35 | 36 | 37 | # vm configuration 38 | config.vm.box = ENV['ANSIBLE_MAGENTO_VAGRANT_BOXNAME'] || c['vm']['box'] 39 | config.vm.box_check_update = c['vm']['check_update'] 40 | 41 | config.vm.define :ansiblemagentotest do |d| 42 | 43 | d.vm.hostname = 'ansiblemagentotest' 44 | if not c['vm']['synced_folders'] 45 | d.vm.synced_folder '.', '/vagrant', id: 'vagrant-root', disabled: true 46 | d.vm.synced_folder '.', '/home/vagrant/sync', id: 'vagrant-root', disabled: true 47 | end 48 | 49 | # provisioner configuration 50 | d.vm.provision :ansible do |ansible| 51 | # configure ansible-galaxy 52 | ansible.galaxy_roles_path = 'tests/roles/:../' 53 | ansible.galaxy_role_file = 'tests/requirements.yml' 54 | ansible.galaxy_command = 'ansible-galaxy install --role-file=%{role_file} --roles-path=tests/roles/ --ignore-errors --force' 55 | 56 | # configure ansible-playbook 57 | ansible.playbook = 'tests/test.yml' 58 | ansible.groups = { 59 | 'vagrant' => ['ansiblemagentotest'] 60 | } 61 | ansible.limit = 'vagrant' 62 | 63 | # dynamic ansible-playbook configuration based on environment variables 64 | ansible.tags = ENV['ANSIBLE_MAGENTO_VAGRANT_ANSIBLE_TAGS'] 65 | ansible.skip_tags = ENV['ANSIBLE_MAGENTO_VAGRANT_ANSIBLE_SKIP_TAGS'] 66 | # dynamic ansible-playbook configuration based on environment variables or user configuration 67 | ansible.verbose = ENV['ANSIBLE_MAGENTO_VAGRANT_ANSIBLE_VERBOSE'] || c['provisioner']['ansible']['verbose'] 68 | 69 | # ansible-playbook raw arguments 70 | ansible.raw_arguments = [] 71 | 72 | if ENV['ANSIBLE_MAGENTO_VAGRANT_ANSIBLE_CHECKMODE'] == '1' 73 | ansible.raw_arguments << '--check' 74 | end 75 | 76 | if ENV['ANSIBLE_MAGENTO_VAGRANT_ANSIBLE_DIFFMODE'] == '1' or c['provisioner']['ansible']['diff'] 77 | ansible.raw_arguments << '--diff' 78 | end 79 | 80 | end 81 | 82 | d.vm.provider :virtualbox do |v| 83 | v.customize 'pre-boot', ['modifyvm', :id, '--nictype1', 'virtio'] 84 | v.customize [ 'modifyvm', :id, '--name', 'ansiblemagentotest', '--memory', '1024', '--cpus', '1' ] 85 | end 86 | 87 | d.vm.provider :libvirt do |lv| 88 | lv.memory = 1024 89 | lv.cpus = 1 90 | end 91 | 92 | end 93 | 94 | end 95 | -------------------------------------------------------------------------------- /ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | roles_path = tests/roles/:../ 3 | nocows = 1 4 | retry_files_enabled = 0 5 | host_key_checking = 0 6 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | magento_manage_magento: true 3 | magento_root: "/var/www/magento" 4 | magento_download: true 5 | magento_install: false 6 | magento_download_host: "http://www.magentocommerce.com/downloads/assets/{{ magento_version }}" 7 | magento_download_package: "magento-{{ magento_version }}.tar.gz" 8 | magento_download_url: "{{ magento_download_host }}/{{ magento_download_package }}" 9 | #magento_download_url: "https://codeload.github.com/OpenMage/magento-mirror/tar.gz/{{ magento_version }}" 10 | magento_version: "1.7.0.2" 11 | magento_bin_dir: "/root/bin" 12 | 13 | magento_webuser: "www-data" 14 | magento_webgroup: "www-data" 15 | 16 | magento_permissions_list: 17 | - mode: "771" 18 | dir: "{{ magento_root }}/media" 19 | type: "d" 20 | - mode: "771" 21 | dir: "{{ magento_root }}/var" 22 | type: "d" 23 | - mode: "664" 24 | dir: "{{ magento_root }}/var" 25 | type: "f" 26 | 27 | magento_config: [] 28 | 29 | magento_patch_files: [] 30 | 31 | magento_modman: true 32 | magento_modman_bin_dir: "{{ magento_bin_dir }}" 33 | magento_modman_extensions_git: [] 34 | magento_modman_extensions_other: [] 35 | magento_modman_extensions_owner: "{{ magento_webuser }}" 36 | magento_modman_extensions_group: "{{ magento_webgroup }}" 37 | magento_modman_extensions_mode: "0770" 38 | 39 | # path to lib_role 40 | magento_path_to_lib_role: "{{ lib_roles_path|default(playbook_dir + '/roles') }}" 41 | -------------------------------------------------------------------------------- /envvars-vagrant.sample: -------------------------------------------------------------------------------- 1 | export RAKE_ANSIBLE_USE_VAGRANT=1 2 | export ANSIBLE_MAGENTO_VAGRANT_BOXNAME=centos/7 # name of the vagrant box to use for testing 3 | export ANSIBLE_MAGENTO_VAGRANT_PROVIDER=virtualbox # name of the vagrant provider to use for testing 4 | #export ANSIBLE_MAGENTO_VAGRANT_ANSIBLE_TAGS= # Multiple tags can be specified comma seperated 5 | unset ANSIBLE_MAGENTO_VAGRANT_ANSIBLE_TAGS # An empty tags variable leads to an error 6 | #export ANSIBLE_MAGENTO_VAGRANT_ANSIBLE_SKIP_TAGS= # Multiple tags can be specified comma seperated 7 | unset ANSIBLE_MAGENTO_VAGRANT_ANSIBLE_SKIP_TAGS # An empty skip_tags variable leads to an error 8 | export ANSIBLE_MAGENTO_VAGRANT_ANSIBLE_VERBOSE= # May contain one to four 'v's 9 | export ANSIBLE_MAGENTO_VAGRANT_ANSIBLE_CHECKMODE= # 1 to enable, any other value to disable 10 | export ANSIBLE_MAGENTO_VAGRANT_ANSIBLE_DIFFMODE= # 1 to enable, any other value to disable 11 | -------------------------------------------------------------------------------- /handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: handle modman extensions links 3 | become: "{{ lib_action_become_enable }}" 4 | become_user: "{{ lib_action_become_user }}" 5 | notify: modman clean 6 | ignore_errors: yes 7 | command: 8 | sh {{ magento_modman_bin_dir }}/handle_extensions.sh 9 | 10 | - name: modman clean 11 | become: "{{ lib_action_become_enable }}" 12 | become_user: "{{ lib_action_become_user }}" 13 | command: 14 | "{{ magento_modman_bin_dir }}/modman clean" 15 | args: 16 | chdir: "{{ magento_root }}" 17 | 18 | - name: modman deploy-all 19 | become: "{{ lib_action_become_enable }}" 20 | become_user: "{{ lib_action_become_user }}" 21 | command: 22 | "{{ magento_modman_bin_dir }}/modman deploy-all --force" 23 | args: 24 | chdir: "{{ magento_root }}" 25 | 26 | - name: modman repair 27 | become: "{{ lib_action_become_enable }}" 28 | become_user: "{{ lib_action_become_user }}" 29 | command: 30 | "{{ magento_modman_bin_dir }}/modman repair" 31 | args: 32 | chdir: "{{ magento_root }}" 33 | 34 | - name: run magento install 35 | become: "{{ lib_action_become_enable }}" 36 | become_user: "{{ lib_action_become_user }}" 37 | command: 38 | sh {{ magento_bin_dir }}/magento-install.sh 39 | 40 | - name: Verify user 41 | become: "{{ lib_action_become_enable }}" 42 | become_user: "{{ lib_action_become_user }}" 43 | file: 44 | state: directory 45 | path: "{{ magento_root }}" 46 | owner: "{{ magento_webuser }}" 47 | group: "{{ magento_webgroup }}" 48 | recurse: true 49 | 50 | - name: Verify permissions 51 | become: "{{ lib_action_become_enable }}" 52 | become_user: "{{ lib_action_become_user }}" 53 | with_items: "{{ magento_permissions_list}}" 54 | shell: > 55 | find . -type {{ item.type }} -exec 56 | chmod {{ item.mode }} {} \; ; 57 | args: 58 | chdir: "{{ item.dir }}" 59 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | author: Anja Siek 4 | description: Manage Magento installation 5 | company: http://silpion.de 6 | # Some suggested licenses: 7 | # - BSD (default) 8 | # - MIT 9 | # - GPLv2 10 | # - GPLv3 11 | # - Apache 12 | # - CC-BY 13 | license: Apache 2 14 | min_ansible_version: 2.0 15 | # 16 | # Below are all platforms currently available. Just uncomment 17 | # the ones that apply to your role. If you don't see your 18 | # platform on this list, let us know and we'll get it added! 19 | # 20 | platforms: 21 | #- name: EL 22 | # versions: 23 | # - all 24 | # - 5 25 | # - 6 26 | #- name: GenericUNIX 27 | # versions: 28 | # - all 29 | # - any 30 | #- name: Fedora 31 | # versions: 32 | # - all 33 | # - 16 34 | # - 17 35 | # - 18 36 | # - 19 37 | # - 20 38 | #- name: opensuse 39 | # versions: 40 | # - all 41 | # - 12.1 42 | # - 12.2 43 | # - 12.3 44 | # - 13.1 45 | # - 13.2 46 | #- name: Amazon 47 | # versions: 48 | # - all 49 | # - 2013.03 50 | # - 2013.09 51 | #- name: GenericBSD 52 | # versions: 53 | # - all 54 | # - any 55 | #- name: FreeBSD 56 | # versions: 57 | # - all 58 | # - 8.0 59 | # - 8.1 60 | # - 8.2 61 | # - 8.3 62 | # - 8.4 63 | # - 9.0 64 | # - 9.1 65 | # - 9.1 66 | # - 9.2 67 | - name: Ubuntu 68 | versions: 69 | - all 70 | # - lucid 71 | # - maverick 72 | # - natty 73 | # - oneiric 74 | # - precise 75 | # - quantal 76 | # - raring 77 | # - saucy 78 | # - trusty 79 | #- name: SLES 80 | # versions: 81 | # - all 82 | # - 10SP3 83 | # - 10SP4 84 | # - 11 85 | # - 11SP1 86 | # - 11SP2 87 | # - 11SP3 88 | #- name: GenericLinux 89 | # versions: 90 | # - all 91 | # - any 92 | - name: Debian 93 | versions: 94 | # - all 95 | # - etch 96 | # - lenny 97 | # - squeeze 98 | # - wheezy 99 | # 100 | # Below are all categories currently available. Just as with 101 | # the platforms above, uncomment those that apply to your role. 102 | # 103 | categories: 104 | #- cloud 105 | #- cloud:ec2 106 | #- cloud:gce 107 | #- cloud:rax 108 | #- database 109 | #- database:nosql 110 | #- database:sql 111 | - development 112 | #- monitoring 113 | #- networking 114 | #- packaging 115 | #- system 116 | - web 117 | dependencies: 118 | - src: https://github.com/silpion/ansible-lib 119 | name: silpion.lib 120 | # List your role dependencies here, one per line. Only 121 | # dependencies available via galaxy should be listed here. 122 | # Be sure to remove the '[]' above if you add dependencies 123 | # to this list. 124 | 125 | -------------------------------------------------------------------------------- /requirements.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - src: https://github.com/silpion/ansible-lib.git 3 | name: silpion.lib 4 | -------------------------------------------------------------------------------- /scripts/release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ##Always exit on $? -ne 0 4 | set -e 5 | ## 6 | 7 | _cleanup() 8 | { 9 | rm $FILENAME_TMPCHANGELOG &>/dev/null 10 | } 11 | 12 | ##### Create a release for a project managed with a Git repository ##### 13 | 14 | 15 | 16 | ### Functions ### 17 | 18 | # Confirm dialog for user interactions 19 | # Usage: confirm "Question?" 20 | # Returns: 0 = true, 1 = false 21 | confirm() { 22 | read -r -p "$1 [y/n] " response 23 | case $response in 24 | [yY][eE][sS]|[yY]) 25 | return 0;; 26 | *) 27 | return 1;; 28 | esac 29 | } 30 | 31 | ### Display usage message 32 | usage () { 33 | echo "Usage: $0 [-v VERSION] [-r REMOTE] -s 'One line summary of changes for this release'" 34 | exit 0 35 | } 36 | 37 | 38 | ### Initialize the variables and settings ### 39 | #Variables 40 | RELEASE_VERSION= 41 | REMOTE= 42 | SHORT_SUMMARY= 43 | 44 | while getopts v:r:s: OPT; do 45 | case $OPT in 46 | v) RELEASE_VERSION="${OPTARG}";; 47 | r) REMOTE="${OPTARG}";; 48 | s) SHORT_SUMMARY="${OPTARG}";; 49 | esac 50 | done 51 | shift $(( $OPTIND - 1 )); 52 | 53 | if [ -z "${SHORT_SUMMARY}" ]; then 54 | usage && exit 0 55 | fi 56 | 57 | : ${REMOTE:=origin} 58 | 59 | FILENAME_TMPCHANGELOG="$( mktemp --suffix=ansible_role_release_changelog )" 60 | 61 | trap _cleanup ALRM HUP INT TERM EXIT 62 | 63 | # Fetch Git remote inormation 64 | git fetch $REMOTE --tags 65 | 66 | # Some information can be detected 67 | LAST_VERSION=$( git tag -l | tail -n 1 ) 68 | REPOSITORY_NAME=$( git remote show -n $REMOTE | grep Fetch | sed 's#.*/##' | sed 's/\.git//' ) 69 | EXISTING_TAGS=`git tag -l` 70 | 71 | # Detect version if not provided by user 72 | if [[ -z "${RELEASE_VERSION}" ]]; then 73 | RELEASE_VERSION=$(echo $LAST_VERSION|awk -F . '{print $1 "." $2 + 1 "." $3}') 74 | fi 75 | 76 | RELEASE_BRANCH="release/${RELEASE_VERSION}" 77 | # Check if there is already a tag named $RELEASE_VERSION 78 | ## Temporary disabling exit on $? -ne 0 to be able to display error message 79 | set +e 80 | if [[ $EXISTING_TAGS =~ "$RELEASE_VERSION" ]]; then 81 | >&2 echo "A tag $RELEASE_VERSION already exists!" 82 | >&2 echo "Aborting.." 83 | exit 1 84 | fi 85 | set -e 86 | 87 | 88 | # Confirm or exit 89 | echo 90 | echo "Settings for the release to be created:" 91 | echo " Version of last release: ${LAST_VERSION}" 92 | echo " Version of new release: ${RELEASE_VERSION}" 93 | echo " Name of Git repository: ${REPOSITORY_NAME}" 94 | echo " Summary text for release: ${SHORT_SUMMARY}" 95 | if ! confirm "Continue with these settings?"; then 96 | exit 1 97 | fi 98 | 99 | 100 | 101 | ### Perform release ### 102 | 103 | echo 104 | echo "Checkout and pull next branch" 105 | git checkout next 106 | git pull $REMOTE next 107 | 108 | echo 109 | echo "Checkout new release branch" 110 | git checkout -b ${RELEASE_BRANCH} 111 | 112 | echo 113 | echo "Write VERSION file" 114 | echo ${RELEASE_VERSION} > VERSION 115 | 116 | echo 117 | echo "Add release information to CHANGELOG.md file" 118 | 119 | cat CHANGELOG.md > $FILENAME_TMPCHANGELOG 120 | echo "# ${RELEASE_VERSION}" > CHANGELOG.md 121 | echo "" >> CHANGELOG.md 122 | 123 | if [[ -n ${LAST_VERSION} ]]; then 124 | tac <(git shortlog --no-merges next --not ${LAST_VERSION} | sed -e '/^[ \t]/s#^[ \t]*#* #' | perl -pe 's/:$/:\n/g') >> CHANGELOG.md 125 | cat $FILENAME_TMPCHANGELOG >> CHANGELOG.md 126 | else 127 | tac <(git shortlog --no-merges next | sed -e '/^[ \t]/s#^[ \t]*#* #' | perl -pe 's/:$/:\n/g') >> CHANGELOG.md 128 | cat $FILENAME_TMPCHANGELOG >> CHANGELOG.md 129 | fi 130 | echo "Please verify and adjust version information that was prepended to CHANGELOG.md file" 131 | echo "Diff looks like this:" 132 | echo 133 | echo '###### Diff start ######' 134 | 135 | ## Disable exit on $? -ne 0 for the diff command, since it returns $? == 1 if a diff was found 136 | set +e 137 | diff -u $FILENAME_TMPCHANGELOG CHANGELOG.md 138 | set -e 139 | 140 | echo '###### Diff end ######' 141 | echo 142 | echo "In case this is not correct, press ctrl+z to pause this script, adjust CHANGELOG.md and get back using the fg command" 143 | while ! confirm "Continue?"; do 144 | echo "And now?" 145 | done 146 | 147 | echo 148 | echo "Commit generated release information" 149 | rm -f $FILENAME_TMPCHANGELOG 150 | git add VERSION 151 | git add CHANGELOG.md 152 | git commit -m "${REPOSITORY_NAME} ${RELEASE_VERSION}: ${SHORT_SUMMARY}" 153 | 154 | echo 155 | echo "Checkout and pull master branch" 156 | git checkout master 157 | git pull $REMOTE master 158 | 159 | echo 160 | echo "Merge release branch to master branch" 161 | git merge --no-ff --log --no-edit ${RELEASE_BRANCH} 162 | 163 | echo 164 | echo "Create release tag ${RELEASE_VERSION}" 165 | git tag -a ${RELEASE_VERSION} -m "${REPOSITORY_NAME} ${RELEASE_VERSION}: ${SHORT_SUMMARY}" 166 | 167 | echo 168 | echo "Merge release branch to next branch" 169 | git checkout next 170 | git merge ${RELEASE_BRANCH} 171 | 172 | echo 173 | echo "Delete release branch - it's obsolete now" 174 | git branch -d ${RELEASE_BRANCH} 175 | 176 | echo 177 | echo "Push all changes to remote repository" 178 | git push $REMOTE master next ${RELEASE_VERSION} 179 | exit 0 180 | -------------------------------------------------------------------------------- /spec/default/magento_spec.rb: -------------------------------------------------------------------------------- 1 | # http://serverspec.org/resource_types.html 2 | # http://serverspec.org/advanced_tips.html 3 | 4 | # testing operating system specific 5 | # 6 | # either: 7 | # 8 | # if os[:family] == 'redhat' 9 | # if os[:release] == 7 10 | # if os[:arch] == 'x86_64' 11 | # 12 | # nested: 13 | # if os[:family] == 'redhat' 14 | # if os[:release] == 7 15 | # describe resource(...) do 16 | # end 17 | # else 18 | # describe resource(...) do 19 | # end 20 | # end 21 | # 22 | # or: 23 | # 24 | # describe file('...'), :if => os[:family] == 'archlinux' do ... end 25 | # 26 | # or multiple OS share the same test data 27 | # 28 | # describe file('...'), :if => ['archlinux', 'redhat'].include?(os[:family]) do ... end 29 | 30 | require 'spec_helper' 31 | 32 | describe 'Testing ansible-magento local facts' do 33 | describe file('/etc/ansible/facts.d/magento.fact') do 34 | it { should be_file } 35 | it { should be_mode '644' } 36 | it { should be_owned_by 'root' } 37 | it { should be_grouped_into 'root' } 38 | its(:content) { should match /vendor = "Silpion"/ } 39 | its(:content) { should match /vendor_url = "http:\/\/silpion.de"/ } 40 | its(:content) { should match /vendor_github = "https:\/\/github.com\/silpion"/ } 41 | its(:content) { should match /role_version = "0.1.0"/ } 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /spec/lib/vagrant.rb: -------------------------------------------------------------------------------- 1 | class Vagrant 2 | 3 | private 4 | 5 | @ssh_host = nil 6 | @ssh_user = nil 7 | @ssh_keys = nil 8 | @ssh_port = nil 9 | 10 | def initialize 11 | c = `vagrant ssh-config` 12 | if c != '' 13 | c.each_line do |l| 14 | if m = /hostname (.*)/i.match(l) 15 | @ssh_host = m[1] 16 | elsif m = /user (.*)/i.match(l) 17 | @ssh_user = m[1] 18 | elsif m = /identityfile (.*)/i.match(l) 19 | @ssh_keys = [m[1].gsub(/"/, '')] 20 | elsif m = /port (.*)/i.match(l) 21 | @ssh_port = m[1] 22 | end 23 | end 24 | end 25 | end 26 | 27 | public 28 | attr_reader :ssh_host, :ssh_user, :ssh_keys, :ssh_port 29 | 30 | end 31 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'serverspec' 2 | require 'lib/vagrant' 3 | 4 | c = Vagrant.new 5 | 6 | set :backend, :ssh 7 | set :host, c.ssh_host 8 | set :ssh_options, :user => c.ssh_user, :port => c.ssh_port, :keys => c.ssh_keys 9 | 10 | set :env, :LANG => 'C', :LC_MESSAGES => 'C' 11 | set :path, '/usr/local/sbin:/usr/sbin:/sbin:$PATH' 12 | -------------------------------------------------------------------------------- /tasks/install.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Include data persintency 3 | tags: magneto 4 | include: "{{ magento_path_to_lib_role }}/silpion.lib/tasks/datapersistency.yml" 5 | 6 | - name: Download Magento 7 | tags: magento 8 | when: magento_download 9 | include: "{{ magento_path_to_lib_role }}/silpion.lib/tasks/get_url.yml" 10 | vars: 11 | url: "{{ magento_download_url }}" 12 | filename: "{{ magento_download_package }}" 13 | 14 | - name: Upload installation archive 15 | tags: magento 16 | include: "{{ magento_path_to_lib_role }}/silpion.lib/tasks/copy.yml" 17 | vars: 18 | filename: "{{ magento_download_package }}" 19 | 20 | - name: Extract Magento 21 | tags: magento 22 | become: "{{ lib_action_become_enable }}" 23 | become_user: "{{ lib_action_become_user }}" 24 | unarchive: 25 | src: "{{ lib_persistent_data_path_remote }}/{{ magento_download_package }}" 26 | dest: "{{ lib_persistent_data_path_remote }}/" 27 | copy: false 28 | 29 | - name: Change owner and group 30 | tags: magento 31 | become: "{{ lib_action_become_enable }}" 32 | become_user: "{{ lib_action_become_user }}" 33 | file: 34 | state: directory 35 | path: "{{ lib_persistent_data_path_remote }}/{{ magento_archive_subdir|default('magento') }}" 36 | owner: "{{ magento_webuser }}" 37 | group: "{{ magento_webgroup }}" 38 | recurse: true 39 | 40 | - name: Move to Magento-Root-Dir 41 | tags: magento 42 | become: "{{ lib_action_become_enable }}" 43 | become_user: "{{ lib_action_become_user }}" 44 | command: 45 | "rsync -av 46 | -p --chmod=Du=rwx --chmod=Dg=rx --chmod=Do= --chmod=Fu=rw --chmod=Fg=r --chmod=Fo= 47 | {{ lib_persistent_data_path_remote }}/{{ magento_archive_subdir|default('magento') }}/ 48 | {{ magento_root }}/" 49 | 50 | #rsync_opts="--chmod=D2750,--chmod=F640" 51 | # 52 | - name: Create Magento-Install script 53 | tags: magento 54 | become: "{{ lib_action_become_enable }}" 55 | become_user: "{{ lib_action_become_user }}" 56 | template: 57 | src: magento-install.j2 58 | dest: "{{ magento_bin_dir }}/magento-install.sh" 59 | 60 | - name: Remove app/etc/local.xml if exists 61 | tags: magento 62 | become: "{{ lib_action_become_enable }}" 63 | become_user: "{{ lib_action_become_user }}" 64 | file: 65 | state: absent 66 | path: "{{ magento_root }}/app/etc/local.xml" 67 | 68 | - name: Install Magento local.xml.template 69 | tags: magento 70 | become: "{{ lib_action_become_enable }}" 71 | become_user: "{{ lib_action_become_user }}" 72 | template: 73 | src: "{{ magento_local_template|default('local.xml.template.j2') }}" 74 | dest: "{{ magento_root }}/app/etc/local.xml.template" 75 | 76 | - name: Notify install 77 | tags: magento 78 | notify: run magento install 79 | command: /bin/true 80 | -------------------------------------------------------------------------------- /tasks/magento.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Register existing installation 3 | tags: magento 4 | become: "{{ lib_action_become_enable }}" 5 | become_user: "{{ lib_action_become_user }}" 6 | register: magento_register_localxml 7 | stat: 8 | path: "{{ magento_root }}/app/etc/local.xml" 9 | 10 | - name: Set magento_install variable 11 | tags: magento 12 | when: not magento_register_localxml.stat.exists 13 | set_fact: 14 | magento_install: true 15 | 16 | - name: Include Magento Install Tasks 17 | tags: magento 18 | when: magento_install 19 | include: install.yml 20 | 21 | - name: Download magento patch files 22 | tags: magento 23 | with_items: "{{ magento_patch_files }}" 24 | include: "{{ magento_path_to_lib_role }}/silpion.lib/tasks/get_url.yml" 25 | args: 26 | url: "{{ item.url }}" 27 | filename: "{{ item.name }}" 28 | 29 | - name: Upload patch files to Remote 30 | tags: magento 31 | become: "{{ lib_action_become_enable }}" 32 | become_user: "{{ lib_action_become_user }}" 33 | with_items: "{{ magento_patch_files }}" 34 | copy: 35 | src: "{{ lib_persistent_data_path_local }}/{{ item.name }}" 36 | dest: "{{ magento_root }}/" 37 | 38 | - name: Create patch-script 39 | tags: magento 40 | become: "{{ lib_action_become_enable }}" 41 | become_user: "{{ lib_action_become_user }}" 42 | template: 43 | src: patch.j2 44 | dest: "{{ magento_root }}/patch.sh" 45 | 46 | - name: Apply patches 47 | tags: magento 48 | become: "{{ lib_action_become_enable }}" 49 | become_user: "{{ lib_action_become_user }}" 50 | ignore_errors: true 51 | command: 52 | sh patch.sh 53 | args: 54 | chdir: "{{ magento_root }}" 55 | 56 | - name: Notify permissions verify 57 | tags: magento 58 | notify: 59 | - Verify user 60 | - Verify permissions 61 | command: "true" 62 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Include Magento Tasks 3 | tags: magento 4 | when: magento_manage_magento 5 | include: magento.yml 6 | 7 | - name: Include Modman Tasks 8 | tags: 9 | - magento 10 | - modman 11 | when: magento_modman 12 | include: modman.yml 13 | -------------------------------------------------------------------------------- /tasks/modman.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Ensure private key access controls 3 | tags: 4 | - magento 5 | - modman 6 | become: "{{ lib_action_become_enable|default(omit) }}" 7 | become_user: "{{ lib_action_become_user|default(omit) }}" 8 | with_items: "{{ magento_modman_extensions_git }}" 9 | when: item.key_file is defined 10 | local_action: file 11 | args: 12 | state: file 13 | dest: "{{ item.key_file }}" 14 | mode: 0600 15 | 16 | - name: Install modman 17 | tags: 18 | - magento 19 | - modman 20 | become: "{{ lib_action_become_enable }}" 21 | become_user: "{{ lib_action_become_user }}" 22 | get_url: 23 | url: https://raw.github.com/colinmollenhour/modman/master/modman 24 | dest: "{{ magento_modman_bin_dir }}/modman" 25 | mode: 0755 26 | owner: "{{ magento_webuser}}" 27 | group: "{{ magento_webgroup }}" 28 | 29 | - name: Check modman dir exists 30 | tags: 31 | - magento 32 | - modman 33 | become: "{{ lib_action_become_enable }}" 34 | become_user: "{{ lib_action_become_user }}" 35 | register: register_magento_modman_check_modman 36 | stat: 37 | path: "{{ magento_root }}/.modman" 38 | 39 | - name: modman Init magento 40 | tags: 41 | - magento 42 | - modman 43 | become: "{{ lib_action_become_enable }}" 44 | become_user: "{{ lib_action_become_user }}" 45 | when: not register_magento_modman_check_modman.stat.exists 46 | command: 47 | "{{ magento_modman_bin_dir }}/modman init" 48 | args: 49 | chdir: "{{ magento_root }}" 50 | 51 | - name: Check extensions already checked out 52 | tags: 53 | - magento 54 | - modman 55 | become: "{{ lib_action_become_enable|default(omit) }}" 56 | become_user: "{{ lib_action_become_user|default(omit) }}" 57 | register: magento_modman_registered_extensions_dirs 58 | with_items: "{{ magento_modman_extensions_git }}" 59 | local_action: stat 60 | args: 61 | path: "{{ lib_persistent_data_path_local }}.{{ item.name }}" 62 | 63 | - name: Update git remote 64 | tags: 65 | - magento 66 | - modman 67 | become: "{{ lib_action_become_enable|default(omit) }}" 68 | become_user: "{{ lib_action_become_user|default(omit) }}" 69 | when: item[0].stat.isdir is defined and item[0].stat.isdir 70 | with_together: 71 | - magento_modman_registered_extensions_dirs.results 72 | - magento_modman_extensions_git 73 | local_action: shell 74 | "git remote set-url {{ item[1].remote|default('origin') }} {{ item[1].repo }}" 75 | args: 76 | chdir: "{{ lib_persistent_data_path_local }}/{{ item[1].name }}" 77 | 78 | - name: Install Extensions from git 79 | tags: 80 | - magento 81 | - modman 82 | become: "{{ lib_local_action_become_enable|default(omit) }}" 83 | become_user: "{{ lib_local_action_become_user|default(omit) }}" 84 | with_items: "{{ magento_modman_extensions_git }}" 85 | local_action: git 86 | args: 87 | repo: "{{ item.repo }}" 88 | dest: "{{ lib_persistent_data_path_local }}/{{ item.name }}" 89 | remote: "{{ item.remote|default('origin') }}" 90 | key_file: "{{ item.key_file|default(None) }}" 91 | ssh_opts: "{{ item.ssh_opts|default(None) }}" 92 | accept_hostkey: "{{ item.accept_hostkey|default(false) }}" 93 | bare: "{{ item.bare|default(false) }}" 94 | depth: "{{ item.depth|default(0) }}" 95 | executable: "{{ item.executable|default('') }}" 96 | reference: "{{ item.reference|default('') }}" 97 | force: "{{ item.force|default(true) }}" 98 | update: "{{ item.gitupdate|default(true) }}" 99 | version: "{{ item.version|default('HEAD') }}" 100 | 101 | - name: Archive extensions local 102 | tags: 103 | - magento 104 | - modman 105 | become: "{{ lib_local_action_become_enable|default(omit) }}" 106 | become_user: "{{ lib_local_action_become_user|default(omit) }}" 107 | with_items: "{{ magento_modman_extensions_git }}" 108 | local_action: command 109 | git archive --format=tar --output="{{ lib_persistent_data_path_local }}/{{ item.name }}.tar" {{ item.version|default('HEAD') }} 110 | args: 111 | chdir: "{{ lib_persistent_data_path_local }}/{{ item.name }}" 112 | 113 | - name: Install extensions directories 114 | tags: 115 | - magento 116 | - modman 117 | become: "{{ lib_action_become_enable }}" 118 | become_user: "{{ lib_action_become_user }}" 119 | with_items: "{{ magento_modman_extensions_git }}" 120 | file: 121 | state: directory 122 | path: "{{ item.dest }}/{{ item.name }}" 123 | group: "{{ magento_modman_extensions_group }}" 124 | mode: "{{ magento_modman_extensions_mode }}" 125 | owner: "{{ magento_modman_extensions_owner }}" 126 | 127 | - name: Extract Extensions to Remote 128 | tags: 129 | - magento 130 | - modman 131 | become: "{{ lib_action_become_enable }}" 132 | become_user: "{{ lib_action_become_user }}" 133 | with_items: "{{ magento_modman_extensions_git }}" 134 | unarchive: 135 | src: "{{ lib_persistent_data_path_local }}/{{ item.name }}.tar" 136 | dest: "{{ item.dest }}/{{ item.name }}" 137 | group: "{{ magento_modman_extensions_group }}" 138 | mode: "{{ magento_modman_extensions_mode }}" 139 | owner: "{{ magento_modman_extensions_owner }}" 140 | 141 | - name: Create modman template 142 | tags: 143 | - magento 144 | - modman 145 | become: "{{ lib_action_become_enable }}" 146 | become_user: "{{ lib_action_become_user }}" 147 | template: 148 | src: handle_extensions.sh.j2 149 | dest: "{{ magento_modman_bin_dir }}/handle_extensions.sh" 150 | 151 | - name: Notify modman updates 152 | tags: 153 | - magento 154 | - modman 155 | notify: 156 | - handle modman extensions links 157 | - modman deploy-all 158 | command: /bin/true 159 | -------------------------------------------------------------------------------- /templates/handle_extensions.sh.j2: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | new_extensions="{% for item in magento_modman_extensions_git %} {{ item.dest }}/{{ item.name }}/{{ item.subdir|default('') }} {% endfor %} {% for item in magento_modman_extensions_other %} {{ item.dest }}/{{ item.subdir|default('')}} {% endfor %}" 4 | 5 | for file in $(ls -l {{ magento_root }}/.modman/ | awk ' {print $11}'); do 6 | in_file=0; 7 | for nfile in $new_extensions; do 8 | if [ "$file" = "$nfile/" ]; then 9 | in_file=1; 10 | fi 11 | done 12 | if [ $in_file -eq 0 ]; then 13 | rm -f {{ magento_root }}/.modman/$(basename $file); 14 | fi 15 | done 16 | 17 | 18 | for nfile in $new_extensions; do 19 | if [ ! -h {{ magento_root }}/.modman/$(basename $nfile) ]; then 20 | cd {{ magento_root }} 21 | {{ magento_modman_bin_dir }}/modman link $nfile 22 | fi 23 | done 24 | -------------------------------------------------------------------------------- /templates/local.xml.template.j2: -------------------------------------------------------------------------------- 1 | 2 | 28 | 29 | 30 | 31 | {{'{{date}}'}} 32 | 33 | 34 | {{'{{key}}'}} 35 | 36 | false 37 | 38 | 39 | {{'{{db_prefix}}'}} 40 | 41 | 42 | 43 | {{'{{db_host}}'}} 44 | {{'{{db_user}}'}} 45 | {{'{{db_pass}}'}} 46 | {{'{{db_name}}'}} 47 | {{'{{db_init_statemants}}'}} 48 | {{'{{db_model}}'}} 49 | {{'{{db_type}}'}} 50 | {{'{{db_pdo_type}}'}} 51 | 1 52 | 53 | 54 | 55 | {{'{{session_save}}'}} 56 | 57 | 58 | 59 | 60 | 61 | {{'{{admin_frontname}}'}} 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /templates/magento-install.j2: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | /usr/bin/php -f {{ magento_root }}/install.php -- \ 4 | --license_agreement_accepted "{{ magento_config.license_agreement_accepted| default('yes') }}" \ 5 | --locale "{{ magento_config.locale | default ('de_DE') }}" \ 6 | --timezone "{{ magento_config.timezone | default('Europe/Berlin') }}" \ 7 | --default_currency "{{ magento_config.default_currency | default('EUR') }}" \ 8 | --db_host "{{ magento_config.db_host | default('localhost') }}" \ 9 | --db_name "{{ magento_config.db_name | default('magento') }}" \ 10 | --db_user "{{ magento_config.db_user | default('magento') }}" \ 11 | --db_pass "{{ magento_config.db_pass | default('magento') }}" \ 12 | --url "{{ magento_config.url |default('http://localhost:8080/') }}" \ 13 | {% if magento_config.skip_url_validation == "yes" %} --skip_url_validation \{% endif %} 14 | --use_rewrites "{{ magento_config.use_rewrites | default('yes')}}" \ 15 | --use_secure "{{ magento_config.use_secure | default('yes') }}" \ 16 | --secure_base_url "{{ magento_config.secure_base_url |default('https://localhost:8080/') }}" \ 17 | --encryption_key "{{ magento_config.encryption_key | default() }}" \ 18 | --use_secure_admin "{{ magento_config.use_secure_admin| default('yes') }}" \ 19 | --admin_firstname "{{ magento_config.admin_firstname | default('Magento') }}" \ 20 | --admin_lastname "{{ magento_config.admin_lastname | default('Admin')}}" \ 21 | --admin_email "{{ magento_config.admin_email | default('magento@test.de')}}" \ 22 | --admin_username "{{ magento_config.admin_username | default('admin') }}" \ 23 | --admin_password "{{ magento_config.admin_password | default('magento12') }}" 24 | 25 | -------------------------------------------------------------------------------- /templates/patch.j2: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | 5 | 6 | applay_patch() 7 | { 8 | if [ ! -f app/etc/applied.patches.list ]; then 9 | sh $1 10 | else 11 | search=$(grep -B 2 '^__PATCHFILE_FOLLOWS__' $1 | sed -e '/__PATCHFILE_FOLLOWS__/d' | sed '/^$/d') 12 | grep "$search" app/etc/applied.patches.list 13 | res=$? 14 | 15 | if [ $res -eq 1 ]; then 16 | sh $1 17 | fi 18 | fi 19 | } 20 | 21 | 22 | {% for v in magento_patch_files %} 23 | applay_patch "{{ v.name }}" 24 | {% endfor %} 25 | -------------------------------------------------------------------------------- /tests/hosts: -------------------------------------------------------------------------------- 1 | localhost -------------------------------------------------------------------------------- /tests/playbook.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: all 3 | roles: 4 | - { role: ansible-magento } 5 | -------------------------------------------------------------------------------- /tests/requirements.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - src: https://github.com/silpion/ansible-lib 3 | name: silpion.lib 4 | -------------------------------------------------------------------------------- /tests/test.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Test silpion/ansible-magento 3 | hosts: all 4 | pre_tasks: 5 | - name: Install aliases 6 | become: true 7 | with_items: 8 | - "l='ls -lh'" 9 | - "s=systemctl" 10 | - "j=journalctl" 11 | lineinfile: 12 | state: present 13 | dest: /root/.bashrc 14 | line: "alias {{ item }}" 15 | roles: 16 | - ansible-magento 17 | -------------------------------------------------------------------------------- /vars/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # lookup role version 3 | magento_role_version: "{{ lookup('file', role_path + '/VERSION') }}" 4 | --------------------------------------------------------------------------------