├── .travis.yml
├── LICENSE
├── README.md
├── Vagrantfile
├── defaults
└── main.yml
├── handlers
└── main.yml
├── meta
└── main.yml
├── sonar.yml
├── tasks
├── analyzer_runner.yml
├── main.yml
├── maven.yml
├── mysql.yml
├── plugins.yml
├── postgresql.yml
├── projects.yml
├── restore.yml
└── sonar.yml
├── templates
├── settings.xml.j2
├── sonar-runner.properties.j2
└── sonar.conf.j2
└── vars
└── main.yml
/.travis.yml:
--------------------------------------------------------------------------------
1 | ---
2 | language: python
3 | python: "2.7"
4 | env:
5 | #- ANSIBLE_VERSION=1.4
6 | #- ANSIBLE_VERSION=1.5
7 | #- ANSIBLE_VERSION=1.6
8 | #- ANSIBLE_VERSION=1.7
9 | - ANSIBLE_VERSION=1.8
10 | before_install:
11 | - sudo apt-get update -qq
12 | - sudo apt-get install -qq python-apt python-pycurl
13 | install:
14 | # Install Ansible.
15 | - pip install ansible==$ANSIBLE_VERSION
16 | script:
17 | - ansible --version
18 | - export ANSIBLE_ROLES_PATH="../"
19 | - echo localhost > inventory
20 | - ansible-playbook -i inventory --syntax-check sonar.yml
21 | - ansible-playbook -i inventory --connection=local --sudo -vvvv sonar.yml
22 |
--------------------------------------------------------------------------------
/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 {yyyy} {name of copyright owner}
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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # NOT MAINTAINED
2 |
3 | [OLD READ ME](https://github.com/ahelal/ansible-sonar/blob/226b6e2e7c5680d41838e9f31a686e8095ad47e8/README.md)
4 |
--------------------------------------------------------------------------------
/Vagrantfile:
--------------------------------------------------------------------------------
1 | # -*- mode: ruby -*-
2 | # vi: set ft=ruby :
3 |
4 | VAGRANT_BASE_PORT = "99"
5 | VAGRANT_SSH_PORT = "22" + VAGRANT_BASE_PORT
6 | VAGRANT_NETWORK_IP = "192.168.11." + VAGRANT_BASE_PORT
7 |
8 | Vagrant.configure("2") do |config|
9 |
10 | # required to download the box if used for the first time
11 | # vagrant box add ubuntu14 https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-i386-vagrant-disk1.box
12 | config.vm.box = "ubuntu_trusty_x64"
13 |
14 | config.vm.define :master do |master|
15 | #master.vm.network :private_network, ip: VAGRANT_NETWORK_IP
16 | master.vm.provider :virtualbox do |vb|
17 | vb.name = "sonar"
18 | vb.customize ["modifyvm", :id, "--memory", "4096"]
19 | end
20 | master.vm.network "forwarded_port", guest: 22, host: 2222, id: "ssh", disabled: "true"
21 | master.vm.network "forwarded_port", guest: 22, host: VAGRANT_SSH_PORT, auto_correct: true
22 | master.vm.network "forwarded_port", guest: 9000, host: 9000, auto_correct: true
23 | master.vm.network "forwarded_port", guest: 3306, host: 3306, auto_correct: true
24 | end
25 |
26 | end
27 |
--------------------------------------------------------------------------------
/defaults/main.yml:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | sonar_major : "3"
4 | sonar_minor : "7.4"
5 | sonar_listen_ip : "0.0.0.0"
6 | sonar_port : "9000"
7 |
8 | # JDBC Setting
9 | #postgres
10 | #sonar_jdbc_driver : "h2" # postgres, h2 or mysql
11 | #sonar_jdbc_host : "127.0.0.1"
12 | #sonar_jdbc_port : 9092 # h2 default is 9092 postgresql 5432 and mysql is 3306
13 | #sonar_jdbc_user : "sonar"
14 | #sonar_jdbc_pass : "rN88HJkB"
15 | #sonar_jdbc_db : sonar
16 | #sonar_psq_schema : sonar ## PostgreSQL account has permissions to access multiple schemas (check documentation)
17 | #sonar_postgres_sudo_user : postgres
18 | #mysql
19 | sonar_jdbc_driver : "mysql" # postgres, h2 or mysql
20 | sonar_jdbc_host : "127.0.0.1"
21 | sonar_jdbc_port : 3306 # h2 default is 9092 postgresql 5432 and mysql is 3306
22 | sonar_jdbc_user : "sonar"
23 | sonar_jdbc_pass : "Motdepasse12"
24 | sonar_jdbc_db : sonar
25 | sonar_mysql_sudo_user : mysql
26 | sonar_login_user : "root"
27 | sonar_login_password : "Motdepasse12"
28 | sonar_mysql_allowed_hosts:
29 | - 127.0.0.1
30 | - ::1
31 | - localhost
32 |
33 | ## Where to install sonar and Unix user/group
34 | sonar_owner : "sonar"
35 | sonar_group : "sonar"
36 | sonar_shell : "/bin/bash"
37 | sonar_base_dir : "/usr/local/sonar"
38 |
39 | ## JDBC extra option
40 | sonar_jdbc_maxActive : 20
41 | sonar_jdbc_maxIdle : 5
42 | sonar_jdbc_minIdle : 2
43 | sonar_jdbc_maxWait : 5000
44 | sonar_jdbc_minEvictableIdleTimeMillis : 600000
45 | sonar_jdbc_timeBetweenEvictionRunsMillis : 30000
46 |
47 | ## Postgresql user/db install
48 | sonar_postgres_install : False ## By default dont install postgresql
49 | ## Mysql user/db install
50 | sonar_mysql_install : False ## By default dont install mysql
51 |
52 | ## Analyzer (non mavin) SonarQube Runner (plugins)
53 | sonar_analyzer_runner_install : true
54 | sonar_analyzer_runner_version : "2.3"
55 | sonar_analyzer_runner_dir : "{{sonar_base_dir}}/sonar-runner-{{sonar_analyzer_runner_version}}"
56 | sonar_analyzer_runner_file : "sonar-runner-dist-{{sonar_analyzer_runner_version}}.zip"
57 | sonar_analyzer_runner_url : "http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/{{sonar_analyzer_runner_version}}/{{sonar_analyzer_runner_file}}"
58 | sonar_analyzer_runner_host_connect : "127.0.0.1"
59 |
60 | ## Maven
61 | maven_install : true
62 | maven_version_major : '3' # Maven major version number
63 | maven_version_minor : '2' # Maven minor version number
64 | maven_version_patch : '1' # Maven patch version number
65 | maven_mirror : "http://archive.apache.org/dist/maven/maven-{{ maven_version|regex_replace('\\..*', '') }}/{{ maven_version }}/binaries"
66 | maven_redis_sha256sum : 'cdee2fd50b2b4e34e2d67d01ab2018b051542ee759c07354dd7aed6f4f71675c'
67 | maven_bin_path : '/usr/local/bin'
68 | maven_install_dir : '/opt/maven'
69 | maven_version : "{{ maven_version_major }}.{{ maven_version_minor }}.{{ maven_version_patch }}"
70 | maven_redis_filename : "apache-maven-{{ maven_version }}-bin.tar.gz"
71 |
72 | ## sonar_projects:
73 | sonar_projects_base : "{{sonar_base_dir}}/projects"
74 |
75 |
76 | sonar_projects :
77 | - name : "sonar-example"
78 | git : "https://github.com/SonarSource/sonar-examples.git"
79 | version : "master"
80 | cron : ""
81 |
82 | ## Sonar plugins
83 | #
84 | sonar_plugins_apt :
85 | - "pylint" ## pre dependency for python
86 |
87 | sonar_plugins :
88 | - name : "Python Support"
89 | url : "http://dist.sonarsource.com/oss/org/codehaus/sonar-plugins/python/sonar-python-plugin/1.1/sonar-python-plugin-1.1.jar"
90 |
91 | # - name : "Java script support"
92 | # url : "http://dist.sonarsource.com/oss/org/codehaus/sonar-plugins/javascript/sonar-javascript-plugin/1.6/sonar-javascript-plugin-1.6.jar"
93 |
94 | # - name : "Web HTML (included in HTML, JSP, JSF, Ruby, PHP, etc. pages"
95 | # url : "http://dist.sonarsource.com/oss/org/codehaus/sonar-plugins/sonar-web-plugin/2.1/sonar-web-plugin-2.1.jar"
96 |
97 | # - name : "XML support"
98 | # url : "http://dist.sonarsource.com/oss/org/codehaus/sonar-plugins/xml/sonar-xml-plugin/1.0.1/sonar-xml-plugin-1.0.1.jar"
99 |
100 | # - name : "German language"
101 | # url : "http://dist.sonarsource.com/oss/org/codehaus/sonar-plugins/l10n/sonar-l10n-de-plugin/1.0/sonar-l10n-de-plugin-1.0.jar"
102 |
103 | # - name : "Jira"
104 | # url : "http://dist.sonarsource.com/oss/org/codehaus/sonar-plugins/sonar-jira-plugin/1.2/sonar-jira-plugin-1.2.jar"
105 |
106 |
107 | ## Most likely you dont need to edit
108 | sonar_service_state : 'started'
109 | sonar_service_enabled : 'yes'
110 | sonar_version : "{{sonar_major}}.{{sonar_minor}}"
111 | sonar_name : "sonar-{{sonar_version}}"
112 | sonar_archive : "sonar-{{sonar_version}}.zip"
113 | sonar_url : "http://dist.sonar.codehaus.org/{{sonar_archive}}"
114 | sonar_home_dir : "{{sonar_base_dir}}/{{sonar_name}}"
115 | sonar_conf_dir : "{{sonar_home_dir}}/conf"
116 | sonar_bin_dir : "{{sonar_home_dir}}/bin"
117 | sonar_webapp : "{{sonar_home_dir}}/webapps"
118 | sonar_war_dir : "{{sonar_home_dir}}/war/sonar-server/deploy/plugins/"
119 | sonar_ext_dir : "{{sonar_home_dir}}/extensions/plugins/"
120 |
121 | sonar_supported_db :
122 | - postgresql
123 | - h2
124 | - tcp
125 | - mysql
126 |
127 | sonar_restore_install : False ## By default dont install sonar from backup
128 | sonar_backup_temp_folder: "/tmp"
129 | sonar_remote_rsa: "/home/vagrant/.ssh/id_rsa" # RSA key used when sonar is created from backup
130 | sonar_remote_user: "{{ sonar_user }}"
131 | sonar_remote_backup_name: "sonar37"
132 | sonar_remote_backup_archive: "{{ sonar_remote_backup_name }}.sql.gz"
133 | sonar_remote_ip: "127.0.0.1"
134 | sonar_backup_number: 100
135 |
--------------------------------------------------------------------------------
/handlers/main.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: restart sonar
3 | service:
4 | name=sonar
5 | state=restarted
6 | enabled={{sonar_service_enabled}}
7 | notify: wait for sonar to start
8 |
9 | - name: wait for sonar to start
10 | wait_for:
11 | port={{sonar_port}}
12 | timeout=180
--------------------------------------------------------------------------------
/meta/main.yml:
--------------------------------------------------------------------------------
1 | ---
2 | dependencies: []
3 |
4 | galaxy_info:
5 | author: Adham Helal
6 | description: "Deploy sonar qube on Ubuntu 12.04"
7 | min_ansible_version: 1.6
8 | platforms:
9 | - name: Ubuntu
10 | versions:
11 | - precise
12 | categories:
13 | - development
14 |
--------------------------------------------------------------------------------
/sonar.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - hosts: all
3 | sudo: true
4 | roles:
5 | - { role: ./ }
6 |
7 | #- include: ./integration-tests.yml
8 |
--------------------------------------------------------------------------------
/tasks/analyzer_runner.yml:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | - name: analyzer_runner | Download
4 | get_url:
5 | url="{{sonar_analyzer_runner_url}}"
6 | dest="/tmp/{{sonar_analyzer_runner_file}}"
7 | tags: analyzer_runner
8 |
9 | - name: analyzer_runner | Create base dir
10 | file:
11 | dest="{{sonar_analyzer_runner_dir}}"
12 | state=directory
13 | owner="{{sonar_owner}}"
14 | group="{{sonar_group}}"
15 | tags: analyzer_runner
16 |
17 | - name: analyzer_runner | Extract archive
18 | unarchive:
19 | src="/tmp/{{sonar_analyzer_runner_file}}"
20 | dest="{{sonar_base_dir}}/"
21 | owner="{{sonar_owner}}"
22 | group="{{sonar_group}}"
23 | copy=no
24 | creates="{{sonar_analyzer_runner_dir}}/conf"
25 | sudo_user: "{{sonar_owner}}"
26 | tags: analyzer_runner
27 | notify: restart sonar
28 |
29 | - name: analyzer_runner | Configuration file
30 | template:
31 | src=sonar-runner.properties.j2
32 | dest="{{sonar_analyzer_runner_dir}}/conf/sonar-runner.properties"
33 | tags: analyzer_runner
34 | notify: restart sonar
35 |
36 | - name: analyzer_runner | bash profile SONAR_RUNNER_HOME
37 | lineinfile:
38 | dest="{{sonar_base_dir}}/.bash_profile"
39 | state=present
40 | create=yes
41 | regexp="SONAR_RUNNER_HOME"
42 | line="export SONAR_RUNNER_HOME={{sonar_analyzer_runner_dir}}"
43 | mode=0644
44 | owner="{{sonar_owner}}"
45 | group="{{sonar_group}}"
46 | tags: analyzer_runner
47 |
48 | - name: analyzer_runner | bash profile PATH
49 | lineinfile:
50 | dest="{{sonar_base_dir}}/.bash_profile"
51 | state=present
52 | create=yes
53 | regexp="PATH"
54 | line="export PATH=$PATH:{{sonar_analyzer_runner_dir}}/bin"
55 | mode=0644
56 | owner="{{sonar_owner}}"
57 | group="{{sonar_group}}"
58 | tags: analyzer_runner
--------------------------------------------------------------------------------
/tasks/main.yml:
--------------------------------------------------------------------------------
1 | ---
2 |
3 |
4 | - include: postgresql.yml
5 | when: sonar_postgres_install
6 |
7 | - include: mysql.yml
8 | when: sonar_mysql_install
9 |
10 | - include: restore.yml
11 | when: sonar_restore_install
12 |
13 | - include: sonar.yml
14 |
15 | - include: analyzer_runner.yml
16 | when: sonar_analyzer_runner_install
17 |
18 | - include: plugins.yml
19 |
20 | - include: maven.yml
21 | when: maven_install
22 |
23 | - include: projects.yml
24 | when: sonar_projects is defined
25 |
--------------------------------------------------------------------------------
/tasks/maven.yml:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | - name: maven | Download Maven
4 | tags: maven
5 | get_url:
6 | dest=/tmp/{{ maven_redis_filename }}
7 | url={{ maven_mirror }}/{{ maven_redis_filename }}
8 | owner=0
9 | group=0
10 | mode=0644
11 | sha256sum={{ maven_redis_sha256sum }}
12 |
13 | - name: maven | Install Maven installation directory
14 | tags: maven
15 | file:
16 | state=directory
17 | owner=0
18 | group=0
19 | mode=0755
20 | dest={{ maven_install_dir }}
21 |
22 | - name: maven | Install Maven
23 | tags: maven
24 | unarchive:
25 | src=/tmp/{{ maven_redis_filename }}
26 | dest={{ maven_install_dir }}
27 | copy=no
28 |
29 | - name: maven | Install Maven bin directory
30 | tags: maven
31 | file:
32 | state=directory
33 | owner=0
34 | group=0
35 | mode=0755
36 | dest={{ maven_bin_path }}
37 |
38 | - name: maven | Install Maven binary
39 | tags: maven
40 | file:
41 | state=link
42 | force=true
43 | src={{ maven_install_dir }}/apache-maven-{{ maven_version }}/bin/mvn
44 | dest={{ maven_bin_path }}/mvn
45 |
46 | - name: maven | Create Maven directory .m2
47 | tags: maven
48 | file:
49 | state=directory
50 | dest="{{sonar_base_dir}}/.m2"
51 | owner="{{sonar_owner}}"
52 | group="{{sonar_group}}"
53 | mode=0755
54 |
55 | - name: maven | Deploy maven settings.xml
56 | tags: maven
57 | template:
58 | src=settings.xml.j2
59 | dest="{{sonar_base_dir}}/.m2/settings.xml"
60 | owner="{{sonar_owner}}"
61 | group="{{sonar_group}}"
62 |
63 | ## might need export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=128m"
64 | ## java home
65 |
--------------------------------------------------------------------------------
/tasks/mysql.yml:
--------------------------------------------------------------------------------
1 | ---
2 |
3 |
4 | - name: mysql | Create sonar mysql database
5 | mysql_db: >
6 | name={{ sonar_jdbc_db }}
7 | state=present
8 | login_user={{ sonar_login_user}}
9 | login_password={{ sonar_login_password }}
10 | sudo_user: "{{ sonar_mysql_sudo_user }}"
11 | notify: restart sonar
12 | tags: mysql_server
13 |
14 | - name: mysql | Create sonar mysql user
15 | mysql_user: >
16 | name={{ sonar_jdbc_user }}
17 | host={{ item }}
18 | priv={{ sonar_jdbc_db }}.*:ALL
19 | password={{ sonar_jdbc_pass }}
20 | login_user={{ sonar_login_user}}
21 | login_password={{ sonar_login_password }}
22 | with_items: sonar_mysql_allowed_hosts
23 | sudo_user: "{{ sonar_mysql_sudo_user }}"
24 | notify: restart sonar
25 | tags: mysql_server
26 |
27 |
--------------------------------------------------------------------------------
/tasks/plugins.yml:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | - name: plugins | Install pylint
4 | apt:
5 | name="{{item}}"
6 | with_items: sonar_plugins_apt
7 | notify: restart sonar
8 | when: "sonar_plugins_apt is defined and sonar_plugins_apt | count > 0"
9 |
10 | - name: plugins | Download and install plugins
11 | sudo: yes
12 | get_url:
13 | url="{{item.url}}"
14 | dest="{{sonar_ext_dir}}"
15 | with_items: sonar_plugins
16 | sudo_user: "{{sonar_owner}}"
17 | notify: restart sonar
18 | when: "sonar_plugins_apt is defined and sonar_plugins_apt | count > 0"
19 |
--------------------------------------------------------------------------------
/tasks/postgresql.yml:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | - name: postgresql | Create sonar postgresql user
4 | postgresql_user:
5 | name="{{sonar_jdbc_user}}"
6 | password="{{sonar_jdbc_pass}}"
7 | sudo_user: "{{ sonar_postgres_sudo_user }}"
8 | notify: restart sonar
9 | tags: postgresql_server
10 |
11 | - name: postgresql | Create sonar postgresql database
12 | postgresql_db:
13 | name="{{sonar_jdbc_db}}"
14 | owner="{{sonar_jdbc_user}}"
15 | encoding='UTF-8'
16 | lc_collate='en_US.UTF-8'
17 | lc_ctype='en_US.UTF-8'
18 | template='template0'
19 | sudo_user: "{{ sonar_postgres_sudo_user }}"
20 | notify: restart sonar
21 | tags: postgresql_server
22 |
--------------------------------------------------------------------------------
/tasks/projects.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: projects | Install git
3 | apt:
4 | name=git
5 |
6 | - name: projects | Create project directory
7 | sudo: yes
8 | file:
9 | dest="{{sonar_analyzer_runner_dir}}"
10 | state=directory
11 | owner="{{sonar_owner}}"
12 | group="{{sonar_group}}"
13 |
14 | - name: projects | Get All projects from git
15 | git:
16 | repo="{{item.git}}"
17 | dest="{{sonar_projects_base}}/{{item.name}}"
18 | version="{{item.version}}"
19 | with_items: sonar_projects
20 | sudo_user: "{{sonar_owner}}"
21 | when: sonar_projects | count > 0
22 |
23 |
24 | #JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
25 |
--------------------------------------------------------------------------------
/tasks/restore.yml:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | - name: create temp folder
4 | local_action: file
5 | path={{ sonar_backup_temp_folder }}/plugins/ owner=vagrant group=vagrant state=directory
6 |
7 | - name: copy plugins from backup
8 | local_action: synchronize
9 | src="{{ sonar_remote_user }}@{{ sonar_remote_ip }}:/home/jenkins/sonar_backup_files/{{ sonar_backup_number }}/plugins/"
10 | dest="{{ sonar_backup_temp_folder }}/plugins/"
11 | rsync_opts="--rsh='ssh -i {{ sonar_backup_temp_folder }}',--recursive,--compress"
12 |
13 | - name: copy sql dump from backup
14 | local_action: synchronize
15 | src="{{ sonar_remote_user }}@{{ sonar_remote_ip }}:/home/jenkins/sonar_backup_files/{{ sonar_backup_number }}/{{ sonar_remote_backup_archive }}"
16 | dest="{{ sonar_backup_temp_folder }}/"
17 | rsync_opts="--rsh='ssh -i {{ sonar_backup_temp_folder }}',--compress"
18 |
19 | - name: restore plugins from backup
20 | remote_user: sonar
21 | sudo: no
22 | synchronize: src="{{ sonar_backup_temp_folder }}/plugins/" dest="{{ sonar_home_dir }}/plugins/" rsync_opts=--rsh='ssh -i {{ sonar_backup_temp_folder }}',--recursive,--compress
23 |
24 | - name: restore sql dump from backup
25 | remote_user: sonar
26 | sudo: no
27 | synchronize: src="{{ sonar_backup_temp_folder }}/{{ sonar_remote_backup_archive }}" dest="{{ sonar_home_dir }}/" rsync_opts=--rsh='ssh -i {{ sonar_backup_temp_folder }}',--compress
28 |
29 | - name: unpack sqldump
30 | shell: gzip -d {{ sonar_home_dir }}/{{ sonar_remote_backup_archive }}
31 |
32 | - name: switch to sonar db
33 | shell: sed -i "s;{{ sonar_remote_backup_name }};sonar;g" {{ sonar_home_dir }}/{{ sonar_remote_backup_name }}.sql
34 |
35 | - name: set ownership on all sonar files
36 | file: path={{ sonar_home_dir }}/ owner=sonar group=sonar state=directory recurse=true
37 |
38 | - name: import sqldump
39 | shell: mysql -u {{ sonar_jdbc_user }} -p{{ sonar_jdbc_pass }} {{ sonar_jdbc_db }} < {{ sonar_home_dir }}/{{ sonar_remote_backup_name }}.sql
40 |
--------------------------------------------------------------------------------
/tasks/sonar.yml:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | - name: Sonar | Check database choice
4 | fail:
5 | msg="{{sonar_jdbc_driver}} is not a supported database"
6 | when: "sonar_jdbc_driver not in sonar_supported_db"
7 |
8 | - name: Install unzip
9 | apt:
10 | name=unzip
11 | tags: sonar_setup
12 |
13 | - name: Add group "sonar"
14 | group:
15 | name="{{sonar_group}}"
16 | tags: sonar_setup
17 |
18 | - name: Add user "sonar"
19 | user:
20 | name="{{sonar_owner}}"
21 | group="{{sonar_group}}"
22 | home="{{sonar_base_dir}}"
23 | shell="{{sonar_shell}}"
24 | comment="Sonar User"
25 | tags: sonar_setup
26 |
27 | - name: Download sonar
28 | get_url:
29 | url="{{sonar_url}}"
30 | dest="/tmp/{{sonar_archive}}"
31 | tags: sonar_setup
32 |
33 | - name: Create Basedir
34 | sudo: yes
35 | file:
36 | dest="{{sonar_base_dir}}"
37 | state=directory
38 | owner="{{sonar_owner}}"
39 | group="{{sonar_group}}"
40 | tags: sonar_setup
41 |
42 | - name: Extract archive sonar
43 | sudo: yes
44 | unarchive:
45 | src="/tmp/{{sonar_archive}}"
46 | dest="{{sonar_base_dir}}/"
47 | owner="{{sonar_owner}}"
48 | group="{{sonar_group}}"
49 | copy=no
50 | creates="{{sonar_home_dir}}/bin"
51 | notify: restart sonar
52 | sudo_user: "{{sonar_owner}}"
53 | tags: sonar_setup
54 |
55 | - name: create a link to sonar
56 | sudo: yes
57 | file:
58 | src="{{sonar_base_dir}}/{{sonar_name}}"
59 | dest="{{sonar_base_dir}}/sonar{{sonar_major}}"
60 | state=link
61 | owner="{{sonar_owner}}"
62 | group="{{sonar_group}}"
63 | tags: sonar_setup
64 |
65 | - name: Configure sonar server properties
66 | sudo: yes
67 | template:
68 | src=sonar.conf.j2
69 | dest="{{sonar_conf_dir}}/sonar.properties"
70 | tags: sonar_setup
71 | notify: restart sonar
72 |
73 | - name: Install sonar init script
74 | sudo: yes
75 | file:
76 | src="{{sonar_bin_dir}}/linux-x86-{{ansible_userspace_bits}}/sonar.sh"
77 | dest="/etc/init.d/sonar"
78 | state=link
79 | mode=0755
80 | owner="root"
81 | group="root"
82 | tags: sonar_setup
83 |
84 | - name: Ensure Sonar is running and set to start on boot.
85 | service: name=sonar state=started enabled=yes
86 | tags: sonar_setup
87 |
--------------------------------------------------------------------------------
/templates/settings.xml.j2:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | sonar
5 |
6 | true
7 |
8 |
9 |
10 | {% if sonar_jdbc_driver == "postgresql" %}
11 | jdbc:postgresql://{{sonar_jdbc_host}}:{{sonar_jdbc_port}}/{{sonar_jdbc_db}}
12 | {% elif sonar_jdbc_driver == "h2" %}
13 | jdbc:h2:tcp://{{sonar_jdbc_host}}:{{sonar_jdbc_port}}/{{sonar_jdbc_db}}
14 | {% elif sonar_jdbc_driver == "mysql" %}
15 | jdbc:mysql://{{sonar_jdbc_host}}:{{sonar_jdbc_port}}/{sonar_jdbc_db}}??useUnicode=true&characterEncoding=utf8
16 | {% else %}
17 |
18 | {% endif %}
19 |
20 | {{sonar_jdbc_user}}
21 | {{sonar_jdbc_pass}}
22 |
23 |
24 | http://{{sonar_analyzer_runner_host_connect}}:{{sonar_port}}
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/templates/sonar-runner.properties.j2:
--------------------------------------------------------------------------------
1 | #Configure here general information about the environment, such as SonarQube DB details for example
2 | #No information about specific project should appear here
3 |
4 | #----- Default SonarQube server
5 | sonar.host.url=http://{{sonar_analyzer_runner_host_connect}}:{{sonar_port}}
6 |
7 | #----- PostgreSQL
8 | #sonar.jdbc.url=jdbc:postgresql://localhost/sonar
9 |
10 | #----- MySQL
11 | #sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
12 |
13 | #----- Oracle
14 | #sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE
15 |
16 | #----- Microsoft SQLServer
17 | #sonar.jdbc.url=jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor
18 |
19 |
20 | #----- Global database settings
21 | ## postgres, h2 or mysql
22 | {% if sonar_jdbc_driver == "postgresql" %}
23 | sonar.jdbc.url=jdbc:postgresql://{{sonar_jdbc_host}}:{{sonar_jdbc_port}}/{{sonar_jdbc_db}}
24 | {% elif sonar_jdbc_driver == "h2" %}
25 | sonar.jdbc.url=jdbc:h2:tcp://{{sonar_jdbc_host}}:{{sonar_jdbc_port}}/{{sonar_jdbc_db}}
26 | {% elif sonar_jdbc_driver == "mysql" %}
27 | sonar.jdbc.url=jdbc:mysql://{{sonar_jdbc_host}}:{{sonar_jdbc_port}}/{{sonar_jdbc_db}}?useUnicode=true&characterEncoding=utf8
28 | {% else %}
29 | ## NO DATABASE supported for {{sonar_jdbc_driver}} in ansible
30 | {% endif %}
31 |
32 | sonar.jdbc.username={{sonar_jdbc_user}}
33 | sonar.jdbc.password={{sonar_jdbc_pass}}
34 |
35 | #----- Default source code encoding
36 | #sonar.sourceEncoding=UTF-8
37 |
38 | #----- Security (when 'sonar.forceAuthentication' is set to 'true')
39 | #sonar.login=admin
40 | #sonar.password=admin
41 |
42 |
--------------------------------------------------------------------------------
/templates/sonar.conf.j2:
--------------------------------------------------------------------------------
1 | # {{ ansible_managed }}
2 | #--------------------------------------------------------
3 | # This file must contain only ISO 8859-1 characters
4 | # see http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Properties.html#load(java.io.InputStream)
5 | #
6 | # To use an environment variable, use the following syntax : ${env:NAME_OF_ENV_VARIABLE}
7 | # For example :
8 | # sonar.jdbc.url: ${env:SONAR_JDBC_URL}
9 | #
10 | #
11 | # See also the file conf/wrapper.conf for JVM advanced settings
12 | #---------------------------------------------------------
13 |
14 |
15 | #---------------------------------------------------------
16 | # WEB SETTINGS - STANDALONE MODE ONLY
17 | # These settings are ignored when the war file is deployed to a JEE server.
18 | #---------------------------------------------------------
19 | # Listen host/port and context path (for example / or /sonar). Default values are 0.0.0.0:9000/.
20 | sonar.web.host: {{sonar_listen_ip}}
21 | sonar.web.port: {{sonar_port}}
22 | #sonar.web.context: /
23 |
24 | # Log HTTP requests. Deactivated by default.
25 | #sonar.web.jettyRequestLogs: ../../logs/jetty-yyyy_mm_dd.request.log
26 | #sonar.web.jetty.threads.min: 5
27 | #sonar.web.jetty.threads.max: 50
28 |
29 | #-----------------------------------------------------------------------
30 | # DATABASE
31 | #
32 | # IMPORTANT : the embedded database H2 is used by default.
33 | # It is recommended for tests only. Please use an external database
34 | # for production environment (MySQL, Oracle, Postgresql, SQLServer)
35 | #
36 | #-----------------------------------------------------------------------
37 |
38 | #----- Credentials
39 | # Permissions to create tables and indexes must be granted to JDBC user.
40 | # The schema must be created first.
41 | sonar.jdbc.username: {{sonar_jdbc_user}}
42 | sonar.jdbc.password: {{sonar_jdbc_pass}}
43 |
44 | #----- Embedded database H2
45 | # Note : it does not accept connections from remote hosts, so the
46 | # SonarQube server and the maven plugin must be executed on the same host.
47 |
48 | # Comment the following line to deactivate the default embedded database.
49 | {% if sonar_jdbc_driver == "h2" %}
50 | sonar.jdbc.url: jdbc:h2:tcp://{{sonar_jdbc_host}}:{{sonar_jdbc_port}}/{{sonar_jdbc_db}}
51 | {% else %}
52 | #sonar.jdbc.url: jdbc:h2:tcp://localhost:9092/sonar
53 | {% endif %}
54 | # directory containing H2 database files. By default it's the /data directory in the SonarQube installation.
55 | #sonar.embeddedDatabase.dataDir:
56 | # H2 embedded database server listening port, defaults to 9092
57 | #sonar.embeddedDatabase.port: 9092
58 |
59 |
60 | #----- MySQL 5.x
61 | # Comment the embedded database and uncomment the following line to use MySQL
62 |
63 | {% if sonar_jdbc_driver == "mysql" %}
64 | sonar.jdbc.url: jdbc:mysql://{{sonar_jdbc_host}}:{{sonar_jdbc_port}}/{{sonar_jdbc_db}}?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true
65 | {% else %}
66 | #sonar.jdbc.url: jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true
67 | {% endif %}
68 |
69 |
70 |
71 |
72 | #----- Oracle 10g/11g
73 | # To connect to Oracle database :
74 | #
75 | # - It's recommended to use the latest version of the JDBC driver (ojdbc6.jar).
76 | # Download it in http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html
77 | # - Copy the driver to the directory extensions/jdbc-driver/oracle/
78 | # - Comment the embedded database and uncomment the following line :
79 | #sonar.jdbc.url: jdbc:oracle:thin:@localhost/XE
80 |
81 |
82 | # Uncomment the following property if the Oracle account has permissions to access multiple schemas,
83 | # for example sonar schemas with different versions. In that case, use the same property during project analysis
84 | # (-Dsonar.jdbc.schema=)
85 | # The schema is case-sensitive.
86 | #sonar.jdbc.schema: sonar
87 |
88 |
89 | #----- PostgreSQL 8.x/9.x
90 | # Comment the embedded database and uncomment the following property to use PostgreSQL
91 | {% if sonar_jdbc_driver == "postgresql" %}
92 | sonar.jdbc.url: jdbc:postgresql://{{sonar_jdbc_host}}:{{sonar_jdbc_port}}/{{sonar_jdbc_db}}
93 | {% else %}
94 | #sonar.jdbc.url: jdbc:postgresql://localhost/sonar
95 | {% endif %}
96 |
97 | # Uncomment the following property if the PostgreSQL account has permissions to access multiple schemas,
98 | # for example sonar schemas with different versions. In that case, use the same property during project analysis
99 | # (-Dsonar.jdbc.schema=)
100 | {% if sonar_jdbc_driver == "postgresql" and sonar_psq_schema is defined %}
101 | sonar.jdbc.schema: {{sonar_psq_schema}}
102 | {% else %}
103 | #sonar.jdbc.schema: public
104 | {% endif %}
105 |
106 | #----- Microsoft SQLServer
107 | # The Jtds open source driver is available in extensions/jdbc-driver/mssql. More details on http://jtds.sourceforge.net
108 | #sonar.jdbc.url: jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor
109 |
110 |
111 | #----- Connection pool settings
112 | sonar.jdbc.maxActive: {{sonar_jdbc_maxActive}}
113 | sonar.jdbc.maxIdle: {{sonar_jdbc_maxIdle}}
114 | sonar.jdbc.minIdle: {{sonar_jdbc_minIdle}}
115 | sonar.jdbc.maxWait: {{sonar_jdbc_maxWait}}
116 | sonar.jdbc.minEvictableIdleTimeMillis: {{sonar_jdbc_minEvictableIdleTimeMillis}}
117 | sonar.jdbc.timeBetweenEvictionRunsMillis: {{sonar_jdbc_timeBetweenEvictionRunsMillis}}
118 |
119 |
120 | #---------------------------------------------------------
121 | # UPDATE CENTER
122 | #---------------------------------------------------------
123 |
124 | # The Update Center requires an internet connection to request http://update.sonarsource.org
125 | # It is activated by default:
126 | #sonar.updatecenter.activate=true
127 |
128 | # HTTP proxy (default none)
129 | #http.proxyHost=
130 | #http.proxyPort=
131 |
132 | # NT domain name if NTLM proxy is used
133 | #http.auth.ntlm.domain=
134 |
135 | # SOCKS proxy (default none)
136 | #socksProxyHost=
137 | #socksProxyPort=
138 |
139 | # proxy authentication. The 2 following properties are used for HTTP and SOCKS proxies.
140 | #http.proxyUser=
141 | #http.proxyPassword=
142 |
143 | #---------------------------------------------------------
144 | # NOTIFICATIONS
145 | #---------------------------------------------------------
146 |
147 | # Delay (in seconds) between processing of notification queue
148 | sonar.notifications.delay=60
149 |
--------------------------------------------------------------------------------
/vars/main.yml:
--------------------------------------------------------------------------------
1 | ---
2 | # You can override default vars defined in defaults/main.yml here
3 | # But i would advice to use host or group vars instead
--------------------------------------------------------------------------------