質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
CentOS

CentOSは、主にRed Hat Enterprise Linux(RHEL)をベースにした、フリーのソフトウェアオペレーティングシステムです。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ansible

Ansibleは、Python で書かれたサーバーの設定を管理するための 構成管理ツールです。

Q&A

解決済

1回答

2795閲覧

Ansibleでrbenvをシステムワイドインストールする際にsource反映されないのでうまくインストールされない

chrokurojp

総合スコア26

CentOS

CentOSは、主にRed Hat Enterprise Linux(RHEL)をベースにした、フリーのソフトウェアオペレーティングシステムです。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ansible

Ansibleは、Python で書かれたサーバーの設定を管理するための 構成管理ツールです。

0グッド

0クリップ

投稿2016/07/18 17:16

編集2016/07/26 03:59

Ansibleでrbenvをシステムワイドインストールする際にsource反映されないのでうまくインストールされない

下記ページのように
http://d.hatena.ne.jp/t_yamo/20150723/1437660326

shell: /bin/bash -lc "rbenv install {{ ruby.version }} && rbenv rehash && rbenv global {{ ruby.version }}"

とするとエラーはないもののruby -vしてみると入っていないような結果が帰ってきます。

下が僕が実際に使っているymlです。
実行環境はcentOS 7です。

yml

1--- 2--- 3- hosts: 127.0.0.1 4 become: yes 5 6 tasks: 7 # 【Roles : rbenv】 8 - name: Remove old directory 9 shell: rm -rf /usr/local/opt/rbenv /usr/local/opt/rbenv/plugins/ruby-build /usr/local/opt/rbenv/plugins/rbenv-gemset 10 11 - name: Git clone rbenv 12 shell: git clone https://github.com/sstephenson/rbenv.git /usr/local/opt/rbenv 13 14 - name: echo 'export RBENV_ROOT="/usr/local/opt/rbenv"' > /etc/profile.d/rbenv.sh 15 shell: echo 'export RBENV_ROOT="/usr/local/opt/rbenv"' > /etc/profile.d/rbenv.sh 16 17 - name: echo 'export PATH="$RBENV_ROOT/bin:$PATH"' >> /etc/profile.d/rbenv.sh 18 shell: echo 'export PATH="$RBENV_ROOT/bin:$PATH"' >> /etc/profile.d/rbenv.sh 19 20 - name: echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh 21 shell: echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh 22 23 - name: Git clone ruby-build 24 shell: git clone https://github.com/sstephenson/ruby-build.git /usr/local/opt/rbenv/plugins/ruby-build 25 26 - name: Git clone rbenv-gemset 27 shell: git clone https://github.com/jamis/rbenv-gemset.git /usr/local/opt/rbenv/plugins/rbenv-gemset 28 29 - name: Reflection rbenv.sh 30 shell: /bin/bash -l /etc/profile.d/rbenv.sh 31 32 - name: Rbenv local install 33 shell: rbenv install $(rbenv install -l | grep -v - | tail -1) 34 35 - name: Gem install 36 shell: yum install -y gem 37 38 - name: Install bundler 39 shell: RBENV_VERSION=$(rbenv install -l | grep -v - | tail -1) gem install bundler 40 41 - name: Rbenv global install 42 shell: rbenv global $(rbenv install -l | grep -v - | tail -1)

シェル版

#!/bin/sh # ruby-buildに必要なパッケージをインストールする # OS毎に必要なパッケージの一覧がruby-buildのWikiに記載されているので、最新版の一覧はWiki参照 # https://github.com/sstephenson/ruby-build/wiki yum install -y gcc openssl-devel libyaml-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel git clone https://github.com/sstephenson/rbenv.git /usr/local/opt/rbenv echo 'export RBENV_ROOT="/usr/local/opt/rbenv"' >> /etc/profile.d/rbenv.sh echo 'export PATH="$RBENV_ROOT/bin:$PATH"' >> /etc/profile.d/rbenv.sh echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh git clone https://github.com/sstephenson/ruby-build.git /usr/local/opt/rbenv/plugins/ruby-build git clone https://github.com/jamis/rbenv-gemset.git /usr/local/opt/rbenv/plugins/rbenv-gemset source /etc/profile.d/rbenv.sh rbenv install -l # list of versions available # ruby ローカル インストール rbenv install $(rbenv install -l | grep -v - | tail -1) # ruby version globalなgemとしてbundlerをインストールする RBENV_VERSION=$(rbenv install -l | grep -v - | tail -1) gem install bundler # ruby グローバル インストール rbenv global $(rbenv install -l | grep -v - | tail -1) # ruby 確認 ruby -v

最終的にコレに落ち着きました。

--- - hosts: 127.0.0.1 become: yes vars: - ver_ruby: 2.2.3 tasks: # 【Roles : rbenv】 - name: Remove old directory rbenv file: path=/usr/local/opt/rbenv state=absent - name: Remove old directory ruby-build file: path=/usr/local/opt/rbenv/plugins/ruby-build state=absent - name: Remove old directory rbenv-gemset file: path=/usr/local/opt/rbenv/plugins/rbenv-gemset state=absent - name: Git clone rbenv git: repo=https://github.com/sstephenson/rbenv.git dest=/usr/local/opt/rbenv accept_hostkey=yes - name: /usr/local/opt/rbenv rbenv.sh shell: echo 'export RBENV_ROOT="/usr/local/opt/rbenv"' > /etc/profile.d/rbenv.sh - name: $RBENV_ROOT/bin:$PATH rbenv.sh shell: echo 'export PATH="$RBENV_ROOT/bin:$PATH"' >> /etc/profile.d/rbenv.sh - name: eval "$(rbenv init -)" rbenv.sh shell: echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh - name: Git clone ruby-build git: repo=https://github.com/sstephenson/ruby-build.git dest=/usr/local/opt/rbenv/plugins/ruby-build accept_hostkey=yes - name: Git clone rbenv-gemset git: repo=https://github.com/jamis/rbenv-gemset.git dest=/usr/local/opt/rbenv/plugins/rbenv-gemset accept_hostkey=yes - name: rbenv install shell: /bin/bash -lc "rbenv install {{ ver_ruby }} && rbenv rehash && rbenv global {{ ver_ruby }}" - name: Gem install yum: name=gem state=present - name: exec $SHELL -l shell: exec $SHELL -l

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

sourceが反映されないのはシェルにlオプションを渡して対応できます。

Ansibleでシェル設定の再読み込みが必要になった場合の対応

投稿2016/07/18 23:41

moonphase

総合スコア6621

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

chrokurojp

2016/07/19 04:26

回答ありがとうございます。 こういう事でしょうか? 実行エラーになってしまいました。 - name: Reflection rbenv.sh shell: /bin/bash -l /etc/profile.d/rbenv.sh エラー内容 ``` TASK [Reflection rbenv.sh] ***************************************************** changed: [127.0.0.1] TASK [Rbenv local install] ***************************************************** fatal: [127.0.0.1]: FAILED! => {"changed": true, "cmd": "rbenv install $(rbenv install -l | grep -v - | tail -1)", "delta": "0:00:00.004575", "end": "2016-07-19 13:22:45.960484", "failed": true, "rc": 127, "start": "2016-07-19 13:22:45.955909", "stderr": "/bin/sh: rbenv: コマンドが見つかりません\n/bin/sh: rbenv: コマンドが見つかりません", "stdout": "", "stdout_lines": [], "warnings": []} ``` 上記でのymlを最新のものに差し替えています
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問