LoginSignup
8
7

More than 5 years have passed since last update.

centosにlinuxbrewを入れるplaybookを書いてみた

Last updated at Posted at 2014-11-16

久々の投稿!

今日はcentos6.5のvm(vagrant x virtualbox)にlinuxbrewをインストールするansibleのplaybook書いたのでさらしてみようと思います。
試してないですがFedoraとかでもいけるはず。
※centos7,Ubuntuでも動作確認済みです

linuxbrew.yml
---
- hosts: "{{ host }}"
  remote_user: "{{ user }}"
  vars:
    - host: 127.0.0.1
    - user: vagrant
    - user_home: /home/{{ user }}
    - brew_home: "{{ user_home }}/.linuxbrew"
  tasks:
    - name: Install the dependency libraries "Development tools" of linuxbrew(Redhat)
      yum: name="@Development Tools" state=present
      when: ansible_os_family == 'RedHat'
      sudo: yes
    - name: Install the dependency libraries "with_items" of linuxbrew(Redhat)
      yum: name={{ item }} state=present
      with_items:
        - curl
        - git
        - m4
        - ruby
        - texinfo
        - bzip2-devel
        - curl-devel
        - expat-devel
        - ncurses-devel
        - zlib-devel
      when: ansible_os_family == 'RedHat'
      sudo: yes
    - name: Install the dependency libraries "with_items" of linuxbrew(Debian)
      apt: name={{ item }} state=present
      with_items:
        - build-essential
        - curl
        - git
        - m4
        - ruby
        - texinfo
        - libbz2-dev
        - libcurl4-openssl-dev
        - libexpat-dev
        - libncurses-dev
        - zlib1g-dev
      when: ansible_os_family == 'Debian'
      sudo: yes
    - name: Add configuration file loading of linuxbrew in bashrc
      lineinfile: dest="{{ user_home }}/.bashrc" state=present regexp="source .linuxbrewrc" line="source .linuxbrewrc"
    - name: Copy .linuxbrewrc
      template: src=linuxbrewrc.j2 dest={{ user_home }}/.linuxbrewrc mode=0644
    - name: Install linuxbrew
      shell: echo -ne '\n' | ruby -e "$(wget -O- https://raw.github.com/Homebrew/linuxbrew/go/install --no-check-certificate)" creates={{ brew_home }}
      register: linuxbrew
    - name: link gcc
      shell: ln -s `which gcc` {{ brew_home }}/bin/gcc-`gcc -dumpversion | cut -d. -f1,2`
      when: linuxbrew.changed
    - name: link g++
      shell: ln -s `which g++` {{ brew_home }}/bin/g++-`g++ -dumpversion | cut -d. -f1,2`
      when: linuxbrew.changed
linuxbrewrc.j2
export LINUXBREWHOME="$HOME/.linuxbrew"
export PATH="$LINUXBREWHOME/bin:$PATH"
export MANPATH="$LINUXBREWHOME/share/man:$MANPATH"
export INFOPATH="$LINUXBREWHOME/share/info:$INFOPATH"
export LD_LIBRARY_PATH="$LINUXBREWHOME/lib:$LD_LIBRARY_PATH"

yamlとtemplateはこんな感じで

$ ansible-playbook -i hosts linuxbrew.yml -k

呼び出しはこんな感じ
デフォルトでvagrantで立ち上げたvmでextra-vars指定しないでできるようになっています
違うuserとかhostに入れる場合は--extra-vars "host=x.x.x.x user=hoge"としてください

これで指定ユーザの$HOMEにlinuxbrewがインストールされます。
gccはシステムのやつを使うようにしています。

参考: http://log.saqihel.net/141018-linuxbrew/

これで新規vm立ち上げても簡単にlinuxbrew環境を構築できますね!

追記:

lxcで立ち上げたcentosとかだとwget,tar,which,rubyがなかったりするので実行前に適宜インストールしてください。

8
7
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
8
7