From ebf4c647b3dd35f5697d752593643ab23f69dfa5 Mon Sep 17 00:00:00 2001 From: Alex Barger Date: Wed, 14 Dec 2022 10:23:15 -0500 Subject: [PATCH 1/2] Fix issue with deprecated "include" Fix type-o in task name "Create the target VNM dir" Added variable nvm_link_global so we can disabled the symlink commands - these tasks fail in some scenarios and could be disabled depending on the end user's environment configuration --- defaults/main.yml | 1 + tasks/_symlink.yml | 1 + tasks/main.yml | 8 +++++--- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 2aa89b2..f26ee07 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -3,6 +3,7 @@ nvm_install_script_version: "0.33.11" nvm_user_name: "root" nvm_dir: "/var/lib/nvm" # for global installation +nvm_link_global: "yes" nvm_node_version: "8.11.3" nvm_install_globally: [] # libraries to add globally # nvm_dir: "~" # for user installation -> isn't working yet however diff --git a/tasks/_symlink.yml b/tasks/_symlink.yml index c36e118..3d7408c 100644 --- a/tasks/_symlink.yml +++ b/tasks/_symlink.yml @@ -15,3 +15,4 @@ state: link mode: "u+rwx,g+rx,o+rx" loop: "{{ find_result.files }}" + when: nvm_link_global == "yes" diff --git a/tasks/main.yml b/tasks/main.yml index 8b2d5f9..8ddaa52 100755 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,12 +1,12 @@ --- -- include: setup-Redhat.yml +- include_tasks: setup-Redhat.yml when: ansible_os_family == "RedHat" -- include: setup-Debian.yml +- include_tasks: setup-Debian.yml when: ansible_os_family == "Debian" # make it so that anyone can use it! -- name: Create the target VNM dir +- name: Create the target NVM dir file: path="{{ nvm_dir }}" state=directory owner="{{ nvm_user_name }}" mode="o+rwx" # variablize the name of the installation script so it fire installation script properly when @@ -43,10 +43,12 @@ - name: Make the node binary always discoverable by symlinking to a system bin PATH that cron sees by default too file: src="{{ nvm_dir }}/versions/node/v{{ nvm_node_version }}/bin/node" dest="/usr/bin/node" state=link mode="u+rwx,g+rx,o+rx" + when: nvm_link_global == "yes" - name: Make the npm binary always discoverable by symlinking to a system bin PATH that cron sees by default too file: src="{{ nvm_dir }}/versions/node/v{{ nvm_node_version }}/bin/npm" dest="/usr/bin/npm" state=link mode="u+rwx,g+rx,o+rx" + when: nvm_link_global == "yes" ### ---- Install version-agnostic and version-aware version of globals ---- ### ### TODO: DRY it some way smart From fedb49e4818669bae404c385df6fdc48c8df389e Mon Sep 17 00:00:00 2001 From: Alex Barger Date: Wed, 14 Dec 2022 15:43:09 -0500 Subject: [PATCH 2/2] Fix issue where SELinux will not allow replacing the bin files with symlinks by deleting it first and when nvm_link_global is "yes" --- tasks/_symlink.yml | 7 +++++++ tasks/main.yml | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/tasks/_symlink.yml b/tasks/_symlink.yml index 3d7408c..67806c7 100644 --- a/tasks/_symlink.yml +++ b/tasks/_symlink.yml @@ -8,6 +8,13 @@ file_type: any register: find_result +- name: Remove original global packages before symlink + file: + path: "/usr/bin/{{ item.path | basename }}" + state: absent + loop: "{{ find_result.files }}" + when: nvm_link_global == "yes" + - name: Symlink global packages into PATH for specific environments (like cron's) to be able to access them. file: src: "{{ item.path }}" diff --git a/tasks/main.yml b/tasks/main.yml index 8ddaa52..3a296c6 100755 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -40,11 +40,23 @@ [ -s \"$NVM_DIR/bash_completion\" ] && \. \"$NVM_DIR/bash_completion\"" when: ansible_os_family == "RedHat" +- name: Remove original node binary before symlink + file: + path: "/usr/bin/node" + state: absent + when: nvm_link_global == "yes" + - name: Make the node binary always discoverable by symlinking to a system bin PATH that cron sees by default too file: src="{{ nvm_dir }}/versions/node/v{{ nvm_node_version }}/bin/node" dest="/usr/bin/node" state=link mode="u+rwx,g+rx,o+rx" when: nvm_link_global == "yes" +- name: Remove original npm binary before symlink + file: + path: "/usr/bin/npm" + state: absent + when: nvm_link_global == "yes" + - name: Make the npm binary always discoverable by symlinking to a system bin PATH that cron sees by default too file: src="{{ nvm_dir }}/versions/node/v{{ nvm_node_version }}/bin/npm" dest="/usr/bin/npm" state=link mode="u+rwx,g+rx,o+rx"