summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllyson Bowles <abowles@hireology.com>2016-10-23 21:39:05 -0500
committerAllyson Bowles <abowles@hireology.com>2016-10-23 21:39:05 -0500
commitb90efeb49cad4f71e93bee232dd7312659dfcb6a (patch)
tree232a4d174622f30485cb987d469fad405b8d8fc7
parentdcbd64b481d054703d2f83b0600f9c348ea41705 (diff)
downloadansible-b90efeb49cad4f71e93bee232dd7312659dfcb6a.tar.gz
Add examples for rbenv and nvm
-rw-r--r--docsite/rst/playbooks_environment.rst55
1 files changed, 55 insertions, 0 deletions
diff --git a/docsite/rst/playbooks_environment.rst b/docsite/rst/playbooks_environment.rst
index bc6a17d4a3..0dba163869 100644
--- a/docsite/rst/playbooks_environment.rst
+++ b/docsite/rst/playbooks_environment.rst
@@ -56,6 +56,61 @@ to define an environment hash might be a group_vars file, like so::
http_proxy: http://proxy.bos.example.com:8080
https_proxy: http://proxy.bos.example.com:8080
+
+Working With Language-Specific Version Managers
+===============================================
+
+Some language-specific version managers (such as rbenv and nvm) require environment variables be set while these tools are in use. When using these tools manually, they usually require sourcing some environment variables via a script or lines added to your shell configuration file. In Ansible, you can instead use the environment directive::
+
+ ---
+ ### A playbook demonstrating a common npm workflow:
+ # - Check for package.json in the application directory
+ # - If package.json exists:
+ # * Run npm prune
+ # * Run npm install
+
+ - hosts: application
+ become: false
+
+ vars:
+ node_app_dir: /var/local/my_node_app
+
+ environment:
+ NVM_DIR: /var/local/nvm
+ PATH: /var/local/nvm/versions/node/v4.2.1/bin:{{ ansible_env.PATH }}
+
+ tasks:
+ - name: check for package.json
+ stat:
+ path: '{{ node_app_dir }}/package.json'
+ register: packagejson
+
+ - name: npm prune
+ command: npm prune
+ args:
+ chdir: '{{ node_app_dir }}'
+ when: packagejson.stat.exists
+
+ - name: npm install
+ npm:
+ path: '{{ node_app_dir }}'
+ when: packagejson.stat.exists
+
+You might also want to simply specify the environment for a single task::
+
+ ---
+ - name: install ruby 2.3.1
+ command: rbenv install {{ rbenv_ruby_version }}
+ args:
+ creates: '{{ rbenv_root }}/versions/{{ rbenv_ruby_version }}/bin/ruby'
+ vars:
+ rbenv_root: /usr/local/rbenv
+ rbenv_ruby_version: 2.3.1
+ environment:
+ CONFIGURE_OPTS: '--disable-install-doc'
+ RBENV_ROOT: '{{ rbenv_root }}'
+ PATH: '{{ rbenv_root }}/bin:{{ rbenv_root }}/shims:{{ rbenv_plugins }}/ruby-build/bin:{{ ansible_env.PATH }}'
+
.. note::
``environment:`` is not currently supported for Windows targets