lean_delivery.sonarqube
SonarQube 役割
この役割は、拡張されたプラグインセットを持つSonarQubeをインストールします。以下のプレイブック例では、openJDK、PostgreSQLデータベース、およびhttpsが有効なnginxウェブサーバーも使用しています。
この記事を参照してください: https://lean-delivery.com/2020/02/how-to-add-sonarqube-to-ci-process.html
デフォルトのプラグインに加えて、SonarQube役割は次の推奨プラグインもインストールできます:
- checkstyle-sonar-plugin
- sonar-pmd-plugin
- sonar-findbugs-plugin
- mutation-analysis-plugin
- sonar-jdepend-plugin
- sonar-jproperties-plugin
- sonar-groovy-plugin
- sonar-dependency-check-plugin
- sonar-json-plugin
- sonar-yaml-plugin
- sonar-ansible-plugin
- sonar-shellcheck-plugin
また、オプションのプラグインもインストールできます。注意してください、いくつかは最新のSonarQubeバージョンでサポートされていない場合があります:
- qualinsight-sonarqube-smell-plugin
- qualinsight-sonarqube-badges
- sonar-auth-github-plugin
- sonar-auth-bitbucket-plugin
- sonar-bitbucket-plugin (Bitbucket Cloud用)
- sonar-stash-plugin (Bitbucket Server用)
- sonar-auth-gitlab-plugin
- sonar-gitlab-plugin
- sonar-xanitizer-plugin
- sonar-build-breaker-plugin
- sonar-issueresolver-plugin
- sonarqube-community-branch-plugin
- sonar-aemrules-plugin
プラグインのマトリックスはここにあります: https://docs.sonarsource.com/sonarqube/latest/instance-administration/plugin-version-matrix/
この役割は、いくつかの設定オプションも提供します:
- SonarQubeを新しいバージョンに更新するときにデータベースを移行する機能
- Jenkins webhookを設定する機能
- カスタムプロファイルを復元する機能
- LDAP設定
- 管理者ユーザーのパスワードを変更する機能
Jenkinsパイプラインの例はここにあります: https://raw.githubusercontent.com/lean-delivery/ansible-role-sonarqube/master/files/example_pipeline.groovy
要件
- サポートされるAnsibleバージョン:
- 5 (2.12) - テストにはまだ含まれていませんが、動作するはずです
- 6 (2.13)
- 7 (2.14)
- サポートされるSonarQubeバージョン:
- 7.9.6 (前のLTS)
- 8.9.10 (前のLTS)
- 9.9.6 LTS
- 10.0 - 10.6
- サポートされるJavaバージョン:
- 11
- 17(SonarQube 9.9以上に使用)
- サポートされるデータベース:
- PostgreSQL
- MySQL(推奨されません)
- 埋め込みH2(テスト用のみ)
- サポートされるウェブサーバー(httpsのリバースプロキシ):
- nginx
- サポートされるOS:
- CentOS、RHEL
- 7
- Ubuntu
- 18.04
- 20.04 - テストにはまだ含まれていませんが、動作するはずです
- 22.04 - テストにはまだ含まれていませんが、動作するはずです
- CentOS、RHEL
Java、データベース、自己署名証明書付きのウェブサーバーは前もってインストールする必要があります。次のGalaxyの役割を使用してください:
- lean_delivery.java
- geerlingguy.postgresql
- jdauphant.ssl-certs
- nginxinc.nginx
役割変数
sonar_version
- SonarQubeバージョンsonar_path
- インストールディレクトリ
デフォルト: /opt/sonarqubesonar_user
- SonarQubeをインストールするユーザー
デフォルト: sonarsonar_group
- SonarQubeユーザーのグループ
デフォルト: sonarsonar_nofile
- SonarQubeを実行するユーザーが開けるファイルディスクリプタの数
デフォルト: 65536sonar_nproc
- SonarQubeを実行するユーザーが開けるスレッドの数
デフォルト: 4096sonar_max_map_count
- Elasticsearchに必要なmmapカウントの制限
デフォルト: 262144sonar_log_level
- SonarQubeサーバーのログレベル
デフォルト: INFOsonar_java_opts
:web
- SonarQubeのウェブ部分の追加Javaオプション
デフォルト: -Xmx512m -Xms128mes
- Elasticsearchの追加Javaオプション
デフォルト: -Xms512m -Xmx512mce
- コンピュートエンジンの追加Javaオプション
デフォルト: -Xmx512m -Xms128m
web
:host
- SonarQubeのバインドIPアドレス
デフォルト: 0.0.0.0port
- HTTP接続のためのTCPポート
デフォルト: 9000path
- ウェブコンテキスト
デフォルト: /
sonar_db
- データベース設定type
デフォルト : postgresqlport
デフォルト : 5432host
デフォルト : localhostname
デフォルト: sonaruser
デフォルト: sonarpassword
デフォルト: sonaroptions
デフォルト:
sonar_store
- SonarQubeアーティファクトプロバイダー
デフォルト: https://sonarsource.bintray.com/Distribution/sonarqubesonar_check_url
- SonarQubeの起動確認用URL
デフォルト: http://{{ web.host }}:{{ web.port }}sonar_download
- sonarqube.zipのダウンロードが必要かどうか。ダウンロードできない場合はfalseに設定し、プレイブック実行前に手動でzipをsonar_download_pathに配置します。 デフォルト: truesonar_download_path
- ローカルダウンロードパス
デフォルト: /tmp/sonar_proxy_type
- ウェブサーバー、現在はnginxのみがサポートされています
デフォルト: nginxsonar_proxy_server_name
- ウェブサーバー設定でのサーバー名
デフォルト: '{{ ansible_fqdn }}'sonar_proxy_http
- HTTP接続が許可されるか
デフォルト: falsesonar_proxy_http_port
- HTTPポート
デフォルト: 80sonar_proxy_ssl
- HTTPS接続が許可されるか
デフォルト: truesonar_proxy_ssl_port
- HTTPSポート
デフォルト: 443sonar_proxy_ssl_cert_path
- 証明書のパス
デフォルト: '/etc/ssl/{{ sonar_proxy_server_name }}/{{ sonar_proxy_server_name }}.pem'sonar_proxy_ssl_key_path
- キーのパス
デフォルト: '/etc/ssl/{{ sonar_proxy_server_name }}/{{ sonar_proxy_server_name }}.key'sonar_proxy_client_max_body_size
- ウェブサーバー設定のクライアント最大ボディサイズ
デフォルト: 32msonar_install_recommended_plugins
- 推奨プラグインが必要か
デフォルト: truesonar_recommended_plugins
- 推奨プラグインのリスト\sonar_update_default_plugins
- デフォルトプラグインの更新が必要か
デフォルト: truesonar_default_plugins
- デフォルトプラグインのリスト\sonar_install_optional_plugins
- オプションのプラグインが必要か
デフォルト: falsesonar_optional_plugins
- デフォルトでオフになっているオプションのプラグインのリスト。すべてが最新のSonarQubeバージョンでサポートされているわけではないため、必要なものを選択してこのプロパティをオーバーライドしてください。sonar_excluded_plugins
- SonarQubeインストーラーから除外された古いプラグインのリストsonar_default_excluded_plugins
- 不要なデフォルトプラグインのリスト
デフォルト: []sonar_web_user
- 管理者ユーザーのユーザー名
デフォルト: adminsonar_web_password
- 管理者ユーザーのパスワード
デフォルト: adminchange_password
- パスワードを変更するためにtrueに設定
デフォルト: falsesonar_web_old_password
- 現在のパスワード(変更前)
デフォルト: adminsonar_migrate_db
- データベースの移行が必要か。既存のSonarQubeを新しいバージョンに更新する場合はtrueに設定してください。
デフォルト: falsesonar_set_jenkins_webhook
- Jenkins webhookの設定が必要か
デフォルト: falsesonar_jenkins_webhook_name
- Jenkins webhookの名前
デフォルト: jenkinssonar_jenkins_webhook_url
- Jenkins webhookのURL
デフォルト: https://jenkins.example.com/sonarqube-webhook/sonar_restore_profiles
- プロファイルの復元が必要か
デフォルト: falsesonar_profile_list
- 復元するプロファイルのリストsonar_updatecenter_activate
- SonarQubeアップデートセンターを有効化
デフォルト: true
LDAP設定セクション。 説明については https://docs.sonarqube.org/latest/instance-administration/delegated-auth/#header-6 を参照してください。
ldap
:
デフォルト: 未定義authenticator_downcase
デフォルト: falseurl
デフォルト: ldap://myserver.mycompany.combind_dn
デフォルト: my_bind_dnbind_password
デフォルト: my_bind_passwordauthentication
デフォルト: simplerealm
デフォルト:contextFactoryClass
デフォルト: com.sun.jndi.ldap.LdapCtxFactoryStartTLS
デフォルト: falsefollowReferrals
デフォルト: trueuser_base_dn
デフォルト : ou=Users,dc=mycompany,dc=comuser_request
デフォルト: (&(objectClass=inetOrgPerson)(uid={login}))user_real_name_attribute
デフォルト: cnuser_email_attribute
デフォルト: mailgroup_base_dn
デフォルト: ou=Groups,dc=sonarsource,dc=comgroup_request
デフォルト: (&(objectClass=posixGroup)(memberUid={uid}))group_idAttribute
デフォルト: cn
プレイブックの例
---
- name: SonarQubeをインストール
hosts: sonarqube
become: true
vars:
# java
java_major_version: 17
transport: repositories
# postgresql
postgresql_users:
- name: sonar
password: sonar
postgresql_databases:
- name: sonar
# ssl-certs
ssl_certs_path_owner: nginx
ssl_certs_path_group: nginx
ssl_certs_common_name: sonarqube.example.com
# sonarqube
sonar_version: 10.6.0.92116
sonar_check_url: 'http://{{ ansible_fqdn }}:9000'
sonar_proxy_server_name: sonarqube.example.com
sonar_install_optional_plugins: true
sonar_optional_plugins:
- 'https://github.com/adnovum/sonar-build-breaker/releases/download/{{ build_breaker_epversion }}'
sonar_default_excluded_plugins:
- '{{ sonar_plugins_path }}/sonar-flex-plugin-2.12.0.4568.jar'
sonar_web_password: your_new_secure_password
change_password: true
sonar_web_old_password: admin
sonar_migrate_db: false # SonarQubeを新しいバージョンに更新する場合はtrueに設定
sonar_set_jenkins_webhook: true
sonar_jenkins_webhook_url: https://jenkins.example.com/sonarqube-webhook/
sonar_restore_profiles: true
sonar_profile_list:
- files/example_profile.xml
pre_tasks:
- name: rpmキーをインストール
rpm_key:
state: present
key: https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-{{ ansible_distribution_major_version }}
when: ansible_distribution == 'RedHat'
- name: epelをインストール
package:
name: https://dl.fedoraproject.org/pub/epel/epel-release-latest-{{ ansible_distribution_major_version }}.noarch.rpm
state: present
when: ansible_distribution == 'RedHat'
# プラグインの競合を防ぐために以前にインストールされたsonarを削除
- name: sonarを削除
file:
path: '{{ sonar_path }}'
state: absent
roles:
- role: lean_delivery.java
- role: geerlingguy.postgresql
- role: nginxinc.nginx
- role: jdauphant.ssl-certs
- role: lean_delivery.sonarqube
tasks:
- name: デフォルトのnginx設定を削除
file:
path: /etc/nginx/conf.d/default.conf
state: absent
- name: nginxを再読み込み
command: 'nginx -s reload'
ライセンス
Apache
著者情報
著者:
- Lean Delivery Team team@lean-delivery.com
Lean Delivery SonarQube server install
ansible-galaxy install lean_delivery.sonarqube