From ed270431ecd9f37acc79950c112c6b2f1dc0ffc7 Mon Sep 17 00:00:00 2001 From: Dorian Pula Date: Tue, 15 Mar 2016 10:10:17 -0400 Subject: [PATCH] Get working setup for local development setup. Include documentation for local setup. --- README.md | 24 ++++++++++++++++++++++++ defaults/main.yml | 7 +++++-- tasks/development.yml | 10 +++++++--- tasks/main.yml | 5 ++--- tasks/nodejs.yml | 3 ++- tasks/tools.yml | 5 ----- templates/npmrc.tmpl | 1 + vars/main.yml | 4 +++- 8 files changed, 44 insertions(+), 15 deletions(-) delete mode 100644 tasks/tools.yml create mode 100644 templates/npmrc.tmpl diff --git a/README.md b/README.md index 225dd44..309b89a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,27 @@ +Local Setup +=========== + +Create a local playbook `local_playbook.yml`: + +``` +--- +- hosts: localhost + user: $MY_USER_NAME + roles: + - { role: ansible-nodejs, node_version_family: "4.x", local_development: { user: "$MY_USER_NAME", enabled: true } } +``` + +Create local inventory `localhost_inventory`: + +``` +localhost ansible_connection=local ansible_become=true +``` + +Run the playbook locally: +``` +ansible-playbook test_playbook.yml -i localhost_inventory -vvvv -K +``` + Role Name ========= diff --git a/defaults/main.yml b/defaults/main.yml index de38834..3a1911c 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -6,5 +6,8 @@ globally_installed_tools: - browserify - npmrc -# Set to true for provisioning a development environment -local_development: false +local_development: + # Set to true for provisioning a development environment + enabled: false + user: "{{ ansible_env.SUDO_USER }}" + diff --git a/tasks/development.yml b/tasks/development.yml index 4ab46b0..8148afc 100644 --- a/tasks/development.yml +++ b/tasks/development.yml @@ -1,7 +1,11 @@ --- - name: setup a user local node folder for development - file: path="{{ ansible.user_home }}/.local/nodejs" state=directory owner={{ ansible.user }} + file: path="{{ local_dev_setup.user_home }}/.local/nodejs" state=directory owner={{ local_development.user }} - name: setup a npmrc setting for local development - file: path="{{ ansible.user_home }}/.npmrc" state=file owner={{ ansible.user }} - when: local_development == true \ No newline at end of file + template: src=npmrc.tmpl dest="{{ local_dev_setup.user_home }}/.npmrc" owner={{ local_development.user }} + +- name: install globally required tools + npm: name={{ item }} state=present registry=http://registry.npmjs.org/ path="{{ local_dev_setup.npm_home }}" + become_user: "{{ local_development.user }}" + with_items: globally_installed_tools diff --git a/tasks/main.yml b/tasks/main.yml index 8669aaa..f7965c8 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,4 +1,3 @@ --- -include: nodejs.yml -{ include: development.yml, when: local_development == true } -include: tools.yml +- { include: nodejs.yml, become_user: root, become_method: sudo } +- { include: development.yml, when: local_development.enabled == true } diff --git a/tasks/nodejs.yml b/tasks/nodejs.yml index 9a445de..5e30f49 100644 --- a/tasks/nodejs.yml +++ b/tasks/nodejs.yml @@ -32,4 +32,5 @@ - name: install globally required tools npm: name={{ item }} global=yes state=present registry=http://registry.npmjs.org/ - with_items: {{ globally_installed_tools }} + when: local_development.enabled == false + with_items: globally_installed_tools diff --git a/tasks/tools.yml b/tasks/tools.yml deleted file mode 100644 index 87c1d83..0000000 --- a/tasks/tools.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -- name: install globally required tools - npm: name={{ item }} global=yes state=present registry=http://registry.npmjs.org/ - with_items: {{ globally_installed_tools }} - when: globally_installed_tools exists \ No newline at end of file diff --git a/templates/npmrc.tmpl b/templates/npmrc.tmpl new file mode 100644 index 0000000..bcc979b --- /dev/null +++ b/templates/npmrc.tmpl @@ -0,0 +1 @@ +prefix={{ local_dev_setup.user_home }}/.local/share/node_modules diff --git a/vars/main.yml b/vars/main.yml index d69fcff..a65d551 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,2 +1,4 @@ --- -# vars file for ansible-nodejs +local_dev_setup: + user_home: "/home/{{ local_development.user }}" + npm_home: "/home/{{ local_development.user }}/.local/share/node_modules"