LoginSignup
10
9

More than 5 years have passed since last update.

【初心者向け】ドットインストールのローカル開発環境の構築をcentOS6から7版に書き換えてみました。【環境構築】

Last updated at Posted at 2016-09-05

いつもお世話になっているドットインストールさんのローカル開発環境の構築チュートリアルでは
OSがcentOS6になっているのでcentOS7でも対応できるようにAnsibleのコードを書き換えてみました。

ローカル開発環境の構築 [Windows編]ローカル開発環境の構築 [Windows編]
ローカル開発環境の構築 [MacOS X編]ローカル開発環境の構築 [MacOS X編]

今後の展望

① : rubyのバージョンをプロンプト入力できるようにする → でけた!!
② : MariaDB対応して更に、実行時にMySQL/MariaDBを選択できるようにする PostgreSQL対応もする ログの設定
③ : 最新のgitに対応する → でけた!!
④ : phpMyAdmin、phpPgAdmin対応する → でけた!!
⑤ : Xdebug対応してリモートデバッグできるようにする
⑥ : ベストプラクティスの構成に変更してみる → でけた!!
⑦ : serverspecでテストできるようにして、実際テストコードを書いてみる
⑧ : 鍵やファイアウォール等のセキュリティ設定する
⑨ : Zabbixを設定する
⑩ : cloud9を設定する Herokuを設定する → でけた!!
⑪ : Jenkinsを設定する → でけた!!
⑫ : Redmineを設定する
⑬ : GitBucketを設定する
⑭ : Owncloudを設定する

⑨ : Ubuntu版に書き換えてみる

下記レポジトリで改造中 。。。
https://github.com/kurokurosawa/centos7Plus

main.yml
---
- hosts: localhost
  become: yes
  vars:
    - ruby_version: 2.2.2
    - url_repo_remi: http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
    - url_repo_mysql: http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
  tasks:
    - name: yum update
      yum: name=* state=latest

    - name: disable Firewalld stop
      service: name=firewalld state=stopped enabled=no

    - name: install libselinux-python
      yum: name=libselinux-python state=latest

    - name: remove localtime
      file: path=/etc/localtime state=absent

    - name: change timezone
      file: src=/usr/share/zoneinfo/Asia/Tokyo dest=/etc/localtime state=link force=yes mode=0644

    - name: change locale
      command: localectl set-locale LANG=ja_JP.utf8

    - name: install remi repository
      yum: name={{ url_repo_remi }} state=present

    - name: install man
      yum: name=man state=latest

    - name: install apache
      yum: name=httpd state=latest

    - name: start apache and enabled
      service: name=httpd state=started enabled=yes

    - name: change owner
      file: dest=/var/www/html owner=vagrant recurse=yes

    - name: install gd-last
      yum: name=gd-last enablerepo=remi state=latest

    - name: install php
      yum: name={{item}} enablerepo=remi-php56 state=present
      with_items:
        - php
        - php-common
        - php-pdo
        - php-cli
        - php-devel
        - php-mysqlnd
        - php-mbstring
        - php-gd
        - php-intl
        - php-xml
      notify:
        - restart apache

    - name: copy php.ini.custom
      copy: src=php.ini.custom dest=/etc/php.ini backup=yes
      notify:
        - restart apache

    - name: install mysql repository
      yum: name={{ url_repo_mysql }} state=present

    - name: install mysql
      yum: name=mysql-community-server enablerepo=remi state=present

    - name: copy my.cnf.custom
      copy: src=my.cnf.custom dest=/etc/my.cnf backup=yes

    - name: start mysql and enabled
      service: name=mysqld state=started enabled=yes

    - name: install ruby dependencies
      yum: name={{item}} enablerepo=remi,epel state=present
      with_items:
        - gcc
        - openssl-devel
        - rpm-build
        - gcc-c++
        - bzip2
        - libtool
        - zlib
        - zlib-devel
        - httpd-devel
        - openssl-devel
        - curl-devel
        - ncurses-devel
        - gdbm-devel
        - readline
        - readline-devel
        - sqlite-devel
        - libyaml-devel
        - libffi-devel
        - bison

    - name: check rbenv installed
      command: test -x /home/vagrant/.rbenv
      register: rbenv_present
      ignore_errors: yes
      become: no

    - name: git clone rbenv
      git: repo=https://github.com/sstephenson/rbenv.git dest=/home/vagrant/.rbenv
      when: rbenv_present.rc != 0
      become: no

    - name: update bash_profile
      copy: src=bash_profile.custom dest=/home/vagrant/.bash_profile backup=yes
      become: no

    - name: check ruby-build installed
      command: test -x /home/vagrant/.rbenv/plugins/ruby-build
      register: rbuild_present
      ignore_errors: yes
      become: no

    - name: git clone ruby-build
      git: repo=https://github.com/sstephenson/ruby-build.git dest=/home/vagrant/.rbenv/plugins/ruby-build
      when: rbuild_present.rc != 0
      become: no

    - name: update rbenv
      command: git pull --rebase chdir=/home/vagrant/.rbenv
      become: no

    - name: update ruby-build
      command: git pull --rebase chdir=/home/vagrant/.rbenv/plugins/ruby-build
      become: no

    - name: check ruby installed
      shell: /bin/bash -lc "rbenv versions | grep {{ruby_version}}"
      register: ruby_installed
      ignore_errors: yes
      become: no

    - name: install ruby
      shell: /bin/bash -lc "rbenv install {{ruby_version}} && rbenv rehash && rbenv global {{ruby_version}}"
      when: ruby_installed.rc != 0
      become: no

    - name: check node js installed
      shell: /bin/bash -lc "node -v"
      register: node_installed
      ignore_errors: yes
      become: no

    - name: install node script
      shell: /bin/bash -lc "curl -sL https://rpm.nodesource.com/setup | bash -"
      when: node_installed.rc != 0
    - name: install nodejs

      yum: name=nodejs state=latest
      when: node_installed.rc != 0

  handlers:
    - name: restart apache
      service: name=httpd state=restarted
check.sh
#!/bin/bash

echo $'\e[33mcentOS/RedHatn\e[0m'
cat /etc/redhat-release
echo ''

echo $'\e[33mwget\e[0m'
wget --version | grep GNU
echo ''

echo $'\e[33mGit\e[0m'
git --version
echo ''

echo $'\e[33mAnsible\e[0m'
ansible --version
echo ""

echo $'\e[33mApache(httpd)\e[0m'
httpd -v
echo ''

echo $'\e[33mphp\e[0m'
php -v
echo ''

echo $'\e[33mperl\e[0m'
perl -version | grep version
echo ''

echo $'\e[33mpython\e[0m'
python --version
echo ''

echo $'\e[33mMySql\e[0m'
mysql --version
echo ''

echo $'\e[33mruby\e[0m'
ruby -v
echo ''

echo $'\e[33mrbenv\e[0m'
rbenv -v
echo ''

echo $'\e[33mnode\e[0m'
node -v
echo ''

echo $'\e[33mnpm -v\e[0m'
npm -v
echo ''

echo $'\e[33mfirewalld status\e[0m'
systemctl status firewalld
echo ''

echo $'\e[33mselinux status\e[0m'
getenforce
echo ''

echo $'\e[33mlocaltime status\e[0m'
ls -la /etc/localtime
echo ''

echo $'\e[33mlocalectl status\e[0m'
localectl status
echo ''

echo $'\e[33mDocument Root\e[0m'
ls -la /var/www/ | grep html
echo ''
10
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
9