ajoute un rôle "rbenv"
Installe un environnement Rbenv (avec quelques plugins) pour un utilisateur, une version de Ruby et des gems par défaut.
This commit is contained in:
parent
94915cda7d
commit
38bc504475
5 changed files with 161 additions and 0 deletions
24
rbenv/README.md
Normal file
24
rbenv/README.md
Normal file
|
@ -0,0 +1,24 @@
|
|||
# munin
|
||||
|
||||
Installation de Rbenv, Ruby et des gems par défaut.
|
||||
|
||||
## Taches
|
||||
|
||||
L'ensemble des actions est dans le fichier `tasks/main.yml`
|
||||
|
||||
## Variables possibles
|
||||
|
||||
Les seules variables sont liées au hostname (court et complet) qui sont simplement déduites des facts.
|
||||
|
||||
* `rbenv_version`: version de Rbenv à installer, `v1.0.0` par défaut
|
||||
* `rbenv_ruby_version`: version de Ruby à installer, `2.3.1` par défaut
|
||||
* `rbenv_root`: dossier d'installation, `~/.rbenv` par défaut
|
||||
* `rbenv_repo`: source Git pour Rbenv
|
||||
* `rbenv_plugins`: liste des plugins Rbenv à installer
|
||||
|
||||
Le rôle doit être ajouté en indiquant l'utilisateur concerné :
|
||||
|
||||
```
|
||||
roles:
|
||||
- { role: rbenv, username: 'johndoe' }
|
||||
```
|
13
rbenv/defaults/main.yml
Normal file
13
rbenv/defaults/main.yml
Normal file
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
rbenv_version: v1.0.0
|
||||
rbenv_ruby_version: 2.3.1
|
||||
rbenv_root: "~/.rbenv"
|
||||
rbenv_repo: "https://github.com/rbenv/rbenv.git"
|
||||
rbenv_plugins:
|
||||
- { name: "rbenv-vars", repo: "https://github.com/rbenv/rbenv-vars.git", version: "v1.2.0" }
|
||||
- { name: "ruby-build", repo: "https://github.com/rbenv/ruby-build.git", version: "v20160426" }
|
||||
- { name: "rbenv-default-gems", repo: "https://github.com/rbenv/rbenv-default-gems.git", version: "ead67889c91c53ad967f85f5a89d986fdb98f6fb" }
|
||||
- { name: "rbenv-installer", repo: "https://github.com/rbenv/rbenv-installer.git", version: "bc21e7055dcc8f5f9bc66ce0c78cc9ae0c28cd7a" }
|
||||
- { name: "rbenv-update", repo: "https://github.com/rkh/rbenv-update.git", version: "1961fa180280bb50b64cbbffe6a5df7cf70f5e50" }
|
||||
- { name: "rbenv-whatis", repo: "https://github.com/rkh/rbenv-whatis.git", version: "v1.0.0" }
|
||||
- { name: "rbenv-use", repo: "https://github.com/rkh/rbenv-use.git", version: "v1.0.0" }
|
1
rbenv/files/default-gems
Normal file
1
rbenv/files/default-gems
Normal file
|
@ -0,0 +1 @@
|
|||
bundler
|
5
rbenv/files/gemrc
Normal file
5
rbenv/files/gemrc
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
:sources:
|
||||
- https://rubygems.org
|
||||
install: --no-document
|
||||
update: --no-document
|
118
rbenv/tasks/main.yml
Normal file
118
rbenv/tasks/main.yml
Normal file
|
@ -0,0 +1,118 @@
|
|||
---
|
||||
|
||||
- name: install rbenv dependencies
|
||||
apt:
|
||||
pkg: '{{ item }}'
|
||||
install_recommends: no
|
||||
state: present
|
||||
with_items:
|
||||
- build-essential
|
||||
- git
|
||||
- libcurl4-openssl-dev
|
||||
- libffi-dev
|
||||
- libreadline-dev
|
||||
- libssl-dev
|
||||
- libxml2-dev
|
||||
- libxslt1-dev
|
||||
- zlib1g-dev
|
||||
tags:
|
||||
- rbenv
|
||||
- packages
|
||||
|
||||
- name: checkout rbenv_repo for {{ username }}
|
||||
git:
|
||||
repo: '{{ rbenv_repo }}'
|
||||
dest: '{{ rbenv_root }}'
|
||||
version: '{{ rbenv_version }}'
|
||||
accept_hostkey: yes
|
||||
force: yes
|
||||
become_user: "{{ username }}"
|
||||
ignore_errors: yes
|
||||
tags:
|
||||
- rbenv
|
||||
|
||||
- name: create plugins directory for {{ username }}
|
||||
file:
|
||||
path: '{{ rbenv_root }}/plugins'
|
||||
state: directory
|
||||
become_user: "{{ username }}"
|
||||
ignore_errors: yes
|
||||
tags:
|
||||
- rbenv
|
||||
|
||||
- name: install plugins for {{ username }}
|
||||
git:
|
||||
repo: '{{ item.repo }}'
|
||||
dest: '{{ rbenv_root }}/plugins/{{ item.name }}'
|
||||
version: '{{ item.version }}'
|
||||
accept_hostkey: yes
|
||||
force: yes
|
||||
with_items:
|
||||
- "{{ rbenv_plugins }}"
|
||||
become_user: "{{ username }}"
|
||||
ignore_errors: yes
|
||||
tags:
|
||||
- rbenv
|
||||
|
||||
- name: Init rbenv in profile for {{ username }}
|
||||
become_user: "{{ username }}"
|
||||
blockinfile:
|
||||
dest: '~{{ username }}/.profile'
|
||||
block: |
|
||||
export PATH="{{ rbenv_root }}/bin:$PATH"
|
||||
eval "$(rbenv init -)"
|
||||
marker: "# {mark} ANSIBLE MANAGED RBENV INIT"
|
||||
|
||||
- name: set default-gems for {{ username }}
|
||||
copy:
|
||||
src: default-gems
|
||||
dest: '{{ rbenv_root }}/default-gems'
|
||||
become_user: "{{ username }}"
|
||||
ignore_errors: yes
|
||||
tags:
|
||||
- rbenv
|
||||
|
||||
- name: set gemrc for {{ username }}
|
||||
copy:
|
||||
src: gemrc
|
||||
dest: ~/.gemrc
|
||||
become_user: "{{ username }}"
|
||||
ignore_errors: yes
|
||||
tags:
|
||||
- rbenv
|
||||
|
||||
- name: check ruby {{ rbenv_ruby_version }} installed for {{ username }}
|
||||
shell: /bin/bash -lc "rbenv versions | grep {{ rbenv_ruby_version }}"
|
||||
become_user: "{{ username }}"
|
||||
register: ruby_installed
|
||||
changed_when: false
|
||||
ignore_errors: yes
|
||||
always_run: yes
|
||||
tags:
|
||||
- rbenv
|
||||
|
||||
- name: install ruby {{ rbenv_ruby_version }} for {{ username }}
|
||||
shell: /bin/bash -lc "TMPDIR=~/tmp rbenv install {{ rbenv_ruby_version }}"
|
||||
become_user: "{{ username }}"
|
||||
when: ruby_installed.rc != 0
|
||||
ignore_errors: yes
|
||||
tags:
|
||||
- rbenv
|
||||
|
||||
- name: check if user ruby version is {{ rbenv_ruby_version }} for {{ username }}
|
||||
shell: /bin/bash -lc "rbenv version | cut -d ' ' -f 1 | grep -Fx '{{ rbenv_ruby_version }}'"
|
||||
become_user: "{{ username }}"
|
||||
register: ruby_selected
|
||||
changed_when: false
|
||||
ignore_errors: yes
|
||||
always_run: yes
|
||||
tags:
|
||||
- rbenv
|
||||
|
||||
- name: set ruby {{ rbenv_ruby_version }} for {{ username }}
|
||||
shell: /bin/bash -lc "rbenv global {{ rbenv_ruby_version }} && rbenv rehash"
|
||||
become_user: "{{ username }}"
|
||||
when: ruby_selected.rc != 0
|
||||
ignore_errors: yes
|
||||
tags:
|
||||
- rbenv
|
Loading…
Reference in a new issue