From 786245d90712b510fa9cbd0e9d4383339135beeb Mon Sep 17 00:00:00 2001 From: Mark Heiges Date: Wed, 11 Nov 2015 23:14:03 -0500 Subject: [PATCH] many fixes; now run redmine installer via wrapper --- README.md | 10 +++ roles/easyredmine/tasks/database.yml | 44 ++++++++++ roles/easyredmine/tasks/main.yml | 82 ++----------------- roles/easyredmine/tasks/nginx.yml | 35 ++++++++ roles/easyredmine/tasks/redmine.yml | 52 ++++++++++++ .../easyredmine/templates/easyredmine.conf.j2 | 2 +- .../easyredmine/templates/install_wrapper.j2 | 49 +++++++++++ .../templates/installer_inputs.txt.j2 | 11 +++ roles/easyredmine/vars/main.yml | 17 ++-- 9 files changed, 220 insertions(+), 82 deletions(-) create mode 100644 README.md create mode 100644 roles/easyredmine/tasks/nginx.yml create mode 100644 roles/easyredmine/tasks/redmine.yml create mode 100755 roles/easyredmine/templates/install_wrapper.j2 create mode 100644 roles/easyredmine/templates/installer_inputs.txt.j2 diff --git a/README.md b/README.md new file mode 100644 index 0000000..36d2389 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ + + + +Redmine sample data + +To import a copy of an existing Redmine database, place a copy of the MySQL dump file +at `scratch/redmine_dump.sql.gz`. _(One of the daily backups on our production +Redmine server is suitable. See `/var/lib/mysql.backups/daily/redmine/`.)_ + + diff --git a/roles/easyredmine/tasks/database.yml b/roles/easyredmine/tasks/database.yml index a1b3f2a..0535283 100644 --- a/roles/easyredmine/tasks/database.yml +++ b/roles/easyredmine/tasks/database.yml @@ -4,3 +4,47 @@ - mysql-devel - mariadb-server - MySQL-python + + +- service: name='{{ redmine_db_service_provider }}' + state=started + sudo: yes + +- mysql_db: name='{{ redmine_db_name }}' + state=present + encoding=utf8 + sudo: yes + register: redmine_db_created + +# source database may not have same name as VM db. +# So remove CREATE or USE statements from dump. +# while unpacking. +- name: unpack mysql dump file + shell: "/usr/bin/gunzip -c {{ redmine_db_dump_file }} | /usr/bin/sed '/^CREATE DATABASE \\|^USE /d' > {{ _redmine_db_import_file }}" + args: + creates: '{{ _redmine_db_import_file }}' + when: do_redmine_db_import == True + +- stat: path='{{ _redmine_db_import_success }}' + register: redmine_db_import_done + when: do_redmine_db_import == True + +- name: import database + mysql_db: name='{{ redmine_db_name }}' + state=import + target='{{ _redmine_db_import_file }}' + register: redmine_db_import + when: do_redmine_db_import == True and (redmine_db_import_done.stat.exists == False or redmine_db_created|changed) + +- file: path='{{ _redmine_db_import_success }}' + state=touch + when: do_redmine_db_import == True and redmine_db_import_done.stat.exists == False and redmine_db_import|success + +- name: create db user + mysql_user: name='{{ redmine_db_user }}' + password='{{ redmine_db_password }}' + append_privs=yes + priv='{{ redmine_db_name }}.*:ALL' + state=present + sudo: yes + diff --git a/roles/easyredmine/tasks/main.yml b/roles/easyredmine/tasks/main.yml index c774960..b673e43 100644 --- a/roles/easyredmine/tasks/main.yml +++ b/roles/easyredmine/tasks/main.yml @@ -8,88 +8,18 @@ # mode=0644 # sudo: yes -- yum: name=epel-release - sudo: yes +- include: database.yml -- get_url: url=https://oss-binaries.phusionpassenger.com/yum/definitions/el-passenger.repo - dest=/etc/yum.repos.d/passenger.repo - sudo: yes -- rpm_key: key=https://packagecloud.io/gpg.key - sudo: yes +- include: redmine.yml -# this makecache is mostly because I can not find any other way to fully import the GPG. -# key for the Passenger repo. 'rpm --import' is not sufficient. -- command: yum -q makecache -y --disablerepo='*' --enablerepo='passenger*' - sudo: yes - changed_when: False +- include: nginx.yml -- yum: name='{{ item }}' - sudo: yes - with_items: - - unzip - - rubygems - - ruby-devel - - zlib-devel - - openssl-devel - - gcc-c++ - - mysql-devel - - ImageMagick-devel - - mariadb-server - - MySQL-python - - nginx - - passenger - -- gem: name='{{ item }}' - sudo: yes - with_items: - - bundler - - redmine-installer - -- stat: path='{{ cache_dir }}/{{ installer_package }}' - register: has_installer_package - -- name: download installer - get_url: url='http://software.apidb.org/source/{{ installer_package }}' - dest='{{ cache_dir }}' - mode=0640 - force=no - when: has_installer_package.stat.exists == False - -- service: name='{{ redmine_db_service }}' - state=started - sudo: yes - -- mysql_db: name='{{ redmine_db_name }}' - state=present - encoding=utf8 - sudo: yes - -- mysql_user: name='{{ redmine_db_user }}' - password='{{ redmine_db_password }}' - append_privs=yes - priv='{{ redmine_db_name }}.*:ALL' - state=present - sudo: yes - -#- command: ~/bin/redmine install '{{ cache_dir }}/{{ installer_package }}' +#- command: ~/bin/redmine install '{{ installer_package }}' # sudo: no - -- template: dest=/etc/nginx/conf.d/easyredmine.conf - src=easyredmine.conf.j2 - sudo: yes - notify: restart nginx - -- template: dest=/etc/nginx/conf.d/passenger.conf - src=passenger.conf.j2 - sudo: yes - notify: restart nginx - -- service: name=nginx - state=started - sudo: yes +# when: redmine_db_created|changed -# {{ redmine_root }} +# {{ redmine_root_dir }} # 1 # {{ redmine_db_name }} # {{ redmine_db_host }} diff --git a/roles/easyredmine/tasks/nginx.yml b/roles/easyredmine/tasks/nginx.yml new file mode 100644 index 0000000..6492885 --- /dev/null +++ b/roles/easyredmine/tasks/nginx.yml @@ -0,0 +1,35 @@ +- get_url: url=https://oss-binaries.phusionpassenger.com/yum/definitions/el-passenger.repo + dest=/etc/yum.repos.d/passenger.repo + sudo: yes +- rpm_key: key=https://packagecloud.io/gpg.key + sudo: yes + +# this makecache is mostly because I can not find any other way to fully +# import the GPG. key for the Passenger repo. 'rpm --import' is not +# sufficient. +- command: yum -q makecache -y --disablerepo='*' --enablerepo='passenger*' + sudo: yes + changed_when: False + +- yum: name=epel-release + sudo: yes + +- yum: name='{{ item }}' + sudo: yes + with_items: + - nginx + - passenger + +- template: dest=/etc/nginx/conf.d/easyredmine.conf + src=easyredmine.conf.j2 + sudo: yes + notify: restart nginx + +- template: dest=/etc/nginx/conf.d/passenger.conf + src=passenger.conf.j2 + sudo: yes + notify: restart nginx + +- service: name=nginx + state=started + sudo: yes diff --git a/roles/easyredmine/tasks/redmine.yml b/roles/easyredmine/tasks/redmine.yml new file mode 100644 index 0000000..0118e6d --- /dev/null +++ b/roles/easyredmine/tasks/redmine.yml @@ -0,0 +1,52 @@ +- yum: name='{{ item }}' + sudo: yes + with_items: + - unzip + - rubygems + - ruby-devel + - zlib-devel + - openssl-devel + - gcc-c++ + - ImageMagick-devel + - expect # for install_wrapper + +- gem: name='{{ item }}' + sudo: yes + with_items: + - bundler + - redmine-installer + +- stat: path='{{ installer_package }}' + register: has_installer_package + sudo: no + +- name: download installer + get_url: url='{{ installer_package_url }}' + dest='{{ cache_dir }}' + mode=0640 + force=no + when: has_installer_package.stat.exists == False + sudo: no + +- template: dest='{{ _redmine_install_wrapper }}' + src=install_wrapper.j2 + mode=750 + sudo: no + +- name: delete contents of redmine root directory + file: path='{{ redmine_root_dir }}' + state=absent + sudo: yes + when: redmine_db_created|changed + +- file: path='{{ redmine_root_dir }}' + state=directory + owner=vagrant + mode=755 + sudo: yes + register: mk_redmine_root_dir + +- name: run redmine installer + command: '{{ _redmine_install_wrapper }}' + when: mk_redmine_root_dir|changed + sudo: no diff --git a/roles/easyredmine/templates/easyredmine.conf.j2 b/roles/easyredmine/templates/easyredmine.conf.j2 index b666404..e47dd02 100644 --- a/roles/easyredmine/templates/easyredmine.conf.j2 +++ b/roles/easyredmine/templates/easyredmine.conf.j2 @@ -1,6 +1,6 @@ server { listen 80; server_name {{ ansible_fqdn }}; - root {{ redmine_root }}/public; + root {{ redmine_root_dir }}/public; passenger_enabled on; } diff --git a/roles/easyredmine/templates/install_wrapper.j2 b/roles/easyredmine/templates/install_wrapper.j2 new file mode 100755 index 0000000..d8ef583 --- /dev/null +++ b/roles/easyredmine/templates/install_wrapper.j2 @@ -0,0 +1,49 @@ +#!/usr/bin/expect + +# EuPathDB wrapper on EasyRedmine installer for +# non-interactive installs by Ansible + +set timeout -1 + +spawn ~/bin/redmine install /vagrant/scratch/easyredmine_package_u2072_d201511101601.zip + +expect -re {[\r\n]+Path for redmine_root} +send "{{ redmine_root_dir }}\r" + +# Database Configuration +expect -re {[\r\n]+> } +send "1\r"; # MySQL + +expect -re {[\r\n]+Database: } +send "{{ redmine_db_name }}\r" + +expect -re {[\r\n]+Host } +send "{{ redmine_db_host }}\r" + +expect -re {[\r\n]+Username:} +send "{{ redmine_db_user }}\r" + +expect -re {[\r\n]+Password:} +send "{{ redmine_db_password }}\r" + +expect -re {[\r\n]+Encoding} +send "{{ redmine_db_encoding }}\r" + +expect -re {[\r\n]+Port} +send "{{ redmine_db_port }}\r" + +# Email sending configuration +expect -re {[\r\n]+> } +send "2\r"; # Sendmail + +expect -re {[\r\n]+Location} +send "{{ sendmail_path }}\r" + +expect -re {[\r\n]+Arguments} +send -- "{{ sendmail_args }}\r" + +# What web-server do you want +expect -re {[\r\n]+> } +send "4\r"; # Passenger (nginx) + +interact diff --git a/roles/easyredmine/templates/installer_inputs.txt.j2 b/roles/easyredmine/templates/installer_inputs.txt.j2 new file mode 100644 index 0000000..c7d768c --- /dev/null +++ b/roles/easyredmine/templates/installer_inputs.txt.j2 @@ -0,0 +1,11 @@ +{{ redmine_root_dir }} +1 +{{ redmine_db_name }} +{{ redmine_db_host }} +{{ redmine_db_user }} +{{ redmine_db_password }} +{{ redmine_db_encoding }} +{{ redmine_db_port }} +2 +{{ sendmail_path }} +{{ sendmail_args }} diff --git a/roles/easyredmine/vars/main.yml b/roles/easyredmine/vars/main.yml index a7fc4c2..073a1fd 100644 --- a/roles/easyredmine/vars/main.yml +++ b/roles/easyredmine/vars/main.yml @@ -1,16 +1,19 @@ --- # vars file for easyredmine +do_redmine_db_import: False cache_dir: /vagrant/scratch -installer_package: easyredmine_package_u2072_d201511101601.zip +installer_package: '{{ cache_dir }}/easyredmine_package_u2072_d201511101601.zip' + +installer_package_url: 'http://software.apidb.org/source/{{ installer_package }}' -mysql_dump: redmine_2015-11-10_03h09m.Tuesday.sql.gz +redmine_db_dump_file: '{{ cache_dir }}/redmine_dump.sql.gz' -redmine_root: /opt/easyredmine +redmine_root_dir: /opt/easyredmine -redmine_db_service: mariadb +redmine_db_service_provider: mariadb # or mysqld redmine_db_name: easyredmine redmine_db_host: localhost redmine_db_user: redmine @@ -22,4 +25,8 @@ redmine_email_addr: mheiges@uga.edu redmine_email_port: 587 sendmail_path: /usr/sbin/sendmail -sendmail_args: -i -t \ No newline at end of file +sendmail_args: -i -t + +_redmine_db_import_file: /tmp/redmine_dump.sql +_redmine_db_import_success: /tmp/redmine_db_import_success +_redmine_install_wrapper: /home/vagrant/bin/install_wrapper \ No newline at end of file