├── hosts
├── roles
├── redmine
│ ├── templates
│ │ ├── database.yml
│ │ └── configuration.yml
│ └── tasks
│ │ └── main.yml
├── apache
│ ├── templates
│ │ └── redmine.conf
│ └── tasks
│ │ └── main.yml
├── pg
│ ├── files
│ │ └── pg_hba_conf.patch
│ └── tasks
│ │ └── main.yml
├── ruby
│ └── tasks
│ │ └── main.yml
└── system
│ └── tasks
│ └── main.yml
├── site.yml
├── group_vars
└── redmine-servers
├── LICENSE.md
├── .circleci
└── config.yml
└── README.md
/hosts:
--------------------------------------------------------------------------------
1 | [redmine-servers]
2 | localhost ansible_connection=local
3 |
--------------------------------------------------------------------------------
/roles/redmine/templates/database.yml:
--------------------------------------------------------------------------------
1 | production:
2 | adapter: postgresql
3 | database: redmine
4 | host: localhost
5 | username: redmine
6 | password: "{{ db_passwd_redmine }}"
7 | encoding: utf8
8 | pool: 5
9 |
--------------------------------------------------------------------------------
/roles/redmine/templates/configuration.yml:
--------------------------------------------------------------------------------
1 | production:
2 | email_delivery:
3 | delivery_method: :smtp
4 | smtp_settings:
5 | address: "localhost"
6 | port: 25
7 | domain: "{{ ansible_fqdn }}"
8 |
9 | rmagick_font_path: {{ redmine_font_path }}
10 |
--------------------------------------------------------------------------------
/site.yml:
--------------------------------------------------------------------------------
1 | - hosts: redmine-servers
2 |
3 | roles:
4 | - system
5 | - pg
6 | - ruby
7 | - redmine
8 | - apache
9 |
10 | post_tasks:
11 | - name: 完了
12 | debug:
13 | msg='インストールが完了しました。 http://{{ ansible_default_ipv4.address }}/redmine/ にアクセスしてください。'
14 |
--------------------------------------------------------------------------------
/roles/apache/templates/redmine.conf:
--------------------------------------------------------------------------------
1 |
2 | Require all granted
3 |
4 |
5 | Alias /redmine /var/lib/redmine/public
6 |
7 | PassengerBaseURI /redmine
8 | PassengerAppRoot /var/lib/redmine
9 |
10 |
11 | {{ passenger_snippet_vars.stdout }}
12 |
13 | PassengerMaxPoolSize 20
14 | PassengerMaxInstancesPerApp 4
15 | PassengerPoolIdleTime 864000
16 | PassengerStatThrottleRate 10
17 |
18 | Header always unset "X-Powered-By"
19 | Header always unset "X-Runtime"
20 |
--------------------------------------------------------------------------------
/roles/pg/files/pg_hba_conf.patch:
--------------------------------------------------------------------------------
1 | --- pg_hba.conf.org 2015-12-06 15:49:05.282188570 +0900
2 | +++ pg_hba.conf 2015-12-06 15:33:01.377197287 +0900
3 | @@ -71,6 +71,8 @@
4 | # "host" records. In that case you will also need to make PostgreSQL
5 | # listen on a non-local interface via the listen_addresses
6 | # configuration parameter, or via the -i or -h command line switches.
7 | +host redmine redmine 127.0.0.1/32 md5
8 | +host redmine redmine ::1/128 md5
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/group_vars/redmine-servers:
--------------------------------------------------------------------------------
1 | # ----------------------------------------------------------------------
2 | # データベースの redmine ユーザーのパスワード (変更推奨)
3 | db_passwd_redmine: Must_be_changed!
4 | # ----------------------------------------------------------------------
5 |
6 | # Redmineのチェックアウト元URL
7 | redmine_svn_url: http://svn.redmine.org/redmine/branches/4.0-stable
8 |
9 | # Redmineのデプロイ先ディレクトリ
10 | redmine_dir: /var/lib/redmine
11 |
12 | # Redmineのデプロイ先ディレクトリのオーナー:グループ
13 | redmine_dir_owner: apache
14 | redmine_dir_group: apache
15 |
16 | # Redmineで使用する日本語フォントファイル
17 | redmine_font_path: /usr/share/fonts/google-noto-cjk/NotoSansCJKjp-Regular.otf
18 |
19 | # Redmineで使用するlocale
20 | redmine_locale: ja_JP.UTF-8
21 |
22 | # pg_hba.confのパス
23 | pg_hba_conf_path: /var/lib/pgsql/data/pg_hba.conf
24 |
25 | # ダウンロードするRubyのソースコード
26 | ruby_url_dir: https://cache.ruby-lang.org/pub/ruby/2.6
27 | ruby_archive_version: ruby-2.6.5
28 | ruby_archive_ext: tar.bz2
29 | ruby_archive_name: "{{ ruby_archive_version }}.{{ ruby_archive_ext }}"
30 |
31 | ruby_file_name: /usr/local/bin/ruby
32 | work_dir: /tmp/redmine-setup
33 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 [Far End Technologies Corporation](http://www.farend.co.jp/)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/roles/apache/tasks/main.yml:
--------------------------------------------------------------------------------
1 | - name: Redmineディレクトリ以下のオーナーを変更
2 | become: yes
3 | file:
4 | path: "{{ redmine_dir }}"
5 | owner: "{{ redmine_dir_owner }}"
6 | group: "{{ redmine_dir_group }}"
7 | recurse: yes
8 |
9 | - name: Passengerがインストールされているか確認
10 | command:
11 | test -f /usr/local/bin/passenger-install-apache2-module
12 | register:
13 | result
14 | failed_when: result.rc not in [0, 1]
15 | changed_when: false
16 |
17 | - name: Passengerをインストール
18 | become: yes
19 | gem:
20 | name=passenger
21 | user_install=no
22 | environment:
23 | PATH: "/usr/local/bin:{{ ansible_env.PATH }}"
24 | when: result.rc == 1
25 |
26 | - name: PassengerのApache用モジュールのインストール
27 | become: yes
28 | command:
29 | passenger-install-apache2-module --auto
30 | environment:
31 | PATH: "/usr/local/bin:{{ ansible_env.PATH }}"
32 | when: result.rc == 1
33 |
34 | - name: PassengerのApache用モジュールの設定を取得
35 | command:
36 | passenger-install-apache2-module --snippet
37 | environment:
38 | PATH: "/usr/local/bin:{{ ansible_env.PATH }}"
39 | register:
40 | passenger_snippet_vars
41 | changed_when: false
42 |
43 | - name: redmine.confの作成
44 | become: yes
45 | template:
46 | src=redmine.conf
47 | dest=/etc/httpd/conf.d/redmine.conf
48 |
49 | - name: httpdの再起動
50 | become: yes
51 | service:
52 | name=httpd
53 | state=restarted
54 | enabled=yes
55 |
--------------------------------------------------------------------------------
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 |
3 | jobs:
4 | build:
5 | machine: true
6 | steps:
7 | - checkout
8 | - run:
9 | name: Setup Centos container
10 | # Use machine executer to execute run command with privileged option
11 | command: |
12 | docker pull centos:8
13 | docker run --privileged -d --name centos -v /home/circleci/project:/redmine_centos_ansible centos:8 /sbin/init
14 | - run:
15 | name: Install packages
16 | command: |
17 | docker exec -it centos systemctl disable dnf-makecache.timer # To prevent installation failure
18 | docker exec -it centos yum update -y
19 | docker exec -it centos yum install -y epel-release glibc-locale-source
20 | docker exec -it centos yum install -y ansible git
21 | docker exec -it centos yum install -y policycoreutils selinux-policy-targeted firewalld sudo
22 | - run:
23 | name: Execute ansible playbook
24 | # Test without -K option to make it non-interactive.
25 | command: docker exec -it centos ansible-playbook -i /redmine_centos_ansible/hosts /redmine_centos_ansible/site.yml
26 |
27 | workflows:
28 | version: 2
29 | commit:
30 | jobs:
31 | - build
32 | nightly:
33 | triggers:
34 | - schedule:
35 | cron: "00 1 * * 1" # Every Monday at 1:00(UTC)
36 | filters:
37 | branches:
38 | only:
39 | - master
40 | jobs:
41 | - build
42 |
--------------------------------------------------------------------------------
/roles/ruby/tasks/main.yml:
--------------------------------------------------------------------------------
1 | - name: Rubyがインストールされているか確認
2 | command:
3 | test -f {{ ruby_file_name }}
4 | register:
5 | ruby_test_vars
6 | failed_when: ruby_test_vars.rc not in [0, 1]
7 | changed_when: false
8 |
9 | - name: Rubyがダウンロード済みか確認
10 | command:
11 | test -f {{ work_dir }}/{{ ruby_archive_version }}
12 | register:
13 | ruby_src_test_vars
14 | failed_when: ruby_test_vars.rc not in [0, 1]
15 | changed_when: false
16 |
17 | - name: Rubyのソースコードのダウンロード
18 | get_url:
19 | url={{ ruby_url_dir }}/{{ ruby_archive_name }}
20 | dest={{ work_dir }}
21 | when: ruby_test_vars.rc == 1 and ruby_src_test_vars.rc == 1
22 |
23 | - name: Rubyのソースコードを展開
24 | unarchive:
25 | src={{ work_dir }}/{{ ruby_archive_name }}
26 | dest={{ work_dir }}
27 | copy=no
28 | when: ruby_test_vars.rc == 1 and ruby_src_test_vars.rc == 1
29 |
30 | - name: Rubyのビルド1 (configure)
31 | command:
32 | ./configure --disable-install-doc
33 | chdir={{ work_dir }}/{{ ruby_archive_version }}
34 | when: ruby_test_vars.rc == 1
35 |
36 | - name: Rubyのビルド2 (make)
37 | command:
38 | make
39 | chdir={{ work_dir }}/{{ ruby_archive_version }}
40 | when: ruby_test_vars.rc == 1
41 |
42 | - name: Rubyのインストール
43 | become: yes
44 | command:
45 | make install
46 | chdir={{ work_dir }}/{{ ruby_archive_version }}
47 | when: ruby_test_vars.rc == 1
48 |
49 | - name: bundlerのインストール
50 | become: yes
51 | gem:
52 | name=bundler
53 | version=1.17.3
54 | user_install=no
55 | environment:
56 | PATH: "/usr/local/bin:{{ ansible_env.PATH }}"
57 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # redmine-centos-ansible
2 |
3 | | :warning: CentOS 8の提供が2021年で終了されることが決まりました。このansible-playbookはこれ以降のRedmineのバージョンアップに対応するための更新を行いません。 |
4 | | --- |
5 |
6 | 最小構成でインストールしたCentOSにRedmineを自動インストールするためのAnsibleプレイブックです。
7 |
8 | コマンド5個実行するだけで、あとはしばらく放置すればインストールが完了します。
9 |
10 |
11 | ## 概要
12 |
13 | Ansibleを使ってRedmineを自動インストールするためのプレイブックです。以下のwebサイトで紹介されている手順におおむね準拠しています。
14 |
15 | [Redmine 3.4をCentOS 7.3にインストールする手順](http://blog.redmine.jp/articles/3_4/install/centos/)
16 |
17 |
18 | ## システム構成
19 |
20 | * Redmine 4.0
21 | * CentOS 8.0
22 | * PostgreSQL
23 | * Apache
24 |
25 |
26 | ## Redmineのインストール手順
27 |
28 | インストール直後の CentOS 8.0 に root でログインし以下の操作を行ってください。
29 |
30 |
31 | ### Ansibleとgitのインストール
32 |
33 | ```
34 | yum update -y
35 | yum install -y epel-release glibc-locale-source
36 | yum install -y ansible git
37 |
38 | ===================== Dockerの場合は以下も実行する===================
39 | yum install -y policycoreutils selinux-policy-targeted firewalld sudo
40 | =====================================================================
41 | ```
42 |
43 | ### playbookのダウンロード
44 |
45 | ```
46 | git clone https://github.com/farend/redmine-centos-ansible.git
47 | ```
48 |
49 | ### PostgreSQLに設定するパスワードの変更
50 |
51 | ダウンロードしたプレイブック内のファイル `group_vars/redmine-servers` をエディタで開き、 `db_passwd_redmine` を適当な内容に変更してください。これはPostgreSQLのRedmine用ユーザー redmine に設定されるパスワードです。
52 |
53 | ### playbook実行
54 |
55 | 下記コマンドを実行してください。Redmineの自動インストールが開始されます。
56 |
57 | ```
58 | cd redmine-centos-ansible
59 | ansible-playbook -i hosts site.yml
60 | ```
61 |
62 | 10〜20分ほどでインストールが完了します。webブラウザで `http://サーバIPアドレス/redmine` にアクセスしてください。Redmineの画面が表示されるはずです。
63 |
64 |
65 | ## ライセンス
66 |
67 | MIT License
68 |
69 |
70 | ## 作者
71 |
72 | [ファーエンドテクノロジー株式会社](http://www.farend.co.jp/)
73 |
--------------------------------------------------------------------------------
/roles/pg/tasks/main.yml:
--------------------------------------------------------------------------------
1 | - name: PostgreSQL initdb
2 | become: yes
3 | shell:
4 | PGSETUP_INITDB_OPTIONS="--encoding=UTF-8 --no-locale" postgresql-setup --initdb
5 | register:
6 | result
7 | failed_when: result.rc not in [0, 1]
8 | changed_when: result.rc == 0
9 |
10 | - name: pg_hba.confにredmine用設定が存在するか確認
11 | become: yes
12 | command:
13 | grep redmine {{ pg_hba_conf_path }}
14 | register:
15 | result_pg_hba
16 | failed_when: result_pg_hba.rc not in [0, 1]
17 | changed_when: false
18 |
19 | - name: pg_hba.conf設定変更用パッチを配置
20 | become: yes
21 | copy:
22 | src=pg_hba_conf.patch
23 | dest={{ work_dir }}
24 | when:
25 | result_pg_hba.rc == 1
26 |
27 | - name: pg_hba.confにredmine用設定を追加
28 | become: yes
29 | shell:
30 | patch -tNp0 {{ pg_hba_conf_path }} < {{ work_dir }}/pg_hba_conf.patch
31 | when:
32 | result_pg_hba.rc == 1
33 |
34 | - name: create locale ja_JP.UTF-8
35 | become: yes
36 | shell: localedef -i ja_JP -c -f UTF-8 -A /usr/share/locale/locale.alias {{ redmine_locale }}
37 |
38 | - name: set locale to ja_JP.UTF-8
39 | become: yes
40 | shell: localectl set-locale LANG={{ redmine_locale }}
41 |
42 | - name: PostgreSQL起動
43 | become: yes
44 | service:
45 | name=postgresql
46 | state=restarted
47 | enabled=yes
48 |
49 | - name: PostgreSQL ユーザー作成
50 | become: yes
51 | become_user: postgres
52 | become_method: sudo
53 | postgresql_user:
54 | name=redmine
55 | password={{ db_passwd_redmine }}
56 |
57 | - name: PostgreSQL データベース作成
58 | become: yes
59 | become_user: postgres
60 | become_method: sudo
61 | postgresql_db:
62 | name=redmine
63 | encoding='UTF-8'
64 | lc_collate= {{ redmine_locale }}
65 | lc_ctype= {{ redmine_locale }}
66 | template='template0'
67 |
--------------------------------------------------------------------------------
/roles/system/tasks/main.yml:
--------------------------------------------------------------------------------
1 | - name: SELinuxの状態確認
2 | command:
3 | /usr/sbin/selinuxenabled
4 | register:
5 | result
6 | changed_when: false
7 | failed_when: result.rc not in [0, 1]
8 |
9 | - name: 起動時にSELinux無効化 (/etc/sysconfig/selinux)
10 | become: yes
11 | selinux: state=disabled
12 | when: result.rc == 0
13 |
14 | - name: SELinux無効化 (setenforce)
15 | become: yes
16 | command: setenforce 0
17 | when: result.rc == 0
18 |
19 | - name: firewalldが起動しているか確認
20 | become: yes
21 | shell: firewall-cmd --state
22 | register: firewall_state
23 | ignore_errors: yes
24 | changed_when: false
25 | check_mode: no
26 |
27 | - name: firewalldでHTTPを許可
28 | become: yes
29 | firewalld:
30 | zone=public
31 | service=http
32 | permanent=yes
33 | state=enabled
34 | immediate=yes
35 | when: firewall_state.rc == 0
36 |
37 | - name: 開発ツールのインストール
38 | become: yes
39 | yum: name='@Development Tools'
40 |
41 | - name: RubyとPassengerのビルドに必要な開発ツールやヘッダファイルのインストール
42 | become: yes
43 | yum:
44 | name='openssl-devel,readline-devel,zlib-devel,curl-devel,libyaml,libffi-devel'
45 |
46 | - name: PostgreSQLとヘッダファイルのインストール
47 | become: yes
48 | yum:
49 | name='postgresql-server,postgresql-devel,python3-psycopg2'
50 |
51 | - name: Apacheとヘッダファイルのインストール
52 | become: yes
53 | yum:
54 | name='httpd,httpd-devel'
55 |
56 | - name: powertoolのインストール
57 | shell: dnf config-manager --set-enabled powertools warn=no
58 |
59 | - name: ImageMagickとヘッダファイル・日本語フォントのインストール
60 | become: yes
61 | yum:
62 | name='ImageMagick,ImageMagick-devel,google-noto-sans-cjk-jp-fonts'
63 |
64 | - name: そのほかのツールのインストール
65 | become: yes
66 | yum:
67 | name='subversion,git,which'
68 |
69 | - name: 作業ディレクトリ作成
70 | file: path={{ work_dir }}
71 | state=directory
72 | mode=0755
73 |
--------------------------------------------------------------------------------
/roles/redmine/tasks/main.yml:
--------------------------------------------------------------------------------
1 | - name: Redmineのソースコードをチェックアウト
2 | become: yes
3 | subversion:
4 | repo={{ redmine_svn_url }}
5 | dest={{ redmine_dir }}
6 |
7 | - name: database.ymlの作成
8 | become: yes
9 | template:
10 | src=database.yml
11 | dest={{ redmine_dir }}/config/database.yml
12 | force=no
13 | register:
14 | result_database_yml
15 |
16 | - name: configuration.ymlの作成
17 | become: yes
18 | template:
19 | src=configuration.yml
20 | dest={{ redmine_dir }}/config/configuration.yml
21 | force=no
22 |
23 | - name: Gemfile.lockが存在するか確認
24 | command:
25 | test -f {{ redmine_dir }}/Gemfile.lock
26 | register:
27 | result_test_gemfile
28 | failed_when: result_test_gemfile.rc not in [0, 1]
29 | changed_when: false
30 |
31 | - name: gemsパッケージのインストール
32 | become: yes
33 | command:
34 | bundle install --path vendor/bundle
35 | chdir={{ redmine_dir }}
36 | environment:
37 | PATH: "/usr/local/bin:{{ ansible_env.PATH }}"
38 | when:
39 | result_test_gemfile.rc == 1
40 |
41 | - name: gemsパッケージのアップデート
42 | become: yes
43 | command:
44 | bundle update
45 | chdir={{ redmine_dir }}
46 | environment:
47 | PATH: "/usr/local/bin:{{ ansible_env.PATH }}"
48 | when:
49 | result_test_gemfile.rc == 0
50 |
51 | - name: secret tokenの作成
52 | become: yes
53 | command:
54 | bundle exec rake generate_secret_token
55 | chdir={{ redmine_dir }}
56 | environment:
57 | PATH: "/usr/local/bin:{{ ansible_env.PATH }}"
58 | RAILS_ENV: production
59 |
60 | - name: データベースのマイグレーション
61 | become: yes
62 | command:
63 | bundle exec rake db:migrate
64 | chdir={{ redmine_dir }}
65 | environment:
66 | PATH: "/usr/local/bin:{{ ansible_env.PATH }}"
67 | RAILS_ENV: production
68 |
69 | - name: デフォルトデータ(日本語)をロード
70 | become: yes
71 | command:
72 | bundle exec rake redmine:load_default_data
73 | chdir={{ redmine_dir }}
74 | environment:
75 | PATH: "/usr/local/bin:{{ ansible_env.PATH }}"
76 | RAILS_ENV: production
77 | REDMINE_LANG: ja
78 | when:
79 | result_database_yml is changed
80 |
81 | - name: farend_basicテーマのダウンロード
82 | become: yes
83 | git:
84 | repo=https://github.com/farend/redmine_theme_farend_basic.git
85 | dest={{ redmine_dir }}/public/themes/farend_basic
86 |
87 | - name: テーマをfarend_basicに切り替え
88 | become: yes
89 | command:
90 | bundle exec rails r 'Setting["ui_theme"]="farend_basic"'
91 | chdir={{ redmine_dir }}
92 | environment:
93 | PATH: "/usr/local/bin:{{ ansible_env.PATH }}"
94 | RAILS_ENV: production
95 | when:
96 | result_database_yml is changed
97 |
98 | - name: デフォルトの言語を日本語に変更
99 | become: yes
100 | command:
101 | bundle exec rails r 'Setting["default_language"]="ja"'
102 | chdir={{ redmine_dir }}
103 | environment:
104 | PATH: "/usr/local/bin:{{ ansible_env.PATH }}"
105 | RAILS_ENV: production
106 | when:
107 | result_database_yml is changed
108 |
109 | - name: ユーザー名の表示形式を「姓 名」に変更
110 | become: yes
111 | command:
112 | bundle exec rails r 'Setting["user_format"]=:lastname_firstname'
113 | chdir={{ redmine_dir }}
114 | environment:
115 | PATH: "/usr/local/bin:{{ ansible_env.PATH }}"
116 | RAILS_ENV: production
117 | when:
118 | result_database_yml is changed
119 |
120 | - name: 添付ファイルとリポジトリのエンコーディングを設定
121 | become: yes
122 | command:
123 | bundle exec rails r 'Setting["repositories_encodings"]="UTF-8,CP932,EUC-JP"'
124 | chdir={{ redmine_dir }}
125 | environment:
126 | PATH: "/usr/local/bin:{{ ansible_env.PATH }}"
127 | RAILS_ENV: production
128 | when:
129 | result_database_yml is changed
130 |
131 | - name: 添付ファイルのサムネイルを表示
132 | become: yes
133 | command:
134 | bundle exec rails r 'Setting["thumbnails_enabled"]="1"'
135 | chdir={{ redmine_dir }}
136 | environment:
137 | PATH: "/usr/local/bin:{{ ansible_env.PATH }}"
138 | RAILS_ENV: production
139 | when:
140 | result_database_yml is changed
141 |
--------------------------------------------------------------------------------